Chooser Intent正在AVD工作,但没有在真正的手机上工作。我的手机是samsumg galaxy core。我将我的应用程序发送到我的电子邮件并下载到手机中并安装完毕。该应用程序正在真正的手机中工作,但只有选择器的Intent部分无效。在选择器意图下,我有3个意图用于从相机拍摄照片,另一个用于从图库中选择图片,另一个用于从视图中移除所选图片。它在Chooser中显示消息“无法找到执行此操作的应用程序”。我的代码如下。
请注意,这适用于AVD(模拟器)但不适用于真实手机。可能是什么问题?
ImageButton imagebutton = (ImageButton) findViewById(R.id.profile_picture);
imagebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT,null);
galleryIntent.setType("image/*");
galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
Intent removeProfPic = new Intent();
String mPackage ="com.example.myapp";
String mClass = mPackage + "." + "RemoveProfilePic";
removeProfPic.setComponent(new ComponentName(mPackage, mClass));
Intent[] intentArray = {cameraIntent,galleryIntent};
Intent chooser = new Intent(Intent.ACTION_CHOOSER);
chooser.putExtra(Intent.EXTRA_TITLE, "Choose");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
chooser.putExtra(Intent.EXTRA_INTENT, removeProfPic);
startActivityForResult(chooser,1);
}
});
: :
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_CANCELED && data != null)
{
if (requestCode == 1 && resultCode == RESULT_OK)
{
Uri pic_uri = data.getData();
if(pic_uri !=null)
{
try
{
Bitmap picture = MediaStore.Images.Media.getBitmap(this.getContentResolver(), pic_uri);
ImageButton imagebtn = (ImageButton) findViewById(R.id.profile_picture);
imagebtn.setImageBitmap(picture);
profilePictureSet = true;
}
catch (Exception e)
{
e.printStackTrace();
}
}
else
{
Bundle b = data.getExtras();
String s = b.getString("key1");
if (s.equals("delete"))
{
ImageButton imagebtn = (ImageButton) findViewById(R.id.profile_picture);
imagebtn.setImageResource(R.drawable.default_img);
profilePictureSet = false;
}
else
{
Bitmap bitmap=(Bitmap) data.getExtras().get("data");
ImageButton imagebtn = (ImageButton) findViewById(R.id.profile_picture);
imagebtn.setImageBitmap(bitmap);
profilePictureSet = true;
}
}
super.onActivityResult(requestCode, resultCode, data);
}
}
}
我也尝试在Androidmanifest.xml中包含以下内容
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.hardware.camera" />
<uses-permission android:name="android.hardware.camera.autofocus" />
但仍然无法工作..感谢任何帮助..提前致谢!
我刚刚交换了galleryIntent和removeProfPic,如下所示,现在正在使用它。谢谢!
:
Intent[] intentArray = {cameraIntent,removeProfPic};
:
:
chooser.putExtra(Intent.EXTRA_INTENT, galleryIntent);
:
答案 0 :(得分:0)
您没有为ex ...
设置意图数据类型Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some@email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, "Send To"));