0

I would like to start a default application: browser, contact-book, phone, email, music app, etc. I have found many q/a, like browser opening a specific URL or blank, and here the answer is even "No not possible". But I would like to just open/launch it without telling it to go to a specific URL or sending a mail to someone, etc.

However, I also saw some Home applications where this seems to be working (at least for some apps). On my colleague's device there is for example a different contact-book (no google) which is detected and opened correctly.

I have seen in the Android documentation some intent categories that point to these problems, but these are only >= API.11. So I can't use/test them on my device.

Question: Is it not somehow possible to launch a default application (having the app chooser is of course ok) without providing extra data? If no, what do you think are these Home apps doing (perhaps workarounds are somehow possible).

PS: for the phone app I think, I have a workaround using Intent.ACTION_DIAL without any other information which will open simply the dialer.

UPDATE: I modified the title. Some applications like the address book may not be the same on different devices. So in this case I would like to start the address-book app, whichever this is.

Community
  • 1
  • 1
Carl K.
  • 457
  • 4
  • 16

2 Answers2

1

This answer is not a 100% answer, but some workarounds on some typical applications.

Still open are: music player, address book

Browser: I get a list of applications that handle "http"-data intents, and then I look if one is available in the list of preferred applications.

Intent appFilter = new Intent(Intent.ACTION_VIEW);
appFilter.setData(Uri.parse("http://www.google.com"));
List<ResolveInfo> browserInfoList = pm.queryIntentActivities(appFilter, 0);

List<IntentFilter> outFilters = new ArrayList<IntentFilter>();
List<ComponentName> outActivities = new ArrayList<ComponentName>();
pm.getPreferredActivities(outFilters, outActivities, null);
if(outActivities.size() > 0) {
  for(ComponentName cn : outActivities) {
    String cnClass = cn.getClassName();
    String cnPkg = cn.getPackageName();
    for (ResolveInfo info : browserInfoList) {
      if(info.activityInfo.name.equals(cnClass) && 
        info.activityInfo.packageName.equals(cnPkg)) {
        return cn;
      }
    }
  }
}

In case no default is found, I open a browser chooser dialog, see here.

Phone: as described in the question:

Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);
Community
  • 1
  • 1
Carl K.
  • 457
  • 4
  • 16
0

You can start apps by the function "startActivity" if you know about the canonical app name like "android.com.browser". Do this simple by searching for AndroidManifest.xml in the app source code (look at Codeaurora.com or at github/Cyanogenmod) and grab the app name you want. After you know about the App name ("Activity") implement the code as follows:

Intent intent = new Intent();
intent.setClassName(this, "com.android.browser");
intent.setCategory(Intent.ACTION_MAIN);
startActivity(intent);

THIS is only a example, sometimes you have to put intent extras or data values, this information can be found in the app's AndroidManifest.xml too.

Andreas
  • 1,617
  • 15
  • 18
  • Thanks. Once I know the class or package name of the activity I know how to start it. But I would like to open the default browser (or other application) that is set by the user (for example to Opera or Dolphin) and in case it is not set open the chooser dialog. However, if there is a method to obtain the default application (in case they are set) for a specific category (browse, email, etc), then this might be useful too. – Carl K. Jan 25 '12 at 01:33