Это текущий код, который у меня есть: < /p>
Код: Выделить всё
File f = new File(getExternalFilesDir("documents"), "jhug.pdf");
Uri fileUri = FileProvider.getUriForFile(Recorder.this, "com.noware.oakesn.jibonbondhu.provider", f);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(fileUri);
intent.setType("application/pdf");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try
{
getContentResolver().openInputStream(fileUri);
}
catch (FileNotFoundException e)
{
throw new RuntimeException(e);
}
// Grant permission to all possible handling apps for this type
// Overkill
List resInfoList = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
grantUriPermission(packageName, fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
startActivity(intent);
< /code>
from androidmanifest.xml: < /p>
android:name="androidx.core.content.FileProvider"
android:authorities="com.noware.oakesn.jibonbondhu.provider"
android:exported="false"
android:grantUriPermissions="true"
android:readPermission="android.permission.permRead">
< /code>
из file_paths.xml: < /p>
uri имеет значение Content: //com.noware.oakesn.jibonbondhu.provider/external_files/android/data/com.noware.oakesn.jibonbondhu/files/documents/jhug.pdf
file существует, и OpenInputStream (). GetExternalStoragePublicDirectory (Environment.Directory_Documents). Он не получает разрешения, даже если есть копия файла. Я поместил файлы там с помощью Explorer. < /P>
Ничего в logcat. Похоже, вам нужна примечание от Бога в эти дни, чтобы читать файлы по телефону!
Подробнее здесь: https://stackoverflow.com/questions/795 ... via-intent
Мобильная версия