Prepare Lunaris 1.1.2 experimental
This commit is contained in:
@@ -42,3 +42,7 @@ android {
|
||||
flutter {
|
||||
source = "../.."
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("androidx.core:core-ktx:1.13.1")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
|
||||
|
||||
<application
|
||||
android:label="Lunaris"
|
||||
@@ -32,6 +33,15 @@
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
<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>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
https://developer.android.com/training/package-visibility and
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.example.gel_rule_app
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.BatteryManager
|
||||
import android.os.Environment
|
||||
import android.provider.MediaStore
|
||||
import androidx.core.content.FileProvider
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
@@ -18,17 +20,24 @@ class MainActivity : FlutterActivity() {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "rulegel/downloads")
|
||||
.setMethodCallHandler { call, result ->
|
||||
if (call.method != "saveToDownloads") {
|
||||
result.notImplemented()
|
||||
return@setMethodCallHandler
|
||||
}
|
||||
try {
|
||||
val path = call.argument<String>("path") ?: error("Missing path")
|
||||
val fileName = call.argument<String>("fileName") ?: File(path).name
|
||||
val mimeType = call.argument<String>("mimeType") ?: "application/octet-stream"
|
||||
result.success(saveToDownloads(path, fileName, mimeType))
|
||||
when (call.method) {
|
||||
"saveToDownloads" -> {
|
||||
val path = call.argument<String>("path") ?: error("Missing path")
|
||||
val fileName = call.argument<String>("fileName") ?: File(path).name
|
||||
val mimeType = call.argument<String>("mimeType") ?: "application/octet-stream"
|
||||
result.success(saveToDownloads(path, fileName, mimeType))
|
||||
}
|
||||
"openFile" -> {
|
||||
val path = call.argument<String>("path") ?: error("Missing path")
|
||||
val mimeType = call.argument<String>("mimeType") ?: "application/octet-stream"
|
||||
openFile(path, mimeType)
|
||||
result.success(null)
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
} catch (error: Throwable) {
|
||||
result.error("save_failed", error.message, null)
|
||||
result.error("download_failed", error.message, null)
|
||||
}
|
||||
}
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "rulegel/device")
|
||||
@@ -89,6 +98,21 @@ class MainActivity : FlutterActivity() {
|
||||
return if (level in 0..100) level else null
|
||||
}
|
||||
|
||||
private fun openFile(path: String, mimeType: String) {
|
||||
val file = File(path)
|
||||
val uri = FileProvider.getUriForFile(
|
||||
this,
|
||||
"${applicationContext.packageName}.fileprovider",
|
||||
file
|
||||
)
|
||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||
setDataAndType(uri, mimeType)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
startActivity(Intent.createChooser(intent, "Open update"))
|
||||
}
|
||||
|
||||
private fun supportedRefreshRates(): List<Double> {
|
||||
val display = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) display else windowManager.defaultDisplay
|
||||
return display?.supportedModes
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<cache-path name="cache" path="." />
|
||||
<external-cache-path name="external_cache" path="." />
|
||||
<files-path name="files" path="." />
|
||||
</paths>
|
||||
Reference in New Issue
Block a user