簡體   English   中英

Android安裝應用程序對話框

[英]Android Install app dialog

我有一個非常簡單的問題,但不知何故無法在stackoverflow上找到解決方案。

我可以從WebView開始下載文件,也可以在下載完成后收聽Broadcast 這是相關的代碼

aWebView.setDownloadListener(new DownloadListener() {
            public void onDownloadStart(String url, String userAgent,
                        String contentDisposition, String mimetype,
                        long contentLength) {
//              Intent i = new Intent(Intent.ACTION_VIEW);
//              i.setData(Uri.parse(url));
//              startActivity(i);

                final String fileName = URLUtil.guessFileName(url,contentDisposition,mimetype);

                        Request request = new Request(
                            Uri.parse(url));
                    request.allowScanningByMediaScanner();
                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName); 
                    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                    dm.enqueue(request);  
            }
        });

現在我需要知道的是,我們可以通過哪種方式以編程方式為該特定下載的應用程序彈出“ Install/Cancel對話框?

您可以嘗試以下方法:

String filePath = "Your file path";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(filePath)),"application/vnd.android.package-archive");
startActivity(intent);

當您使用從應用程序下載的.apk文件時,情況有些特殊嗎?

暫無
暫無

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

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