无法将图片设置为. “没有app可以执行此操作" [英] Unable to set picture as. "No appps can perform this action"

查看:196
本文介绍了无法将图片设置为. “没有app可以执行此操作"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为用户提供一个将图像设置为墙纸/whatsapp dp的选项,如下所示.

I am trying to give users an option to set image as wallpaper/whatsapp dp like this.

但是我被这段代码所困扰

But I'm stuck with this code

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

It shows a dialog that no apps can perform this action. I also tried to check my Uri through this method

        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,并且存在于原始文件夹中. 我尝试更改URI路径,但没有成功.

And It always returned that the URI was invalid. But I'm sure that the image is valid jpg and is present in raw folder. I tried changing URI paths but to no success.

推荐答案

targetSdkVersion >= 24

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

You can find the details here; https://stackoverflow.com/a/38858040/1367450

这篇关于无法将图片设置为. “没有app可以执行此操作"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆