package am.project.x.activities.develop.test;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.Toast;

import am.project.x.R;
import am.project.x.activities.BaseActivity;

public class TestActivity extends BaseActivity {

    @Override
    protected int getContentViewLayoutResources() {
        return R.layout.activity_test;
    }

    @Override
    protected void initResource(Bundle savedInstanceState) {
        setSupportActionBar(R.id.test_toolbar);
    }

    @Override
    protected void onResume() {
        super.onResume();
        Toast.makeText(getApplicationContext(), Boolean.toString(checkApkExist(getApplicationContext(), "com.tencent.mm")), Toast.LENGTH_SHORT).show();
    }

    @SuppressWarnings("all")
    public boolean checkApkExist(Context context, String packageName) {
        try {
            ApplicationInfo info = context.getPackageManager().getApplicationInfo(packageName,
                    PackageManager.GET_UNINSTALLED_PACKAGES);
            if (info != null)
                return true;
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
        return false;
    }

    public static void startActivity(Context context) {
        context.startActivity(new Intent(context, TestActivity.class));
    }
}

@@ -122,131 +122,17 @@
 oid.
-content.pm.ApplicationInfo;%0Aimport android.content.pm.PackageManager;%0Aimport android.os.Bundle;%0Aimport android.widget.Toast
+os.Bundle
 ;%0A%0Ai
@@ -432,24 +432,24 @@
 nceState) %7B%0A
+
         setS
@@ -495,694 +495,8 @@
  %7D%0A%0A
-    @Override%0A    protected void onResume() %7B%0A        super.onResume();%0A        Toast.makeText(getApplicationContext(), Boolean.toString(checkApkExist(getApplicationContext(), %22com.tencent.mm%22)), Toast.LENGTH_SHORT).show();%0A    %7D%0A%0A    @SuppressWarnings(%22all%22)%0A    public boolean checkApkExist(Context context, String packageName) %7B%0A        try %7B%0A            ApplicationInfo info = context.getPackageManager().getApplicationInfo(packageName,%0A                    PackageManager.GET_UNINSTALLED_PACKAGES);%0A            if (info != null)%0A                return true;%0A        %7D catch (PackageManager.NameNotFoundException e) %7B%0A            return false;%0A        %7D%0A        return false;%0A    %7D%0A%0A
     

测试 更新