0

I know there are a lot of similar posts like

this: Launch an application from another application on Android

and this: Launch Activity from another Application Android

but they do not satisfy my question.

Background:

I am working on an application where i need to call an application that is already installed in my phone. e.g Astro Filemanager

My Question is:

How can i call an application that is installed in my phone from my Activity, keeping in mind that i do not have the package name, i have only the application name.

Can i achieve this?

If yes then how?

if not then why?

I know that i can call another application using the package name, but in my case i do not have the package name, i have only the application name available

Another Scenario

Can i save the .apk file of an application in my project folder and call that apk from there?

Community
  • 1
  • 1
Hassaan Rabbani
  • 2,399
  • 5
  • 27
  • 50
  • 1
    Android has some thing called Intents to achieve this. – Triode Feb 21 '14 at 14:07
  • I have already mentioned it. please read the question completely. i have mentioned that i have been trying to use intents but passing application name would'nt do anything – Hassaan Rabbani Feb 21 '14 at 14:08
  • would the application you want to start be the same everytime? If this is the case there are ways to get the package name.. – Dage Feb 21 '14 at 14:13
  • 2
    You have to pass the package name not the application name, a detailed answer will be this http://stackoverflow.com/questions/2780102/open-another-application-from-your-own-intent – Triode Feb 21 '14 at 14:13

2 Answers2

2

I wrote a method once which returned all installed apps with their package and display name.

public static List<PInfo> getInstalledApps(Context context) {
   List<PInfo> result = new ArrayList<PInfo>();        
   List<PackageInfo> packs = context.getPackageManager().getInstalledPackages(0);

    for(int i=0;i<packs.size();i++) {           
       PackageInfo p = packs.get(i);
       PInfo fileInfo = new PInfo();
       fileInfo.appname =  p.applicationInfo.loadLabel(context.getPackageManager()).toString();
       fileInfo.pname = p.packageName;
       fileInfo.versionName = p.versionName;
       fileInfo.versionCode = p.versionCode;
       fileInfo.icon = p.applicationInfo.loadIcon(context.getPackageManager());
       result.add(fileInfo);
    }   
    return result;
}

Maybe you could search the package name by the display name and create an intent with that package name.

CSchulz
  • 10,102
  • 9
  • 54
  • 107
Aqid
  • 76
  • 2
0

If you need to start Astro File Manager to pick a file, then you can start

final Intent getContent = new Intent(Intent.ACTION_GET_CONTENT);
//check if there are any app to handle. If not, you must not call startActivity.
if (!getPackageManager.queryIntentActivities(getContent, 0).isEmpty()) {
    startActivity(new Intent(Intent.ACTION_GET_CONTENT));
}

Note if there is an app which has defaults for GET_CONTENt you will not see a chooser. You can force chooser by creating a chooser intent

startActivity(Intent.createChooser(new Intent(Intent.ACTION_GET_CONTENT), "Pick an app"));

Don't forget to check if queryIntentActivities are not empty b

If you just want to start Astro explicitly, you must use it's package name

startActivity(getPackageManager().getLaunchIntentForPackage(ASTRO_PACKAGE));

Where ASTRO_PACKAGE can be found as

adb shell pm list packages astro

Where

  • adb shell starts next command in adb shell
  • pm starts package manager app
  • list packages command of package manager
  • astro is a filter parameter for list packages command
Yaroslav Mytkalyk
  • 16,503
  • 10
  • 70
  • 96