如何与Share Intent共享整个Android应用程序

The*_*ter 34 android sharing android-intent

我以前使用过共享类型的意图,例如:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "---" });
intent.putExtra(Intent.EXTRA_SUBJECT, "---");
startActivity(Intent.createChooser(intent, "Contact Us!"));
Run Code Online (Sandbox Code Playgroud)

但是,这基本上与电子邮件/彩信和其他文本或文档类型的应用程序共享.你如何做同样的事情,但包括社交分享,如Facebook,Twitter和谷歌Plus(名称重要的).我要分享的是应用程序,文本中写着"嘿下载此链接以查看应用程序!" (或类似的东西).

ata*_*ulm 107

要添加Facebook,Twitter等共享选项,用户只需要安装这些应用程序.它取决于其他应用程序,Intents它们将告诉系统它们可以处理什么类型的应用程序.

然后ACTION_SEND将获得基本意图.

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
    "Hey check out my app at: https://play.google.com/store/apps/details?id=com.google.android.apps.plus");
sendIntent.setType("text/plain");
startActivity(sendIntent);
Run Code Online (Sandbox Code Playgroud)

资料来源:http://developer.android.com/training/sharing/send.html


Pri*_*nce 6

如果您应用此代码,则如下图所示

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "My application name");
intent.putExtra(Intent.EXTRA_TEXT, "This is my text");
startActivity(Intent.createChooser(intent, "choose one"));
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

================================================== ===================

如果您应用此代码,则如下图所示

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
startActivity(sendIntent);
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明


小智 5

您可以通过使用共享意图来实现

            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hey, download this app!");
            startActivity(shareIntent);     
Run Code Online (Sandbox Code Playgroud)

你可以把这个意图放在onclick上,或者在你想要的时候使用它

我认为这回答了你的问题=)