gpt4 book ai didi

android - 我想制作一个像 WhatsApp 个人资料照片对话框屏幕这样的对话框屏幕

转载 作者:太空狗 更新时间:2023-10-29 14:14:27 25 4
gpt4 key购买 nike

你好 friend ....

我目前正在尝试使用隐式 Intent 制作一个对话框,我想在其中显示我的对话框,如 whatsApp(个人资料照片屏幕),并且在此屏幕中 whatsApp 使用名为“删除照片”的额外字段。当我尝试制作相同类型的屏幕对话框时,我无法添加这个额外的字段(“删除照片”)。我已经完成了所有代码。它在对话框中的三个选项(画廊、照片、相机)中工作正常,我无法在 onActivityResult() 中处理所有这些。我正在发送我所有的源代码,我已经很努力地尝试了,但是我找不到这样做的解决方案。 plz ..... friend 帮我解决这个问题。

在这段代码中,我只是创建了一个名为 openFileChooser() 的方法,我在其中编写了用于创建对话框屏幕的所有代码,并在 onActivityResult() 中处理此结果

这是我的代码

ProfilePhotoActivity.java

public class ProfilePhotoActivity extends Activity implements OnClickListener{
ImageButton back, editPhoto, selectAction;
ImageView imgCamera;
private static final int FILECHOOSER_RESULTCODE = 2888;
protected static final int CAMERA_REQUEST = 0;
protected static final int GALLERY_PICTURE = 1;
private Uri mCapturedImageURI = null;
Intent intent;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_profilephoto);

back=(ImageButton)findViewById(R.id.btn_back);
editPhoto=(ImageButton)findViewById(R.id.ibEditPhoto);
selectAction=(ImageButton)findViewById(R.id.ibSelectAction);

imgCamera=(ImageView)findViewById(R.id.imvProfilePhoto);

editPhoto.setOnClickListener(this);
selectAction.setOnClickListener(this);
back.setOnClickListener(this);
}

@Override
public void onClick(View v) {

switch (v.getId()) {
case R.id.btn_back:
ProfilePhotoActivity.this.finish();
break;

case R.id.ibEditPhoto:
openFileChooser(null, null);
// startDialog();


break;
case R.id.ibSelectAction:
break;
}
}

public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType){

try{

// Create AndroidExampleFolder at sdcard

File imageStorageDir = new File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES)
, "AndroidExampleFolder");

if (!imageStorageDir.exists()) {
// Create AndroidExampleFolder at sdcard
imageStorageDir.mkdirs();
}

// Create camera captured image file path and name
File file = new File(
imageStorageDir + File.separator + "IMG_"
+ String.valueOf(System.currentTimeMillis())
+ ".jpg");

mCapturedImageURI = Uri.fromFile(file);

// Camera capture image intent
final Intent captureIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);

Intent i = new Intent(Intent.ACTION_PICK);
// i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");

// Create file chooser intent
Intent chooserIntent = Intent.createChooser(i, "Image Chooser");

// Set camera intent to file chooser
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS
, new Parcelable[] { captureIntent });

// On select image call onActivityResult method of activity
startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);

}
catch(Exception e){
Toast.makeText(getBaseContext(), "Exception:"+e,
Toast.LENGTH_LONG).show();
}

}
protected void onActivityResult(int requestCode, int resultCode,Intent intent) {

if(requestCode==FILECHOOSER_RESULTCODE)
{
if (requestCode == GALLERY_PICTURE)
{
if (resultCode == RESULT_OK)
{
if (intent != null)
{
// our BitmapDrawable for the thumbnail
BitmapDrawable bmpDrawable = null;

// try to retrieve the image using the data from the intent
Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null);

if (cursor != null)
{
cursor.moveToFirst();

int idx = cursor.getColumnIndex(ImageColumns.DATA);
String fileSrc = cursor.getString(idx);
Bitmap galleryBitmap = BitmapFactory.decodeFile(fileSrc); // load preview image
galleryBitmap = Bitmap.createScaledBitmap(galleryBitmap, 200, 200, true);


String filePath = Environment.getExternalStorageDirectory()
.getAbsolutePath()+"/TimeChat/image/"+System.currentTimeMillis()+".jpg";

//imgCamera.setRotation(0);
imgCamera.setImageBitmap(galleryBitmap);
// writeToFile(filePath, galleryBitmap);
}
else
{
bmpDrawable = new BitmapDrawable(getResources(), intent.getData().getPath());
imgCamera.setImageDrawable(bmpDrawable);
}
}
else
{
Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
}
}
else if (resultCode == RESULT_CANCELED)
{
Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
}
}
else if (requestCode == CAMERA_REQUEST)
{
if (resultCode == RESULT_OK)
{
if (intent.hasExtra("data"))
{
// retrieve the bitmap from the intent
Bitmap cameraBitmap = (Bitmap) intent.getExtras().get("data");

String filePath = Environment.getExternalStorageDirectory()
.getAbsolutePath()+"/TimeChat/image/"+System.currentTimeMillis()+".jpg";

// update the image view with the bitmap
imgCamera.setImageBitmap(cameraBitmap);
// writeToFile(filePath, circleBitmap);

}
else if (intent.getExtras() == null) {

Toast.makeText(getApplicationContext(), "No extras to retrieve!", Toast.LENGTH_SHORT).show();

BitmapDrawable thumbnail = new BitmapDrawable(getResources(), intent.getData().getPath());

// update the image view with the newly created drawable
imgCamera.setImageDrawable(thumbnail);

}

}
else if (resultCode == RESULT_CANCELED) {
Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
}
}
}
}


@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
ProfilePhotoActivity.this.finish();
}

}

最佳答案

这看起来会是个问题:

 if(requestCode==FILECHOOSER_RESULTCODE)  
{
if (requestCode == GALLERY_PICTURE)

除非 FILECHOOSER_RESULTCODE 和 GALLERY_PICTURE 是相同的整数,否则语句永远不会通过。

关于android - 我想制作一个像 WhatsApp 个人资料照片对话框屏幕这样的对话框屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23825289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com