【发布时间】:2012-02-25 03:30:52
【问题描述】:
我想将图像设置为联系人图标。该图像存储在缓存中。这是我的代码 -
Intent myIntent = new Intent();
myIntent.setAction(Intent.ACTION_ATTACH_DATA);
myIntent.setType("image/jpeg");
myIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(getApplicationContext().getCacheDir()
.getAbsolutePath()
+ "/" + fileName));
startActivityForResult(Intent.createChooser(myIntent, "Set As"),
200);
此代码为我提供了选项 - 联系人图标、壁纸。 当我选择联系人图标时,联系人列表正在打开。当我从联系人列表中选择任何联系人时,应用程序正在崩溃。
日志是 -
E/AndroidRuntime(15004): FATAL EXCEPTION: main
E/AndroidRuntime(15004): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/0r2-5C48544A48463C46323C2C/2 (has extras) }} to activity {com.android.contacts/com.android.contacts.AttachImage}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.camera.action.CROP (has extras) }
E/AndroidRuntime(15004): at android.app.ActivityThread.deliverResults(ActivityThread.java:3515)
E/AndroidRuntime(15004): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557)
E/AndroidRuntime(15004): at android.app.ActivityThread.access$2800(ActivityThread.java:125)
E/AndroidRuntime(15004): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
E/AndroidRuntime(15004): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(15004): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(15004): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(15004): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(15004): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(15004): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(15004): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(15004): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(15004): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.camera.action.CROP (has extras) }
E/AndroidRuntime(15004): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
E/AndroidRuntime(15004): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
E/AndroidRuntime(15004): at android.app.Activity.startActivityForResult(Activity.java:2817)
E/AndroidRuntime(15004): at com.android.contacts.AttachImage.onActivityResult(AttachImage.java:133)
E/AndroidRuntime(15004): at android.app.Activity.dispatchActivityResult(Activity.java:3890)
E/AndroidRuntime(15004): at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)
我找不到我的代码有什么问题。我需要为此添加一些权限吗?
这可以与android set image as contact icon/wallpaper 重复
但我没有找到任何解决方案。如果有人知道解决方案,请帮助我。
【问题讨论】: