Skip to content Skip to sidebar Skip to footer

Opening System Application Using Intent

I am trying to make a simple application which will send the user to a specific (system installed) app (system settings, calendar, browser, etc.) when clicked by the user from the

Solution 1:

You have to make the call to LaunchComponent which can be done in onCreate first life-cycle callback function

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
     LaunchComponent (packageName, name);
}

updated

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;


publicclassMainActivityextendsActivity {

publicvoidonCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
         LaunchComponent ("com.sec.android.app.controlpanel", "abc?");
    }


publicvoidLaunchComponent(String packageName, String name){
    Intenti=newIntent(Intent.ACTION_MAIN);
    PackageManagermanager= getPackageManager();
    i = manager.getLaunchIntentForPackage(packageName);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    startActivity(i);

}

Solution 2:

In this example you can open system alarm clock app., hope it helps, example activity:

publicclassTestActivityextendsActivity {

    @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        PackageManagerpackageManager=this.getPackageManager();
        if (packageManager != null) {

            IntentAlarmClockIntent=newIntent(Intent.ACTION_MAIN).addCategory(
                        Intent.CATEGORY_LAUNCHER).setComponent(
                                newComponentName("com.android.deskclock", "com.android.deskclock.DeskClock"));

            ResolveInforesolved= packageManager.resolveActivity(AlarmClockIntent, PackageManager.MATCH_DEFAULT_ONLY);
            if (resolved != null) {
                startActivity(AlarmClockIntent);
                finish();
                return;
            } else {
                // required activity can not be located!
            }
        }
    }
}

Post a Comment for "Opening System Application Using Intent"