을 사용할 때 사용자 정의 자동 다운로드를하고이내 응용 프로그램에서 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);
}
};
안드로이드 매니페스트처럼 작동 APK를 설치 의도를 처리하기 위해 찾을 수 없습니다 활동 :
<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 (일부 미안 이유 때문에 = 경로 태그)
외부 경로 이름 = "MyFolder에"경로를 잘라 "."/>
,691
파일이 onComplete를 다운로드 완료호출되지만 activiy가 시작되지 않습니다
활동이 의도를 처리하기 위해 발견 {행위 = android.intent.action.VIEW DAT = 내용 : //com.myapp/myfolder/myfile.apk 일반은 = 응용 프로그램/vnd.android.package 아카이브 FLG =은 0x4000000}
정상적인 파일을 사용하여 : // 그것은
이 있는가 작동 하는가 내가 뭔가 파일 제공자를 사용할 때 누락 되었습니까? 파일이 없기 때문에 활동이 시작되지 않습니까? 추가 권한이 필요합니까? (현재 인터넷에 연결되어 있으며 외부 저장소에 읽기 및 쓰기)
'파일을 찾을 수 없어서 활동이 시작되지 않습니까? '. 활동을 찾을 수 없다는 메시지입니다. – greenapps
"if"mime 형식을 "*/*"로 대체하면 응용 프로그램 선택이 열리지 만 "파일 관리자"를 선택하면 열어서 루트에 남습니다. 그래서 파일이 실제로 발견되지 않는 FileProvider를 사용하여 궁금합니다. – Johny19
"file"변수를 어디에 선언 했습니까? – emaillenin