<pre name="code" class="java">ApplicationInfo info = null;
try {
info = getPackageManager().getApplicationInfo("com.svse.test", PackageManager.GET_UNINSTALLED_PACKAGES);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (info == null) {
Toast.makeText(MainActivity.this, "该应用未安装", Toast.LENGTH_SHORT).show();
DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Uri uri = Uri.parse("fileUrl");
Request request = new Request(uri);
//设置允许使用的网络类型,这里是移动网络和wifi都可以
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
//禁止发出通知,既后台下载,如果要使用这一句必须声明一个权限:android.permission.DOWNLOAD_WITHOUT_NOTIFICATION
//request.setShowRunningNotification(false);
//不显示下载界面
request.setVisibleInDownloadsUi(false);
/*设置下载后文件存放的位置,如果sdcard不可用,那么设置这个将报错,因此最好不设置如果sdcard可用,下载后的文件 在/mnt/sdcard/Android/data/packageName/files目录下面,如果sdcard不可用,设置了下面这个将报错,不设置,下载后的文件在/cache这个 目录下面*/
//request.setDestinationInExternalFilesDir(this, null, "tar.apk");
long id = downloadManager.enqueue(request);
//把id保存好,在接收者里面要用,最好保存在Preferences里面
} else {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.jhtg.beautygarage",
"com.jhtg.beautygarage.WXEntryActivity"));
int launchFlags = Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED;
intent.setFlags(launchFlags);
intent.setAction("android.intent.action.VIEW");
Bundle bundle = new Bundle();
bundle.putString("uid", "来自测试应用");
bundle.putString("upwd", "来自测试应用");
intent.putExtras(bundle);
startActivity(intent);
}
ComponentName("com.svse.test","com.svse.test.MainActivity");//第一个参数是包名,第二个是参数是启动的页面