在活动 A 中,我想打开一个对话框 (CustomDialog)。在 CustomDialog 中,它有一个用于打开相机的按钮。但是onActivityResult在我从图库中选择图像后没有被调用。没有toast正在显示。
活动A
private void openDialog() {
CustomDialog alert = new CustomDialog();
alert.showDialog(this);
}
自定义对话框
public class CustomDialog extends Activity{
Activity activity;
ImageView imageView;
public void showDialog(Activity activity) {
this.activity = activity;
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.custom_dialog);
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
dialog.setCanceledOnTouchOutside(true);
imageView = (ImageView) dialog.findViewById(R.id.logoApp);
Button galleryBtn = (Button) dialog.findViewById(R.id.galleryBtn);
galleryBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
galleryIntent();
}
});
dialog.show();
}
private void galleryIntent() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);//
activity.startActivityForResult(Intent.createChooser(intent, "Select File"), 1);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Toast.makeText(activity,"sdddddsss",Toast.LENGTH_LONG).show();
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == 1) {
onSelectFromGalleryResult(data);
}else{
// ...
}
我按照这个http://www.theappguruz.com/blog/android-take-photo-camera-gallery-code-sample
潇潇雨雨
森林海
HUWWW
相关分类