向SnapChat发送纯/文本意图不起作用



这是我发送简单文本的代码

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(android.content.Intent.EXTRA_TEXT,"Download this App");
intent.setPackage("com.snapchat.android");
startActivity(Intent.createChooser(intent, "Send Via Snapchat"));

它适用于所有其他消息应用程序,但不适用于Snapchat。此代码仅打开Snapchat应用程序。

这是如何共享snapchat直接消息中的文本。根据https://stackoverflow.com/a/51361192/5939682需要设置组件而不是通过snapchat共享的包。这是我的工作代码。

public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "TEXT TO SEND");
ComponentName intentComponent = new ComponentName("com.snapchat.android", "com.snapchat.android.LandingPageActivity");
intent.setComponent(intentComponent);
try {
startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.snapchat.android")));
}
}

如果应用程序没有安装,它会抛出ActivityNotFoundException,所以我们会处理它。您可以显示一条消息为"应用程序未安装",也可以将用户引导到appstore。

相关内容

最新更新