【问题标题】:Unable to set picture as. "No appps can perform this action"无法将图片设置为。 “没有应用程序可以执行此操作”
【发布时间】:2016-02-25 06:07:13
【问题描述】:

我正在尝试为用户提供一个选项,可以像这样将图像设置为墙纸/whatsapp dp。

但我被这段代码卡住了

Uri sendUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.a_day_without_thinking_mobile);

Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(sendUri, "image/jpg");
intent.putExtra("mimeType", "image/jpg");
startActivity(Intent.createChooser(intent,"Set As"));

它显示一个对话框,没有应用程序可以执行此操作。 我也尝试通过这种方法检查我的Uri

        ContentResolver cr = getContentResolver();
        String[] projection = {MediaStore.MediaColumns.DATA};
        Cursor cur = cr.query(sendUri, projection, null, null, null);
        if (cur != null) {
            if (cur.moveToFirst()) {
                String filePath = cur.getString(0);

                if (new File(filePath).exists()) {
                    Log.d("URI: ","File path exist");
                } else {
                    Log.d("URI: ","File not found");
                }
            } else {
                Log.d("URI: ","URI ok but no enty found");
            }
            cur.close();
        } else {
            Log.d("URI: ","URI was invalid for some other reason");
        }

而且它总是返回 URI 无效。但我确定该图像是有效的 jpg 并且存在于 raw 文件夹中。 我尝试更改 URI 路径但没有成功。

【问题讨论】:

  • 你遇到了什么问题?
  • 当我选择该选项时,它显示“没有应用程序可以执行此操作”。我认为这可能是由于未加载正确的图像 URI。
  • 实际上您是否想将文件附加/发布到社交媒体。这是正确的吗?
  • 不,我想为用户提供将图像设置为壁纸的选项。如上图所示。但是那个对话框没有弹出而是向我显示一条消息“没有应用程序可以执行此操作”。
  • 但是壁纸应用程序是如何工作的。它们还提供了在应用程序中将图像设置为壁纸的选项。

标签: android android-intent android-imageview android-menu android-wallpaper


【解决方案1】:

targetSdkVersion >= 24之后Android文件读取格式发生变化

您可以在此处找到详细信息; https://stackoverflow.com/a/38858040/1367450

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多