Android一些问题的解决方案

1.强行停止一个应用

首先需要权限

<!-- 系统权限,强行停止一个应用 -->
    <uses-permission android:name="android.permission.FORCE_STOP_PACKAGES" />

非源码环境使用反射来完成操作

/**
     * 强行停止一个应用
     * 
     * @param pkgName
     */
    private void forceStopPackage(String pkgName) {
        ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        Method method;
        try {
            method = Class.forName("android.app.ActivityManager").getMethod(
                    "forceStopPackage", String.class);
            method.invoke(am, pkgName);
        } catch (Exception e) {
            Log.e("MainActivity", "Exception when forcing stop app:" + pkgName);
        }
    }

 

读取系统中的一些属性:

/**
     * 从系统属性中读取某一字段对应的信息
     * 
     * @param context
     * @return
     */
    private static boolean isWinLauncherFromSysArg(Context context) {
        Boolean isWinLauncher = SystemProperties.getBoolean(
                "abc.iswin_on_first_launch", true);
        return isWinLauncher;
    }

 

posted @ 2017-07-22 11:59  BlogCommunicator  阅读(210)  评论(0编辑  收藏  举报