How to launch an Activity from another Application in Android

后端 未结 12 1449
春和景丽
春和景丽 2020-11-21 06:02

I want to launch an installed package from my Android application. I assume that it is possible using intents, but I didn\'t find a way of doing it. Is there a link, where t

12条回答
  •  醉梦人生
    2020-11-21 06:46

    If you want to open specific activity of another application we can use this.

    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.fuelgauge.PowerUsageSummary");
    intent.setComponent(cn);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try 
    {
        startActivity(intent)
    }catch(ActivityNotFoundException e){
        Toast.makeText(context,"Activity Not Found",Toast.LENGTH_SHORT).show()
    }
    

    If you must need other application, instead of showing Toast you can show a dialog. Using dialog you can bring the user to Play-Store to download required application.

提交回复
热议问题