2017-08-29 161 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) –

相关问题