Trong ứng dụng của tôi, tôi có một ô tô tải tùy chỉnh và cài đặt APK nó hoạt động nhưKhông Hoạt động phát hiện để xử lý Ý định khi sử dụng FileProvider
// auto register for the complete download
activity.registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
// Download the file through DownloadManager
String destination = Environment.getExternalStorageDirectory() + "/";
String fileName = "myfile.apk";
destination += fileName;
final Uri uri = Uri.parse("file://" + destination);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(apkUrl));
request.setDescription("description");
request.setTitle("title");
request.setDestinationUri(uri);
final DownloadManager manager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
final long downloadId = manager.enqueue(request);
onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
Intent install = new Intent(Intent.ACTION_VIEW);
// BEFORE working doing this
//install.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//install.setDataAndType(uri,
// manager.getMimeTypeForDownloadedFile(downloadId));
// Using file provider it doesnt work
Uri apkUri = FileProvider.getUriForFile(AutoUpdate.this,
"com.myapp", file);
install.setDataAndType(apkUri,manager.getMimeTypeForDownloadedFile(downloadId));
activity.startActivity(install);
activity.unregisterReceiver(this);
}
};
manifest Android này:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.myapp"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
Provider_path (Xin lỗi cho một số lý do để cắt thẻ đường dẫn)
tên đường dẫn bên ngoài = "myfolder" path = "." />
Khi tập xong để tải onComplete được gọi nhưng activiy không bắt đầu:
Không Hoạt động phát hiện để xử lý Ý định {hành động = android.intent.action.VIEW dat = Nội dung: //com.myapp/myfolder/myfile.apk typ = application/vnd.android.package-archive FLG = 0x4000000}
Khi sử dụng các tập tin bình thường: // nó làm việc
có một cái gì đó tôi thiếu khi sử dụng nhà cung cấp tệp? Hoạt động không bắt đầu vì không tìm thấy tệp? Tôi có cần thêm sự cho phép không? (tại thời điểm này tôi có INTERNET, READ và VIẾT trên bộ nhớ ngoài)
'Hoạt động không bắt đầu vì không tìm thấy tệp '. Thông báo là hoạt động không được tìm thấy. – greenapps
Lưu ý rằng "nếu" tôi thay thế loại mime bằng "*/*", nó sẽ mở lựa chọn ứng dụng nhưng khi tôi chọn "trình quản lý tệp", nó chỉ mở nó và giữ nguyên gốc. Đó là lý do tại sao tôi tự hỏi bằng cách sử dụng FileProvider tệp không thực sự được tìm thấy? – Johny19
bạn đã khai báo biến "tệp" ở đâu? – emaillenin