如何在android中实现通过选项共享?

发布于 2024-12-23 15:47:43 字数 148 浏览 3 评论 0原文

我想实现这样的事情。 share via

它不应该被硬编码。如果用户尚未安装 Dropbox,则不应有通过 Dropbox 共享的选项。

提前致谢 !

I want to implement something like this. share via

It should not be hard coded. If user haven't installed Dropbox there should not be a option to share via Dropbox.

Thanks in advance !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ˉ厌 2024-12-30 15:47:43

您可以使用以下方法执行相同操作:

Intent i=new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject test");
i.putExtra(android.content.Intent.EXTRA_TEXT, "extra text that you want to put");
startActivity(Intent.createChooser(i,"Share via"));

详细示例供您参考: http://mobile.tutsplus.com/tutorials/android/android-sdk-implement-a-share-intent/

You can do the same by using:

Intent i=new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject test");
i.putExtra(android.content.Intent.EXTRA_TEXT, "extra text that you want to put");
startActivity(Intent.createChooser(i,"Share via"));

Detailed example is here for your reference: http://mobile.tutsplus.com/tutorials/android/android-sdk-implement-a-share-intent/

指尖凝香 2024-12-30 15:47:43

通过以下方式共享内容:

Intent shareIntent =  new Intent(android.content.Intent.ACTION_SEND); 

//set type  

shareIntent.setType("text/plain");  

//add what a subject you want

shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"add what a subject you want");  

 String shareMessage="message body"; 

//message  

shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,shareMessage); 

//start sharing via 

startActivity(Intent.createChooser(shareIntent,"Sharing via"));  

For Sharing the Content Via:

Intent shareIntent =  new Intent(android.content.Intent.ACTION_SEND); 

//set type  

shareIntent.setType("text/plain");  

//add what a subject you want

shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"add what a subject you want");  

 String shareMessage="message body"; 

//message  

shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,shareMessage); 

//start sharing via 

startActivity(Intent.createChooser(shareIntent,"Sharing via"));  
轻许诺言 2024-12-30 15:47:43

在 KOTLIN 中:

startActivity(createShareIntent(url))


fun createShareIntent(url: String): Intent = Intent.createChooser(Intent().apply {
    action = Intent.ACTION_SEND
    putExtra(Intent.EXTRA_TEXT, url)
    type = "text/plain"
}, null)

希望它会有所帮助。

in KOTLIN :

startActivity(createShareIntent(url))


fun createShareIntent(url: String): Intent = Intent.createChooser(Intent().apply {
    action = Intent.ACTION_SEND
    putExtra(Intent.EXTRA_TEXT, url)
    type = "text/plain"
}, null)

Hope it will helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文