2016-09-15 117 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。原因是其他應用程序無法訪問應用程序專用內存中的文件。所以要分享應用程序中的圖像或任何其他文件,您必須使其可供其他應用程序閱讀。

相關問題