2016-09-15 104 views
-1

我有麻烦从我的应用程序共享图像到其他应用程序。从Android应用程序共享图像

问题是当我分享图像时,它不包括扩展程序和其他应用程序,比如messenger,whatsapp或gmail不能识别它们。

我的代码是:

Intent intent = new Intent(Intent.ACTION_SEND); 

    String path = "android.resource://com.xxxx.xxxxxxx/drawable/image"; 
    Uri screenshotUri = Uri.parse(path); 

    intent.putExtra(Intent.EXTRA_TEXT, "Hello world!"); 
    intent.putExtra(Intent.EXTRA_STREAM, screenshotUri); 
    intent.setType("image/*"); 

    startActivity(Intent.createChooser(intent, "Share:")); 

我有同样的问题,共享音频:

Intent share = new Intent(); 
    share.setAction(Intent.ACTION_SEND); 

    String sharePath = "android.resource://com.xxx.xxxxx/raw/" + sound; 
    Uri uri = Uri.parse(sharePath); 

    share.putExtra(Intent.EXTRA_STREAM, uri); 
    share.setType("audio/mp3"); 

    Intent i = Intent.createChooser(share, "Share Sound File"); 
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

    baseContext.startActivity(i); 

我已经签了正式文件,可是仍然存在问题:https://developer.android.com/training/sharing/send.html

感谢帮助或任何提示!

+0

检查了这可能有所帮助 - http://stackoverflow.com/questions/7661875/how-to-use-share-image-using-sharing-intent-to-share-images-in-android https ://guides.codepath.com/android/Sharing-Content-with-Intents –

回答

1

您必须在共享之前将图像或音频文件写入SD卡或ExternalStorege。原因是其他应用程序无法访问应用程序专用内存中的文件。所以要分享应用程序中的图像或任何其他文件,您必须使其可供其他应用程序阅读。

相关问题