내 응용 프로그램간에 파일을 공유하고 싶습니다. File Provider를 사용하려고했지만 작동하지 않았습니다. 내 filepaths.xml이FileProvider를 사용하여 내부 저장소 공유
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mdl.test.plug">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".ModuleActivity"
android:label="@string/title_activity_module"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mdl.test.plug.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
</application>
:
<paths>
<files-path path="/" name="allfiles" />
</paths
과 핵심 응용 프로그램에서
, I가 시도 내 플러그 응용 프로그램에서 첫 번째, 나는 파일 제공자를 설정 한 test.txt를 읽으십시오 :
Uri uri = Uri.parse("content://com.mdl.test.plug.fileprovider/allfiles/test.txt");
InputStream is = null;
StringBuilder result = new StringBuilder();
try {
is = getApplicationContext().getContentResolver().openInputStream(uri);
BufferedReader r = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = r.readLine()) != null) {
result.append(line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try { if (is != null) is.close(); } catch (IOException e) { }
}
그러나 그것은 권한 오류를 반환 :
Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord
내가 원하는 것은 코어 플러그에서 파일을 읽을 대신 플러그의 코어 파일을 보낼 수 있습니다. 어떤 해결책?
감사
핵심 응용 프로그램은 그Uri
에 대한 권한이 없기 때문입니다
test.txt 파일의 위치를 알려주지 않았습니다. 전체 경로를 알려주십시오. 또한 getUriForFile()을 사용하여 URI를 설정해야합니다. – greenapps