Java 如何下载apk并在android 6上安装
如何在Android编程中下载和安装apk文件。安卓6及以上版本存在问题Java 如何下载apk并在android 6上安装,java,android,Java,Android,如何在Android编程中下载和安装apk文件。安卓6及以上版本存在问题 dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(file_url)); enqueue = dm.enqueue(request); receiver3 = new BroadcastReceiver()
dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(file_url));
enqueue = dm.enqueue(request);
receiver3 = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
long downloadId = intent.getLongExtra(
DownloadManager.EXTRA_DOWNLOAD_ID, 0);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(enqueue);
Cursor c = dm.query(query);
if (c.moveToFirst()) {
int columnIndex = c
.getColumnIndex(DownloadManager.COLUMN_STATUS);
if (DownloadManager.STATUS_SUCCESSFUL == c
.getInt(columnIndex)) {
String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE));
String uriString2 = c.getString(c.getColumnIndex(DownloadManager.COLUMN_URI));
Intent intent2 = new Intent(Intent.ACTION_VIEW);
intent2.setDataAndType(Uri.fromFile(new File(uriString2)), "application/vnd.android.package-archive");
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent2);
}
}
}
}
};
StartActivity.this.registerReceiver(receiver3, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
当下载完成并安装错误:解析
错误时,解析包
堆栈时出现问题
也许这个链接对你有用
https://stackoverflow.com/questions/4604239/install-application-programmatically-on-android
同时检查以下影响安装的因素
文件可能下载不完整。
应用程序可能不适合您的设备配置。
安全问题-但您可以从设置选项启用。
APK文件已损坏。您可以显示与您的问题相关的任何屏幕截图吗?在“file file=new file(dir,“App.APK”);“file file=new file(uriString2)”上的dir是什么?不,不工作。当startactivity(intent)安装时,我有错误。我的错误解析错误解析软件包时出现问题android 6上的错误解析错误解析软件包时出现问题
https://stackoverflow.com/questions/4604239/install-application-programmatically-on-android