Java Android直接共享
我正在尝试与direct share共享我的应用程序中的链接。共享对话框必须如下图所示,包含消息应用程序中使用最多的联系人,如WhatsApp联系人 这是我用于共享链接的Java Android直接共享,java,android,share,Java,Android,Share,我正在尝试与direct share共享我的应用程序中的链接。共享对话框必须如下图所示,包含消息应用程序中使用最多的联系人,如WhatsApp联系人 这是我用于共享链接的Intent结构: Intent shareIntent = ShareCompat.IntentBuilder .from(getActivity()) .setType("text/plain")
Intent
结构:
Intent shareIntent = ShareCompat.IntentBuilder
.from(getActivity())
.setType("text/plain")
.setText(sTitle+ "\n" + urlPost)
.getIntent();
if (shareIntent.resolveActivity(
getActivity().getPackageManager()) != null)
startActivity(shareIntent);
这就是我的应用程序所显示的:
你知道如何实现吗?你应该使用
.createChooseContent()
而不是.getIntent()
像下面的代码一样,你可以使用Intent.createChooser
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("file://" + filePath);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
您应该使用
.createChooseContent()
而不是.getIntent()
文档:这使用了意图,它显示
活动选择器,允许用户在继续之前选择他们想要的内容。当您尝试启动具有多个可能匹配项的活动时,系统会显示标准活动选取器,该选取器可作为标准活动选取器的替代品,其行为存在以下差异:
- 您可以指定将显示在“活动选择器”中的标题
- 用户没有将其中一个匹配活动作为首选活动的选项,所有可能的活动都将 始终显示,即使其中一个当前标记为 首选活动李>
嗯,如果您是共享链接的人,那么您不会实现
ChooserTargetService
。WhatsApp、contacts应用程序和其他应用程序可以实现ChooserTargetService
,如果他们愿意的话。哦,也许我对ChooserTargetService
有点困惑,但是,为什么我的应用程序中的共享对话框在我共享文本等链接时不显示联系人?也许WhatsApp没有实现ChooserTargetService
,或者,他们这样做并不是为了满足您的请求所使用的意图
结构。