Reputation: 375
So I'm downloading stuff and it gets put into the built in downloads app since thats how the download manager works. I just want to the user to click a button which opens the built in downloads app. Heres my try:
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);
}
}
}
});
Ok finally managed to get the solution:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
Upvotes: 2
Views: 2724
Reputation: 5834
Use the DownloadManager.ACTION_VIEW_DOWNLOADS constant:
startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));
Upvotes: 6
Reputation: 46856
You'd have to know the package name to launch the Downloads application. I am not certain that it is the same on every device either (though it may be). You can find it by watching the Logcat and launching it you should see some line in the log that has the package name in it.
However you can skip the downloads app completely and launch the package installer directly (which is what will happen when the user selects your apk in the downloads app)
just fill in the path to the file in the following snippet:
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);
Upvotes: 0