【问题标题】:Can I access android's "/system","/data",and "/mnt" with FileProvider ? If so,how?我可以使用 FileProvider 访问 android "/system","/data" 和 "/mtn" 吗?如果是这样,怎么做?
【发布时间】:2018-06-02 15:23:06
【问题描述】:

我正在尝试创建一个应用程序,将已安装的 apk 保存在用户存储中(我们可以用来存储我们自己的文件的普通手机内部存储器)。我用普通的“Uri.fromFile()”做得很好。但是当我使用“FileProvider.getUriFromFile()”时,它显示以下错误:

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.ragib.apkbackup, PID: 13200
              java.lang.IllegalArgumentException: Failed to find configured root that contains /data/app/com.example.ragib.apkbackup-1/base.apk
                  at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:738)
                  at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:417)
                  at com.example.ragib.apkbackup.MainActivity$7$2.onMenuItemClick(MainActivity.java:502).........................[and many more]

我的清单文件是:

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="@string/authority"
        android:grantUriPermissions="true"
        android:exported="false">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/shareable_paths" />
    </provider>

    <activity
        android:name=".MainActivity"
 android:configChanges="orientation|screenSize|keyboardHidden|screenLayout">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

元数据资源是:

<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="device_app_path" path="system/"/>
<external-path name="sd_card_app_path" path="data/"/>
<external-path name="system_app_path" path="mnt/asec/"/>
</paths>

我知道发生错误是因为“外部路径”与 Environment.getExternalStorageDirectory() 相同,并且不包含 /system...

我的问题是,有什么方法可以访问这些文件夹吗? 我只是一个初学者。对不起,如果这个问题很愚蠢:(

【问题讨论】:

    标签: android android-fileprovider


    【解决方案1】:

    有什么方法可以访问这些文件夹吗?

    不适用于FileProvider。你需要自己写ContentProvider

    【讨论】:

      【解决方案2】:

      你尝试过这样的事情吗?

      <root-path
          name="mount"
          path="/mnt/" />
      

      【讨论】:

        猜你喜欢
        • 2011-01-21
        • 2023-04-10
        • 2012-04-08
        • 2021-06-30
        • 2017-11-14
        • 2017-09-26
        • 1970-01-01
        • 1970-01-01
        • 2020-01-21
        相关资源
        最近更新 更多