个人知识点总结

时间:2023-02-02 11:55:35
#卸载#

    1.卸载
        viewHolder.iv_antivirusitem_clear.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    //卸载应用
                    Intent intent = new Intent();
                    intent.setAction("android.intent.action.DELETE");
                    intent.addCategory("android.intent.category.DEFAULT");
                    intent.setData(Uri.parse("package:"+antiVirusInfo.packagename));
                    startActivity(intent);
                    //将卸载应用的bean保存到卸载应用的标示bean类中
                    deleteAntiVirusInfo = antiVirusInfo;
                }
            });
    2.监听卸载广播事件
        1.创建监听卸载的广播接受者
            private class UninstallReceiver extends BroadcastReceiver{

                @Override
                public void onReceive(Context context, Intent intent) {
                    
                }
            }
        2.代码注册监听卸载的广播接受者
            //代码注册一个监听卸载应用的广播接受者
            uninstallReceiver = new UninstallReceiver();
            //设置过滤条件
            IntentFilter filter = new IntentFilter();
            filter.setPriority(1000);
            filter.addAction(Intent.ACTION_PACKAGE_REMOVED);//设置接受卸载应用的广播接受者
            //设置接受广播事件的data
            filter.addDataScheme("package");//参数:卸载页面中过滤条件的data
            registerReceiver(uninstallReceiver, filter);
        3.在广播接受者的onreceive方法中进行界面更新操作
            @Override
            public void onReceive(Context context, Intent intent) {
                //更新界面
                //1.从集合中删除相应的应用的bean对象
                list.remove(deleteAntiVirusInfo);
                myadapter.notifyDataSetChanged();
                //2.更新的提示文本,如果卸载一下,就从病毒个数中减去一个
                totalAntivirus--;
                //重新判断病毒的个数,从而去更新提示文本
                if (totalAntivirus > 0) {
                    // 有病毒
                    tv_antivirus_antivirustext.setText("您的手机发现"
                            + totalAntivirus + "个病毒");
                } else {
                    // 没有病毒
                    tv_antivirus_antivirustext
                            .setText("您的手机很安全");
                }
            }
        4.在ondestory方法中注销广播接受者
            @Override
            protected void onDestroy() {
                super.onDestroy();
                unregisterReceiver(uninstallReceiver);
            }


#快捷方式#

     <permission
        android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="normal"
        android:label="@string/permlab_install_shortcut"
        android:description="@string/permdesc_install_shortcut" />

    自定义权限:就是给某个组件使用的权限

    android允许创建多个快捷方式
    
    创建操作
        /**
         * 创建快捷方式
         */
        private void shorcut() {
            if (!SharedPrefUtil.getBoolean(getApplicationContext(), Constants.SHORT_CUT, false)) {
                //创建快捷方式,其实就是给桌面发送一个广播事件
                //<action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
                Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
                //1.设置快捷方式的名称
                intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "手机卫士79");
                //2.设置快捷方式的图标
                //id : 图片资源的id
                Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
                intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
                //3.设置快捷方式的操作
                Intent value = new Intent(this,SplashActivity.class);
                intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, value);
                sendBroadcast(intent);
                //保存创建快捷方式的标示
                SharedPrefUtil.putBoolean(getApplicationContext(), Constants.SHORT_CUT, true);
            }
        }

    权限:
    <!-- 创建快捷方式的权限,自定义权限 -->
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>


#log的管理工具#

    目的:就是为在应用开启完毕,上线的时候,将log全部屏蔽掉
    public class LogUtil {

        private static boolean isEnable = false;
        
        public static void e(String tag,String msg){
            if (isEnable) {
                Log.e(tag, msg);
            }
        }
    
    }

#bug收集#

    测试 -> 上线 -> bug收集(收集用户使用时程序出现的bug,当程序崩溃的时候,将崩溃的信息保存到文件中,当用户再次打开手机的时候,通过发送将文件发送给服务器)'

    1.创建application
        public class MyApplication extends Application {
    2.清单文件使用
        <application
            android:name="com.itheima.mobilesafe79.activity.MyApplication"
    3.bug收集
        @Override
        public void onCreate() {
            super.onCreate();
            System.out.println("MyApplication启动了");
            //监听当前进程的异常
            Thread.currentThread().setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
        }
        //异常的监听
        private class MyUncaughtExceptionHandler implements UncaughtExceptionHandler{
            //当有未捕获的异常的时候调用
            //Throwable : Error和Exception的父类
            @Override
            public void uncaughtException(Thread thread, Throwable ex) {
                System.out.println("哥发现异常,哥捕获了...");
                ex.printStackTrace();
                try {
                    //将异常保存到文件中
                    ex.printStackTrace(new PrintStream(new File("/mnt/sdcard/log.txt")));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                //杀死我们自己的应用,自杀
                //myPid() : 获取我们自己的pid
                //killProcess :杀死进程
                //闪退
                android.os.Process.killProcess(android.os.Process.myPid());
            }
            
        }

#混淆#

    目的:防止别人反编译应用程序查看我们的代码,增加阅读的难度
    proguard-android.txt : 设置混淆的操作

    1.将sdk\tools\proguard\proguard-android.txt拷贝到工程的根目录下
    2.修改project.properties文件
        proguard.config=proguard-android.txt:proguard-project.txt代码放开