Intent to open a chat with a specific user on snapchat app

断了今生、忘了曾经 提交于 2019-12-01 15:56:14

This the only thing that works for me. Unfortunately, it adds the extra step of making the user choose the browser or Snapchat app.

Intent nativeAppIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://snapchat.com/add/" + snapchatId));
startActivity(nativeAppIntent);

Oddly enough, the URL scheme snapchat://add/" + snapchatId works on iOS but not on Android (it opens the Android app, but does not pop up the user).

EDIT: Add intent.setPackage("com.snapchat.android"); and it will open the app without the chooser. But adding this means you will need to surround everything with a try/catch to prevent a crash.

try {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://snapchat.com/add/" + snapchatId));
    intent.setPackage("com.snapchat.android");
    startActivity(intent);
} catch (Exception e) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://snapchat.com/add/" + snapchatId)));
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!