Opening System Application Using Intent

前端 未结 2 932
Happy的楠姐
Happy的楠姐 2021-01-15 20:57

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 fr

相关标签:
2条回答
  • 2021-01-15 21:04

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

    public class TestActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            PackageManager packageManager = this.getPackageManager();
            if (packageManager != null) {
    
                Intent AlarmClockIntent = 
                    new Intent(Intent.ACTION_MAIN).addCategory(
                            Intent.CATEGORY_LAUNCHER).setComponent(
                                    new ComponentName("com.android.deskclock", "com.android.deskclock.DeskClock"));
    
                ResolveInfo resolved = packageManager.resolveActivity(AlarmClockIntent, PackageManager.MATCH_DEFAULT_ONLY);
                if (resolved != null) {
                    startActivity(AlarmClockIntent);
                    finish();
                    return;
                } else {
                    // required activity can not be located!
                }
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-15 21:09

    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;
    
    
    public class MainActivity extends Activity {
    
    public void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
             LaunchComponent ("com.sec.android.app.controlpanel", "abc?");
        }
    
    
    public void  LaunchComponent (String packageName, String name){
        Intent i = new Intent(Intent.ACTION_MAIN);
        PackageManager manager = getPackageManager();
        i = manager.getLaunchIntentForPackage(packageName);
        i.addCategory(Intent.CATEGORY_LAUNCHER);
        startActivity(i);
    
    }
    
    0 讨论(0)
提交回复
热议问题