Opening System Application Using Intent

前端 未结 2 933
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: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);
    
    }
    

提交回复
热议问题