在Android中共享意图在弹出窗口后无法将图像分享给任何应用程序

3

我正在尝试在Android中使用分享意图共享图像。点击按钮后显示已安装应用程序的列表。但是当我选择任何一个应用程序时,它无法进行共享。打开的应用程序崩溃或某些应用程序会告诉发送内容类型不支持。

我的代码:

Intent share = new Intent(Intent.ACTION_SEND);
            File filepath = Environment.getExternalStorageDirectory();
            File dir = new File(filepath.getAbsolutePath() + "/");
            dir.mkdirs();
            Uri uri = Uri.parse(dir+"/img.jpg");
            share.putExtra(Intent.EXTRA_STREAM,uri);
            share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            share.setType("image/jpg"); 
            startActivity(Intent.createChooser(share, "Share Image"));

我同意让应用程序读写外部存储器。

日志记录:

我一直收到这个错误:

07-06 12:25:11.654: E/SurfaceFlinger(113): SurfaceFlinger translucent=1 isOpaque=0 isExternalDisplayLayer=0 isExternalBlockLayer0

@Amarbir Singh 我没有使用任何库。在这个方法之前,我正在尝试文件提供程序。那时候我正在更新我的库。 - Suresh
能否将崩溃日志发布出来? - Saurav
@Saurav 谢谢,我已经发布了我的日志记录,并等待您的回复。 - Suresh
请发布您的完整崩溃日志。 - Saurav
1个回答

1

Try This:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
Uri uri = Uri.fromFile(new File(getFilesDir(), "foo.jpg"));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri.toString());
startActivity(Intent.createChooser(shareIntent, "Share image using"));

http://developer.android.com/training/sharing/send.html


我也尝试了上面的代码。但是问题仍然存在。 - Suresh
你正在测试哪个设备? - Chaudhary Amar
谢谢您的快速回复。我正在使用三星Galaxy Tab2进行测试。 - Suresh
请查看以下链接: http://stackoverflow.com/questions/19909832/what-does-this-logcat-error-message-mean https://dev59.com/gG_Xa4cB1Zd3GeqP6egc - Chaudhary Amar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接