fix: add FileProvider for share, fix DataViewModel share intent
Build APK / build (push) Failing after 4s
Build APK / build (push) Failing after 4s
This commit is contained in:
@@ -62,6 +62,17 @@
|
||||
android:name="com.google.android.geo.API_KEY"
|
||||
android:value="YOUR_API_KEY_HERE" />
|
||||
|
||||
|
||||
<!-- FileProvider for sharing exported files -->
|
||||
<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>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -8,6 +8,9 @@ import androidx.lifecycle.viewModelScope
|
||||
import com.senstools.domain.repository.DataRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.core.content.FileProvider
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
|
||||
@@ -62,7 +65,8 @@ class DataViewModel(application: Application) : AndroidViewModel(application) {
|
||||
success to csvPath
|
||||
}
|
||||
_exportResult.value = if (result.first) {
|
||||
"CSV exported to: " + result.second
|
||||
shareFile(result.second)
|
||||
"CSV exported"
|
||||
} else {
|
||||
"CSV export failed"
|
||||
}
|
||||
@@ -84,7 +88,8 @@ class DataViewModel(application: Application) : AndroidViewModel(application) {
|
||||
success to jsonPath
|
||||
}
|
||||
_exportResult.value = if (result.first) {
|
||||
"JSON exported to: " + result.second
|
||||
shareFile(result.second)
|
||||
"JSON exported"
|
||||
} else {
|
||||
"JSON export failed"
|
||||
}
|
||||
@@ -110,6 +115,24 @@ class DataViewModel(application: Application) : AndroidViewModel(application) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun shareFile(filePath: String) {
|
||||
try {
|
||||
val app = getApplication<Application>()
|
||||
val file = File(filePath)
|
||||
if (!file.exists()) return
|
||||
val uri = FileProvider.getUriForFile(app, app.packageName + ".fileprovider", file)
|
||||
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||
type = if (filePath.endsWith(".csv")) "text/csv" else "application/json"
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}
|
||||
app.startActivity(Intent.createChooser(intent, "Share data"))
|
||||
} catch (e: Exception) {
|
||||
_exportResult.value = "Share failed: " + e.message
|
||||
}
|
||||
}
|
||||
|
||||
fun clearExportResult() {
|
||||
_exportResult.value = null
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths>
|
||||
<cache-path name="exports" path="exports/" />
|
||||
</paths>
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
Reference in New Issue
Block a user