2016-11-28 3 views
0

/Android/data/package.name/files/에있는 일부 파일에 대해 PDF Reader를 여는 방법을 구현하려고합니다. . 적절한 FileProvider를 사용하지 못했지만 방금 추가 한 내용을 찾았습니다. // 작업을 수행했습니다. 그러나 어떤 이유에서 그것들 중 일부를 열 수는 없으며 그 이유를 이해할 수 없습니다. Adobe Reader는 인 텐트의 유효한 pdfs 및 Android의 content : ///를 열지 않습니다.

File file=new File("Direct path to file as string"); 

if(file.exists()){ ///Yes, File Exists 
      try { 

       Intent intent = new Intent(Intent.ACTION_VIEW); 
       Log.v("Authority", context.getApplicationContext().getPackageName()); 
       Log.v("URI", Util.UriForFile(context, file).toString()); 
       intent.setDataAndType(Util.UriForFile(context, file), "application/pdf"); 
       intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
       context.startActivity(intent); 


      } catch (ActivityNotFoundException e) { 
       parent.alert(context.getString(R.string.error_nopdfreader)); 
      } 
} 

실제 방법 Util.UriForFile :

public static Uri UriForFile(Context context, File file){ 
    return Uri.parse("content://"+file.getAbsolutePath()); 
//  if(context==null) 
//   Log.v("Util", "Context is null"); 
// 
//  if(file==null) 
//   Log.v("Util", "File is null"); 
// 
//  if(context.getApplicationInfo()==null) 
//   Log.v("Util", "getApplicationInfo is null"); 
// 
//  return FileProvider.getUriForFile(context, context.getApplicationInfo().packageName+".provider", file); 
} 
+0

가 : - 거의 0 애플 리케이션과 함께 작동합니다 "난 그냥 내용을 추가 발견 // 작업을했다." Adobe Reader에서 작동하는 경우 이는 Adobe Reader의 버그입니다. 그것은 잘못된 'Uri'입니다 (예를 들어, 권한 문자열이 없음). "적절한 FileProvider를 사용하지 못했습니다"- 스택 오버 플로우 문제에 대해 질문하고 [mcve]를 제공하고 세부적으로 "실패한"의미를 설명하십시오. – CommonsWare

+0

음, FileProvider 내 문제의 절반 여기에 설명되어 있습니다 : http://stackoverflow.com/questions/40318116/fileprovider-and-secondary-external-storage. 그 외에도 사용자가 안드로이드/데이터 폴더 이외의 다른 디렉토리를 지정하게하고 보조 저장소에서도 content : ///를 사용하는 것이 유일한 방법이었습니다 – Myoch

+0

FileProvider 내부 저장소에서 Adobe는 일부 특정 파일을 열지 않습니다. 열리지 않는 파일은 실제 파일 이름에 "% 20"이있는 파일 인 것처럼 보입니다 (공백이 없지만 FileProvider에서 "% 2520"으로 인코딩 된 실제 "% 20"문자). – Myoch

답변

0

좋아, I는 「마법」FileProvider (라인의 주석)의 사용으로 돌아가서, 2 개 변형을 수행하여 문제 해결 :

  1. 액세스하기위한 의도의 플래그
  2. 은 "비 문서화 된"파일 경로를 추가하는 FLAG_GRANT_READ_URI_PERMISSION을 (추가 안드로이드/데이터)의 외부에있는 파일을 보내고 :

    <root-path path="/storage/" name="root_test" />