Why Uri.parse() does not return valid image uri of an image in the drawable folder?

爱⌒轻易说出口 提交于 2020-01-07 02:56:09

问题


intent = new Intent(Intent.ACTION_SEND);
        intent.setType("image/jpg");
        //intent.setType("image/*");

        Uri imageUri = Uri.parse("android.resource://com.example.anjuthanm.intenttest/"+R.drawable.test_image);
        //Uri imageUri = Uri.parse("android.resource://com.example.anjuthanm.intenttest/drawable/test_image");

        intent.putExtra(Intent.EXTRA_STREAM, imageUri);
        intent.putExtra(Intent.EXTRA_TEXT, "Sent from my app");
        chooser = Intent.createChooser(intent, "Send Image");
        startActivity(chooser);

When I run the app it opens the chooser dialog box. When I select Whatsapp it toast appears saying file format not supported. When I choose Evernote, the evernote app opens but the image is show as "7985522.null" (Some random number).

I think the image is not getting parsed into a valid uri.

In the tutorial I follow it seems to work for them. Is there anything wrong in the code?

来源:https://stackoverflow.com/questions/40947380/why-uri-parse-does-not-return-valid-image-uri-of-an-image-in-the-drawable-fold

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!