0

I am creating an home replacement app for android(Launcher) and I want to place the sms , call, contacts ,gallery and browser apps in the home screen. How can I know the package name for them.

If the user is using a custom contact app as the default one , I need to get the package name of that one and not the android contact app.

How can I achieve this?Thanks.

hybrid
  • 1,255
  • 2
  • 17
  • 42

2 Answers2

2

You can use this code to get Intent to those thing. The problomatic one is the SMS one.

For sms:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(ctx);
                Intent lunchIntent;
                if (defaultSmsPackageName != null) {
                    launchIntent = pm.getLaunchIntentForPackage(defaultSmsPackageName);
                } else {
                    String SMS_MIME_TYPE = "vnd.android-dir/mms-sms";
                    launchIntent = new Intent(Intent.ACTION_MAIN);
                    launchIntent.setType(SMS_MIME_TYPE);
                }
            } else {
                String SMS_MIME_TYPE = "vnd.android-dir/mms-sms";
                launchIntent = new Intent(Intent.ACTION_MAIN);
                launchIntent.setType(SMS_MIME_TYPE);
            }

For call:

     Intent intent = new Intent(Intent.ACTION_DIAL);

For browser:

Intent intent;
Intent queryIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://www.google.com"));
                ActivityInfo af = queryIntent.resolveActivityInfo(pm, 0);
                intent = new Intent(Intent.ACTION_MAIN);
                intent.setClassName(af.packageName, af.name);

For photos:

 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media"));
                try {
                    context.startActivity(intent);
                } catch (ActivityNotFoundException eee){
                    try {
                        intent = new Intent(Intent.ACTION_VIEW);
                        intent.setType(android.provider.MediaStore.Images.Media.CONTENT_TYPE);
                    } catch (Exception err){
                        Toast.makeText(context, "This app not supported in your device", Toast.LENGTH_LONG).show();
                    }
                }
yshahak
  • 4,996
  • 1
  • 31
  • 37
  • 1
    Thanks , but how will I get the default app name , its image uri and its package name from this? Will I get it by using PackageManager pm = context.getPackageManager(); final ResolveInfo mInfo = pm.resolveActivity(intent, 0); – hybrid Sep 07 '15 at 06:23
  • @yshahak: How about voice app. Let see my question at http://stackoverflow.com/questions/40500143/how-to-get-default-device-assistance-app-in-android-by-code – Jame Nov 09 '16 at 05:11
1

You could try getting the default launch activity for a specific Intent, for example for SMS you do an Intent with an sms:-URI, and from there check the 'default'-Activity its launching, on the way getting its package name and other details.

Get Preferred/Default app on Android

Community
  • 1
  • 1
deubaka
  • 1,447
  • 12
  • 22