2012-07-05 58 views
2

因此,我正在下載內容,並將其下載到內置的下載應用程序中,因爲這是下載管理器的工作原理。我只想讓用戶點擊一個打開內置下載應用程序的按鈕。 繼承人我嘗試:我如何打開內置下載應用程序的android?

btnDownloads.setOnClickListener(new Button.OnClickListener(){ 
    public void onClick(View v) { 
     PackageManager pakMan=MainActivity.context.getPackageManager(); 
     Log.d("bebr", "Making pak"); 
     if(pakMan!=null){ 
      Intent downloadsIntent=new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("com.android.downloads","com.android.downlods.Downloads")); 
      ResolveInfo resolved=pakMan.resolveActivity(downloadsIntent, PackageManager.MATCH_DEFAULT_ONLY); 
      Log.d("bebr","Resolving"); 
      if(resolved!=null){ 
       Log.d("bebr", "Starting"); 
       startActivity(downloadsIntent); 
      } 
     } 
    } 
}); 

好吧終於設法解決方案:

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address"); 
startActivity(LaunchIntent); 
+0

是啊,包的名稱是一個總的猜測。 – Light

+0

繼承人包名稱,但它給出了一個錯誤,他的活動未在te清單中定義(即使它是) 07-05 09:19:01.398: I/ActivityManager(135): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.providers.downloads.ui/.DownloadList} from pid 354 Light

回答

0

你必須知道啓動下載應用程序包的名稱。我不確定它在每個設備上都是如此(儘管可能是)。您可以通過觀察Logcat並啓動它來找到它,您應該在日誌中看到包含該軟件包名稱的一行。

但是你完全可以跳過下載應用程序並直接啓動安裝程序包(也就是當用戶選擇下載應用程式的APK會發生什麼)

只是在路徑填充該文件在以下片段:

File appFile = new File("/path/to/your/file.apk"); 
Uri packageURI = Uri.parse("file:/"+ appFile.getAbsolutePath()); 
Intent installIntent = new Intent(Intent.ACTION_VIEW); 
installIntent.setDataAndType(Uri.fromFile(appFile),"application/vnd.android.package-archive"); 
startActivity(installIntent); 
+0

我不一定使用下載管理器來下載應用程序。你的建議雖然有幫助,但現在我知道下載應用程序的pakage(它給出了一個錯誤,雖然活動沒有在清單中定義,所以它不打開): $ 07-05 09:19:01.398:I/ActivityManager(135 ):從pid 354開始{act = android.intent.action.MAIN cat = [android.intent.category.LAUNCHER] flg = 0x10200000 cmp = com.android.providers.downloads.ui/.DownloadList} – Light

相關問題