2017-01-23 20 views
1

プロバイダを使用して、負荷のテキストファイルERR_UNKNOWN_URL_SCHEMEときのmanifest.xmlにfileprovider

<!-- File Provider --> 
    <provider 
     android:name="android.support.v4.content.FileProvider" 
     android:authorities="com.example.test.fileprovider" 
     android:exported="false" 
     android:grantUriPermissions="true"> 
     <meta-data 
      android:name="android.support.FILE_PROVIDER_PATHS" 
      android:resource="@xml/provider_paths"/> 
    </provider> 

リソースファイルfileprovider

Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".fileprovider", file); 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(uri, "*/*"); 
intent.startActivity(intent); 

<?xml version="1.0" encoding="utf-8"?> 
<paths xmlns:android="http://schemas.android.com/apk/res/android"> 
    <external-path name="external_files" path="."/> 
</paths> 

使用10

リファレンスhere

説明: 私は開いている画像、テキストファイル、PDFファイル、このプロバイダを使用することはできません。 ファイルのテキストファイルを開くと、ERR_UNKNOWN_URL_SCHEMEが表示されます。 私は画像やPDFを開くと、その何もあなたの意思に「FLAG_GRANT_READ_URI_PERMISSION」フラグを追加する必要が何

+0

uri.toString()の値を教えてください。 – greenapps

+0

そしてfile.getAbsolutePath()。 – greenapps

+0

/ストレージ//0/KOOPSv3Sales/KOOPSv3Salesメッセージの添付ファイル/ 29ca8aed.txt –

答えて

0

示していない:

Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".fileprovider", file); 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(uri, "*/*"); 
intent.addFlags(FLAG_GRANT_READ_URI_PERMISSION); 
intent.startActivity(intent); 

https://developer.android.com/reference/android/content/Intent.html#FLAG_GRANT_READ_URI_PERMISSION

FLAG_GRANT_READ_URI_PERMISSION設定した場合は、この受信者をインテント は、 のインテントのデータとそのClipDataで指定されたURIのURIに対して読み取り操作を実行するためのアクセス許可を与えられます。 をIntentのClipDataに適用すると、すべてのURIおよび再帰的な のデータまたはその他のIntentアイテムのClipDataは、 になります。トップレベルインテントの許可フラグのみが使用されます。

関連する問題