Ashish
Ashish

Reputation: 41

click button open application if installed otherwise open play store in android?

I am creating an application in which I provide a link to another application. If that application is already installed on user device then open it otherwise open Google Play store page of android device.

Upvotes: 1

Views: 3363

Answers (2)

Maddy Sharma
Maddy Sharma

Reputation: 4956

I think you should try this :

PackageManager packageManager = getActivity().getPackageManager();
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
intent.setType("file/*");
List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
                                PackageManager.GET_ACTIVITIES));

if (list.size > 0) {
    // File explore is present (Size tells how many file explorers are present)
} else {

    // Not present
    // Just pointing to this app - https://play.google.com/store/apps/details?id=com.rhmsoft.fm
    // You can choose whichever you need

     try {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.rhmsoft.fm")));
        } catch (android.content.ActivityNotFoundException e) {
            startActivity(new Intent(Intent.ACTION_VIEW,     Uri.parse("http://play.google.com/store/apps/details?id=com.rhmsoft.fm")));
      }
    }

Upvotes: 1

Kalpesh Lakhani
Kalpesh Lakhani

Reputation: 993

for open app:

Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage("app package name");
if (i == null)
    throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {

//if not found in device then will come here
  Intent intent = new Intent(Intent.ACTION_VIEW);
  intent.setData(Uri.parse("market://details?id=com.example.android"));
  startActivity(intent);
}

Upvotes: 8

Related Questions