Отказ от разрешения: чтение контента URI Sapiuiprovider. Требовать, чтобы поставщик был экспортирован, или грантюрпирмис ⇐ Android
-
Anonymous
Отказ от разрешения: чтение контента URI Sapiuiprovider. Требовать, чтобы поставщик был экспортирован, или грантюрпирмис
Привет,
Я пытаюсь открыть PDF, и он работает довольно хорошо, когда: PDF уже загружен в G -gr/p>
raw Ошибка. < /p>
my androidmanifest.xml < /p>
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
< /code>
app.json
{
"name": "DocReader",
"displayName": "DocReader",
"permissions": [
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.ACCESS_MEDIA_LOCATION"
]
}
< /code>
mainactivity.kt
package com.docreader
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.core.content.FileProvider
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.ReactApplication
import com.facebook.react.modules.core.DeviceEventManagerModule
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate
import java.io.File
import java.io.FileOutputStream
class MainActivity : ReactActivity() {
override fun getMainComponentName(): String = "DocReader"
override fun createReactActivityDelegate(): ReactActivityDelegate =
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
intent?.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent?.let { handleIncomingFile(it) }
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
handleIncomingFile(intent)
}
private fun handleIncomingFile(intent: Intent) {
val uri: Uri? = when (intent.action) {
Intent.ACTION_VIEW -> intent.data
Intent.ACTION_SEND -> intent.getParcelableExtra(Intent.EXTRA_STREAM)
else -> null
}
if (uri != null) {
try {
val inputStream = contentResolver.openInputStream(uri)
val file = File(cacheDir, "temp_imported.pdf")
val outputStream = FileOutputStream(file)
inputStream?.copyTo(outputStream)
inputStream?.close()
outputStream.close()
// Convert file to content URI using FileProvider
val localUri = FileProvider.getUriForFile(this, "${packageName}.fileprovider", file)
val reactContext = (application as ReactApplication)
.reactNativeHost
.reactInstanceManager
.currentReactContext
reactContext?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
?.emit("OpenPDF", localUri.toString())
} catch (e: Exception) {
Log.e("PDF_IMPORT", "Failed to copy file", e)
}
}
}
}
< /code>
Я новичок в реагировании, но я не мог найти решение даже после нескольких часов расследования. Если вам нужно больше файлов, пожалуйста, дайте мне знать. < /P>
Есть идеи о том, что я могу изменить? Почему это блокирует? Как заставить это работать?
Спасибо, лучше!
Подробнее здесь: https://stackoverflow.com/questions/796 ... vider-be-e
Привет,
Я пытаюсь открыть PDF, и он работает довольно хорошо, когда: PDF уже загружен в G -gr/p>
raw Ошибка. < /p>
my androidmanifest.xml < /p>
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
< /code>
app.json
{
"name": "DocReader",
"displayName": "DocReader",
"permissions": [
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.ACCESS_MEDIA_LOCATION"
]
}
< /code>
mainactivity.kt
package com.docreader
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.core.content.FileProvider
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.ReactApplication
import com.facebook.react.modules.core.DeviceEventManagerModule
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate
import java.io.File
import java.io.FileOutputStream
class MainActivity : ReactActivity() {
override fun getMainComponentName(): String = "DocReader"
override fun createReactActivityDelegate(): ReactActivityDelegate =
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
intent?.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent?.let { handleIncomingFile(it) }
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
handleIncomingFile(intent)
}
private fun handleIncomingFile(intent: Intent) {
val uri: Uri? = when (intent.action) {
Intent.ACTION_VIEW -> intent.data
Intent.ACTION_SEND -> intent.getParcelableExtra(Intent.EXTRA_STREAM)
else -> null
}
if (uri != null) {
try {
val inputStream = contentResolver.openInputStream(uri)
val file = File(cacheDir, "temp_imported.pdf")
val outputStream = FileOutputStream(file)
inputStream?.copyTo(outputStream)
inputStream?.close()
outputStream.close()
// Convert file to content URI using FileProvider
val localUri = FileProvider.getUriForFile(this, "${packageName}.fileprovider", file)
val reactContext = (application as ReactApplication)
.reactNativeHost
.reactInstanceManager
.currentReactContext
reactContext?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
?.emit("OpenPDF", localUri.toString())
} catch (e: Exception) {
Log.e("PDF_IMPORT", "Failed to copy file", e)
}
}
}
}
< /code>
Я новичок в реагировании, но я не мог найти решение даже после нескольких часов расследования. Если вам нужно больше файлов, пожалуйста, дайте мне знать. < /P>
Есть идеи о том, что я могу изменить? Почему это блокирует? Как заставить это работать?
Спасибо, лучше!
Подробнее здесь: https://stackoverflow.com/questions/796 ... vider-be-e
Мобильная версия