2017-08-29 163 views
1

我有以下代碼爲Android與其他應用程序如Facebook,Twitter,WhatsApp或Watever分享應用程序。我的Android應用程序共享我的應用程序鏈接到其他應用程序不起作用

它是開放的對話,並顯示應用程序選擇任何人,但是當我選擇的應用程式它給我的消息共享失敗,請稍後再試

Intent shareIntent = new Intent(Intent.ACTION_SEND); 
shareIntent.setType("plain/text"); 
shareIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); 
startActivity(Intent.createChooser(shareIntent, "share_with")); 

回答

1
public static void shareApp(Context context) { 
    final String appPackageName = context.getPackageName(); 
    Intent sendIntent = new Intent(); 
    sendIntent.setAction(Intent.ACTION_SEND); 
    sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    sendIntent.putExtra(Intent.EXTRA_TEXT, "Check this cool Sticker App at: https://play.google.com/store/apps/details?id=" + appPackageName); 
    sendIntent.setType("text/plain"); 
    context.startActivity(sendIntent); 
} 
0

試試這個

startActivity(new Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()));   

或在您的代碼(第二行)中輸入text/plain

+0

它只需將url複製到短信我想與其他應用程序共享,當我點擊按鈕時,它應該顯示應用程序選擇一個whatsapp viber imo或任何,所以我會選擇該應用程序假設whatsapp,然後用戶, –

+0

它看起來像你做得很好[你可以參考這個](https://developer.android.com/training/sharing/send.html#send-text-content) –

相關問題