我遇到了与此处描述的完全相同的问题。
我正在尝试使用此意图:
android.provider.ContactsContract.Intents.ATTACH_IMAGE
Starts an Activity that lets the user pick a contact to attach an image to.
听起来适合我,但不幸的是导致ActivityNotFoundException
.
代码:
import android.provider.ContactsContract;
...
try {
Intent myIntent = new Intent();
myIntent.setAction(ContactsContract.Intents.ATTACH_IMAGE);
myIntent.setData(imageUri);
startActivity(myIntent);
} catch (ActivityNotFoundException anfe) {
Log.e("ImageContact",
"Firing Intent to set image as contact failed.", anfe);
showToast(this, "Firing Intent to set image as contact failed.");
}
我在上面的代码中找不到任何错误。以下imageUri
代码是正确的,运行良好:
代码:
try {
Intent myIntent = new Intent();
myIntent.setAction(Intent.ACTION_ATTACH_DATA);
myIntent.setData(imageUri);
startActivity(myIntent);
} catch (ActivityNotFoundException anfe) {
Log.e("ImageContact",
"Firing Intent to set image as contact failed.", anfe);
showToast(this, "Firing Intent to set image as contact failed.");
}
如链接中所述,这会导致在访问联系人之前出现另一个菜单。这是可以接受的,但并不完美。