I have tried to implement the file provider approach and the detail for the same are given below:
xml file created for providing path
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="logs" path="logs/" />
</paths>
File provider added in manifest file
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
Code for sharing the file
var directory = File(requireActivity().getFilesDir(), "logs")
var logFile = File(directory, "InformerLog.txt")
if(logFile.exists()) {
val fileUri = FileProvider.getUriForFile(
requireContext(),
requireActivity().packageName + ".fileprovider",
logFile
)
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.setType("text/plain")
shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri)
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
requireActivity().startActivity(Intent.createChooser(shareIntent, "Share log file"))
When I share the file to google drive via this approach then it just showed a notification that unable to schedule one file for upload. Tried other apps as well to share but none works.