我試圖與其他Android應用程序共享文字和圖像的意圖,但我似乎無法讓它工作。我一直在關注這個文檔:https://developer.android.com/training/sharing/send.html,但它似乎沒有工作,或者我做錯了什麼。分享文字和圖像的意圖在Android中產生錯誤
這是我使用創建此意向代碼:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
sendIntent.putExtra(Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=game.bounce");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://game.bounce/"+R.mipmap.logo));
sendIntent.setType("*/*");
startActivity(Intent.createChooser(sendIntent, "Share using:"));
當我去跑我的意圖它拋出這個錯誤:
W/Bundle﹕ Attempt to cast generated internal exception:
java.lang.ClassCastException: android.net.Uri$StringUri cannot be cast to java.util.ArrayList
特別是我想分享這與Facebook和Facebook應用程序也產生此錯誤:
Please attach photos or a single video.
我一直在猜測這條線m飛行將產生錯誤:
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://game.bounce/"+R.mipmap.logo));
但我也試過這樣:
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("https://path.to.my.image));
並且不與如何解決這一問題的提示工作
任何人將不勝感激!
我想,之前我又嘗試過了,我仍然得到一個錯誤。這是錯誤:java.lang.ClassCastException:java.util.ArrayList不能轉換爲android.os.Parcelable。它還在文檔中說Uri類實現了Parcelable – Jamaal
我測試了我的機器上的確切代碼,它的工作原理 –
有趣的是,也許它是我想要分享的特定應用程序以及我正在使用的設備。我正在使用Google Nexus 4,並且正在嘗試與Facebook和Gmail應用程序共享。你有工作時使用了什麼設備和應用程序? – Jamaal