Mehdi Fanai
Mehdi Fanai

Reputation: 4059

How to start another application with a specific string in its name

I need to start another application from mine in the following order:

  1. Check all installed applications on device and find the applications that has a specific string on their name and list them so they can be selected and launched(eg checks for all the application which contain "timer" in their name such as "perfect timer","your timer", etc.)

2.if no application is available, start Google Play and search for the name(eg "timer").

Upvotes: 0

Views: 149

Answers (2)

Tomer Mor
Tomer Mor

Reputation: 8028

first you need to read all the installed app read more here http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon,

after you found the desire application, you can simple fire intent to that application or else open the market with filter search like this

   Intent i = new Intent(Intent.ACTION_VIEW);
   i.setData(Uri.parse("market://search?q=com.amazon.kindle"));
   startActivity(i);

Upvotes: 0

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132982

you will need to use PackageManager for getting all installed Applications name and use getLaunchIntentForPackage for launching application if it contain specific string :

PackageManager pm = getPackageManager();
  List<ApplicationInfo> packages = 
                  pm.getInstalledApplications(PackageManager.GET_META_DATA);

  for (ApplicationInfo packageInfo : packages) {
   if(packageInfo.packageName.toLowerCase().
                   contains(""perfect timer".toLowerCase())){

     Intent intent = 
                pm.getLaunchIntentForPackage(packageInfo.packageName);   
      if (intent != null)  {
         intent.addCategory(Intent.CATEGORY_LAUNCHER);
         startActivity(intent);  
      }  
  } else{
            // Launch google play app here
            String apppackname = "com.example.appname";
             Intent intentapp=new (Intent.ACTION_VIEW, 
                Uri.parse("market://search?q="+apppackname)));
             startActivity(intentapp);
      }       
}

Upvotes: 1

Related Questions