Opening System Application Using Intent

前端 未结 2 931
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!
                }
            }
        }
    }
    

提交回复
热议问题