我想将图像设置为联系人图标.该图像存储在缓存中.这是我的代码 -
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);
Run Code Online (Sandbox Code Playgroud)
这段代码给了我选项 - 联系人图标,壁纸.当我选择联系人图标时,联系人列表正在打开.当我从联系人列表中选择任何联系人时,该应用程序正在崩溃.
日志是 -
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)
Run Code Online (Sandbox Code Playgroud)
我找不到我的代码有什么问题.我需要为此添加一些权限吗?
这可以是android设置图像的副本作为联系人图标/壁纸
但我没有找到任何解决方案.如果有人知道解决方案,请帮助我.
我已经做了.你只需要设置正确的意图,意图是
Uri sendUri = Uri.fromFile(externalFile)
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(sendUri, "image/jpg");
intent.putExtra("mimeType", "image/jpg");
startActivityForResult(Intent.createChooser(intent, "Set As"), 200);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1570 次 |
| 最近记录: |