Android determines whether an application exists and Android disables the entire application

Source: Internet
Author: User

Identify by package name


    public boolean checkBrowser(String packageName) {

        if (packageName == null || "".equals(packageName))

            return false;

        try {

            ApplicationInfo info = getPackageManager().getApplicationInfo(

                    packageName, PackageManager.GET_UNINSTALLED_PACKAGES);

            return true;

        } catch (NameNotFoundException e) {

            return false;

        }

    }



Determine the activity in the package



        Intent intent = new Intent(Intent.ACTION_VIEW);

        intent.setClassName("com.android.settings", //$NON-NLS-1$


                "com.android.settings.InstalledAppDetails"); //$NON-NLS-1$


        intent.putExtra("com.android.settings.ApplicationPkgName", //$NON-NLS-1$


                mCurrentPkgName);

        List<ResolveInfo> acts = getPackageManager().queryIntentActivities(

                intent, 0);

        if (acts.size() > 0) {

            startActivity(intent);

        } else {

            Toast.makeText(this,

                    getString(R.string.failed_to_resolve_activity),

                    Toast.LENGTH_SHORT).show();

        }




Android disables the entire application


When an application is no longer used, you usually need to disable the application. You can use the following method to disable the Android Application:

Method 1: first obtain the ID of the current process and then kill the process.
Android. OS. process. killprocess (Android. OS. process. mypid ())

Method 2: Terminate the currently running Java virtual machine, resulting in program termination
System. Exit (0 );

Method 3: Force disable all executions associated with the package
Activitymanager manager = (activitymanager) getsystemservice (context. activity_service );
Manager. restartpackage (getpackagename ());
<Uses-Permission Android: Name = "android. Permission. restart_packages"/>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.