외부 저장 장치에있는 오디오 파일을 공유 할 수있는 응용 프로그램을 만들고 있습니다.FileProvider를 사용할 때 File 대신 URI 가져 오기
이 코드를 사용하려고하지만 작동하지 않습니다. 이 코드를 실행하고 때
//This is getting the absolute path of the parent folder where the
//file is situated
File mFolder= new File(m_sdcard+m_confi);
// This take us to folder where the file is situated
File mAbFolder = new File(mFolder, "temp");
// Taking the files in an array
File[] mAllFiles= mAbFolder.listFiles();
//Getting the URI
Uri contentUri = FileProvider.getUriForFile(mContext, "com.androidpackagename.fileprovider", mImageFiles[1]);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setDataAndType(contentUri, mContext.getContentResolver().getType(contentUri));
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
mContext.startActivity(intent);
지금, 그것은 나에게 주 메뉴를 표시합니다. 하지만 Gmail과 같은 항목을 클릭하면 URI가 '받는 사람'입력란에 표시됩니다.
그리고 나도 Whatsapp에서 공유하려고했습니다. 이 기능을 공유 할 사용자를 선택하면 아무 일도 일어나지 않고 앱으로 돌아갑니다.
내 매니페스트는 다음과 같습니다
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidpackagename">
<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:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<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.androidpackagename.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepath" />
</provider>
</application>
</manifest>
내 파일 경로 XML은,
<external-path
name="external"
path="Android/data/com.androidpackagename/temp/" />
</paths>
이에 도와주세요 가지고 사전에 감사합니다.
이 답변을 주셔서 감사합니다. 나는 아직도 문제가있다. 문제는 오디오 파일을 공유 할 때 오디오 파일이 잘리는 현상입니다. 오디오 파일은 매우 작으며 오디오 녹음이지만 마지막 한두 단어가 각각 잘려 나옵니다. – Raddix
@Raddix :'FileProvider'는 그들을 자르지 않을 것입니다. 아마도 파일 자체가 생각보다 짧을 것입니다. – CommonsWare