很多人已经回答了这个问题,但我仍在回答。使用上面回答的方法,工作流程要经过 3 个步骤。
Step1:应用解析 uri 和 intent
第二步:意图进入浏览器并加载 Instagram url
Step3:浏览器然后重定向到 Instagram 应用
但要直接打开 Instagram 应用程序而不用浏览器,您可以使用下面提到的方法。
创建如下 Intent 方法:-
private Intent instaIntn(Context context) {
Intent i1;
String instaId = "your insta id";
String appResolver = "instagram://user?username=";
String webResolver = "https://instagram.com/";
String instaPackageName = "com.instagram.android";
String instaLitePackName = "com.instagram.lite";
try {
context.getPackageManager().getPackageInfo(instaPackageName, 0);
i1 = new Intent(Intent.ACTION_VIEW, Uri.parse(appResolver+instaId));
} catch (PackageManager.NameNotFoundException e1) {
Toast.makeText(getApplication(), "Instagram not found", Toast.LENGTH_SHORT).show();
try {
context.getPackageManager().getPackageInfo(instaLitePackName, 0);
i1 = new Intent(Intent.ACTION_VIEW, Uri.parse(appResolver+instaId));
} catch (PackageManager.NameNotFoundException e2) {
Toast.makeText(getApplication(), "Instagram and instagram lite not found", Toast.LENGTH_SHORT).show();
i1 = new Intent(Intent.ACTION_VIEW, Uri.parse(webResolver+instaId));
}
}
return i1;
}
现在你可以通过简单地调用下面的语句从类内的任何地方开始这个意图:-
startActivity(instaIntn(getApplicationContext()));
现在它会做什么,它将尝试打开 Instagram 应用程序,如果未安装 instagram 应用程序,那么它将尝试打开 Instagram lite。如果这两个应用程序都丢失,那么它将意图浏览器。
上述方法意图用户访问 Instagram 应用程序和用户个人资料。您还可以让用户关注 Instagram 图片视频和其他页面。在此处查看完整文档https://developers.facebook.com/docs/instagram/sharing-to-feed/