0

i want to open an another app activity from my app, if the app is not installed go to the play store to install the app.

my code is working fine but its only open the app from it's package name, it's not opening activity.

Code:

public void startApplication(String packageName) { try { Intent intent = new Intent("android.intent.action.MAIN"); intent.addCategory("android.intent.category.LAUNCHER"); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); List<ResolveInfo> resolveInfoList = getPackageManager().queryIntentActivities(intent, 0); for(ResolveInfo info : resolveInfoList) if(info.activityInfo.packageName.equalsIgnoreCase(packageName)) { launchComponent(info.activityInfo.packageName, info.activityInfo.name); return; } // No match, so application is not installed showInMarket(packageName); } catch (Exception e) { showInMarket(packageName); } } private void launchComponent(String packageName, String name) { Intent intent = new Intent("android.intent.action.MAIN"); intent.addCategory("android.intent.category.LAUNCHER"); intent.setComponent(new ComponentName(packageName, name)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } private void showInMarket(String packageName) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } 
0

1 Answer 1

0

Try

public void startApplication(String packageName) { Intent launchIntent = getPackageManager().getLaunchIntentForPackage(packageName); if (launchIntent != null) { startActivity(launchIntent); } else { showInMarket(packageName); } } 
Sign up to request clarification or add additional context in comments.

1 Comment

No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.nouvellesapplis.lt2.view.LoginActivity

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.