开发者

Launching installedapplication

开发者 https://www.devze.com 2023-03-21 19:04 出处:网络
How do I launch the installed application? I have installed using below: File file = new File(dir, "App.apk");

How do I launch the installed application?

I have installed using below: File file = new File(dir, "App.apk");

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setD开发者_Python百科ataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");

startActivity(intent);

Second time, I am checking if the package already installed, if yes, I want to launch.

Intent intent = new Intent(com.example.app);


i'm using this method. You should change package and class names.


    private static final String GPS_STATUS_PACKAGE_NAME = "com.eclipsim.gpsstatus2";
    private static final String GPS_STATUS_CLASS_NAME = "com.eclipsim.gpsstatus2.GPSStatus";
   /**
     * Run GpsStatus & toolbox application
     * 
     * @param context
     *            which can start activity
     */
    public static void runGpsStatus(Context context) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setComponent(new ComponentName(GPS_STATUS_PACKAGE_NAME, GPS_STATUS_CLASS_NAME));
        List list = context.getPackageManager().queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);

        if (list.size() > 0) {
            // Have application
            context.startActivity(intent);
        } else {
            // None application
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消