How to open a installed android app with a button click intent?

前端 未结 1 2018
滥情空心
滥情空心 2020-12-19 10:27

Hi i\'m working on a android launcher for education and I need it to be able to when the user clicks the school tools button it launches the school tools app that is install

相关标签:
1条回答
  • 2020-12-19 11:11

    This code snippet should do exactly what you are trying to achieve

    Intent i;
    PackageManager manager = getPackageManager();
    try {
       i = manager.getLaunchIntentForPackage("com.example.schoolToolApp");
    if (i == null)
        throw new PackageManager.NameNotFoundException();
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    startActivity(i);
    } catch (PackageManager.NameNotFoundException e) {
    
    }
    

    It will just launch another app by its package name

    source - Open another application from your own (intent)

    0 讨论(0)
提交回复
热议问题