【问题标题】:Control the uninstaller action of an Android App from code从代码控制 Android 应用程序的卸载程序操作
【发布时间】:2021-04-24 19:54:42
【问题描述】:

我正在尝试在可以卸载应用程序之前执行一些卸载前活动。我是 Android 开发的新手。 我正在尝试的广播接收器不起作用。 我想使用上下文注册的接收器。 任何建议都会有所帮助

【问题讨论】:

    标签: java android


    【解决方案1】:

    如果您想以编程方式卸载任何应用程序。您需要应用程序包名称。

    清单(并非每个 API 级别都需要):

    <uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES"/>
    

    Java:

    Uri packageURI = Uri.parse("package:"+"your.packagename.here");
    Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
    startActivity(uninstallIntent);
    

    stackoverflow question

    获取应用的包名

    PackageManager pm = getPackageManager();
        Intent main = new Intent(Intent.ACTION_MAIN, null);
        main.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> packages = pm.queryIntentActivities(main, 0);
    
        ArrayList<String> app_name_list = new ArrayList<String>();
        ArrayList<String> app_package_list = new ArrayList<String>();
    
        for(ResolveInfo resolve_info : packages) {
            try {
                package_name = resolve_info.activityInfo.packageName;
                app_name = (String)pm.getApplicationLabel(
                        pm.getApplicationInfo(package_name
                                , PackageManager.GET_META_DATA));
                boolean same = false;
                for(int i = 0 ; i < app_name_list.size() ; i++) {
                    if(package_name.equals(app_package_list.get(i)))
                        same = true;
                }
                if(!same) {
                    app_name_list.add(app_name);
                    app_package_list.add(package_name);
                }
                app_name = app_name.toLowerCase();
                package_name = package_name.toLowerCase();
                applicationArray.put(app_name,package_name);
                Log.i("Check", "package = <" + package_name + "> name = <" + app_name + ">");
               //Log.d("APPLICATION_ARRAY", String.valueOf(applicationArray));
            } catch(Exception e) { }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-22
      • 2012-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 2012-04-13
      • 2011-01-01
      相关资源
      最近更新 更多