Reputation: 211
I just want to open Instagram application on button click (if installed) on minimum API 16.
What I am trying is:
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();
}
But when running on a phone where Instagram is installed, it's not launching it.
Upvotes: 0
Views: 8544
Reputation: 166
use this. I already used this.
Intent i = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
startActivity(i);
Upvotes: 0
Reputation: 322
Try this method:
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();
}
}
Upvotes: -1
Reputation: 438
pass this this Uri to your intent.
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")));
}
Upvotes: 5