Permisssion denied while attaching apk file with GMail app android

后端 未结 1 592
青春惊慌失措
青春惊慌失措 2020-12-22 13:04

I have a requirement to send a apk file through share Intent and I have also implemented without any hassle. But the problem arises only while sending apk via GMail, I am ge

相关标签:
1条回答
  • 2020-12-22 13:10

    When sharing files between applications, you should use a FileProvider as per the setting up file sharing training as this ensures that the receiving app can read the file without requiring any permissions. As of Android 6.0, Gmail does not request the storage permission, meaning it is unable to read any files you provide with Uri.fromFile().

    You'd declare a FileProvider in your manifest:

    <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.example.myapp.fileprovider"
            android:grantUriPermissions="true"
            android:exported="false">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
    </provider>
    

    An XML file (in this case called filepaths.xml to match the above manifest declaration) which determines which directories are available via the FileProvider:

    <paths>
        <files-path path="images/" name="myimages" />
    </paths>
    

    Then, in place of using Uri.fromFile(file), you use FileProvider.getUriForFile(), passing in the same authority as in your manifest.

    0 讨论(0)
提交回复
热议问题