如何在Android Studio上单击按钮启动Instagram应用程序
我只想在最低API 16上单击按钮(如果已安装)打开Instagram应用程序 我尝试的是:如何在Android Studio上单击按钮启动Instagram应用程序,android,android-studio,Android,Android Studio,我只想在最低API 16上单击按钮(如果已安装)打开Instagram应用程序 我尝试的是: Intent likeIng = new Intent(Intent.ACTION_VIEW); likeIng.setPackage("com.instagram.android"); try { startActivity(likeIng); } catch (ActivityNotFoundException e) { Toast.makeText(this,"Instagr
Intent likeIng = new Intent(Intent.ACTION_VIEW);
likeIng.setPackage("com.instagram.android");
try {
startActivity(likeIng);
} catch (ActivityNotFoundException e) {
Toast.makeText(this,"Instagram Not Installed!",Toast.LENGTH_LONG).show();
}
但在安装Instagram的手机上运行时,它不会启动它。使用使用将此Uri传递给您
Uri uri = Uri.parse("http://instagram.com/_u/YOUR_USERNAME");
Intent i= new Intent(Intent.ACTION_VIEW,uri);
i.setPackage("com.instagram.android");
try {
startActivity(i);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://instagram.com/xxx")));
}
将此Uri传递给您的意图
Uri uri = Uri.parse("http://instagram.com/_u/YOUR_USERNAME");
Intent i= new Intent(Intent.ACTION_VIEW,uri);
i.setPackage("com.instagram.android");
try {
startActivity(i);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://instagram.com/xxx")));
}
尝试以下方法:
private void callInstagram() {
String apppackage = "com.instagram.android";
Context cx=this;
try {
Intent i = cx.getPackageManager().getLaunchIntentForPackage(apppackage);
cx.startActivity(i);
} catch (Exception e) {
Toast.makeText(this, "Sorry, Instagram Apps Not Found", Toast.LENGTH_LONG).show();
}
}
尝试以下方法:
private void callInstagram() {
String apppackage = "com.instagram.android";
Context cx=this;
try {
Intent i = cx.getPackageManager().getLaunchIntentForPackage(apppackage);
cx.startActivity(i);
} catch (Exception e) {
Toast.makeText(this, "Sorry, Instagram Apps Not Found", Toast.LENGTH_LONG).show();
}
}
用这个。我已经用过这个了
Intent i = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
startActivity(i);
用这个。我已经用过这个了
Intent i = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
startActivity(i);
奇怪,这对我有效,我会在几小时后发布另一个解决方案奇怪,这对我有效,我会在几小时后发布另一个解决方案StartActivity(getPackageManager().getLaunchIntentForPackage(“com.instagram.android”);startActivity(getPackageManager().getLaunchIntentForPackage(“com.instagram.android”);