簡體   English   中英

如何強制卸載應用以進行更新?

[英]How to force app uninstall in order to update?


我犯了一個錯誤,顯然只有卸載然后再安裝我的應用程序才能解決。

我向用戶傳遞了一條消息,但似乎沒有人將其卸載。

AFAIK,如果我更改證書文件,Play商店將不允許我上載該應用程序,顯然我也不想上載一個新的應用程序。

有沒有一種方法可以強制卸載以進行更新?

謝謝!

沒有killswitch可以遠程強制卸載(那將是安全的噩夢)。 可以在Google Play上發布固定版本,然后等待用戶升級。

我不知道這是否可以幫助您,但我有同樣的問題。 對我來說,解決方案是,每當用戶打開應用程序版本時,我都會對其進行檢查,並將其與存儲在apache服務器上的版本代碼(在checkversion.php文件中)進行比較。 如果版本不匹配,我將顯示一個不可取消的對話框,要求用戶進入市場並下載更新。

這是一個示例(請記住,我使用Volley庫來處理連接):

    public class UpdateManager {

        private Activity ac;
        private HashMap<String,String> params;

        public UpdateManager(Activity ac) {
            this.ac = ac;
        }

        public void checkForUpdates() {
            Log.d("UpdateManager","checkForUpdates() - Started...");

            params = new HashMap<String,String>();
            params.put("request","checkforupdates");
            try {
                params.put("versioncode", String.valueOf(ac.getPackageManager().getPackageInfo(ac.getPackageName(), 0).versionCode));
            } catch (NameNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (Helper.isInternetAvailable(ac)) { //this is a class i made to check internet connection availability
                checkAppVersion();
            } else { Log.d("UpdateManager","CheckForUpdates(): Impossible to update version due to lack of connection"); }
        }

        private void checkAppVersion() {
            Log.d("UpdateManager","checkAppVersion() - Request started...");

            JsonObjectRequest req = new JsonObjectRequest("http://yourserver/checkappversion.php", new JSONObject(params),
                    new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    if (response != null && response.has("result")) {
                        try {
                            Log.d("UpdateManager","checkAppVersion() - Request finished - Response: "+response.getString("result"));
                            if (response.getString("result").matches("updaterequested")) { //Update requested. Show the relative dialog
                                Log.d("UpdateManager","Update requested");

                                askUserForUpdate();
                            }
                            else if (response.getString("result").matches("current")) { //Same version. Do nothing 
                                Log.d("UpdateManager","Version is up to date");
                            }
                            else if (response.getString("result").matches("error")) { //You can return an error message if error occurred on server
                                Log.d("UpdateManager","checkappversion Error - "+response.getString("error"));
                            }

                            VolleyLog.v("Response:%n %s", response.toString(4));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("UpdateManager","Volley Error - "+error.getMessage());
                }
            });
            req.setRetryPolicy(new DefaultRetryPolicy(60000,0,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
            ConnectionController.getInstance().addToRequestQueue(req);
        }

        public void askUserForUpdate() {
            final Dialog diag = new Dialog(ac);
            diag.requestWindowFeature(Window.FEATURE_NO_TITLE);
            diag.setContentView(R.layout.updatemanager_requestupdate_dialog);
            diag.setCancelable(false);
            diag.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
            TextView t = (TextView)diag.findViewById(R.id.requestupdate_dialog_main_text);
            ImageView im_ok = (ImageView)diag.findViewById(R.id.requestupdate_dialog_ok);
            ImageView im_canc = (ImageView)diag.findViewById(R.id.requestupdate_dialog_canc);
            t.setText(ac.getResources().getString(R.string.update_manager_askuserforupdate));
            im_canc.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    diag.dismiss();
                    ac.finish();
                }
            });
            im_ok.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse("market://details?id="+ac.getPackageName()));
                    diag.dismiss();
                    ac.startActivity(intent);
                    ac.finish();
                }
            });
            diag.show();
        }
    }

然后,當您的主要活動(或登錄活動)開始時,您可以使用它:

     UpdateManager updateManager = new UpdateManager(MainActivity.this); //i assume MainActicity as the calling activity
     updateManager.checkForUpdates();

顯然,這必須在應用程序代碼中實現,因此,第一次,您僅需依靠用戶即可手動升級它。 但是,如果將來遇到相同的問題,這會有所幫助。

這是我個人代碼的摘錄,因此您必須根據需要對其進行重新排列。 希望這對某人有幫助。

用戶應該能夠轉到Settings > Applications > Manage Applications然后選擇要刪除的應用程序。 我從來沒有見過無法通過這種方式刪除應用程序的情況,除非是內置應用程序需要root用戶設備才能刪除的情況。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM