【问题标题】:set cache image as contact photo将缓存图像设置为联系人照片
【发布时间】: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 重复

但我没有找到任何解决方案。如果有人知道解决方案,请帮助我。

【问题讨论】:

    标签: android contact


    【解决方案1】:

    错误很明显:

    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)
    

    正如这里可以指出的,没有什么可以处理那个动作(com.android.camera.action.CROP),我希望你没有输入那个动作为了那个意图。

    这可能会提供一些见解: How to select and crop an image in android?

    【讨论】:

    • 感谢@JoxTraex 的快速响应。正如我在问题中提到的那样,我正在设置 Intent.ACTION_ATTACH_DATA 动作。这将启动 com.android.contacts/.AttachImage 组件。此活动正在设置 com.android.camera.action.CROP 操作。所以应该由这个活动来处理。另外,从列表中选择联系人后,我也没有接到任何电话,因此我可以设置此操作。
    • 嗯,有些东西不见了。看源码。
    【解决方案2】:

    我已经做到了。你只需要设置适当的意图,意图是

    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);
    

    【讨论】:

    • 我遇到了类似的问题:当我发送此意图时,联系人和 Nova 壁纸都崩溃了。我添加了intent.putExtra("mimeType", "image/jpg"),现在它们可以工作了。谢谢!
    • @Shweta 谢谢你,对我很有帮助
    猜你喜欢
    • 1970-01-01
    • 2012-01-02
    • 1970-01-01
    • 2016-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多