# Conflicts:
#	pages/index/index.nvue
#	unpackage/cache/appleConfig.ini
#	unpackage/cache/uts_custom_ios/app-ios-debug.json
#	unpackage/cache/wgt/__UNI__BAAC5A9/app-service.js
#	unpackage/cache/wgt/__UNI__BAAC5A9/app-view.js
#	unpackage/cache/wgt/__UNI__BAAC5A9/manifest.json
#	unpackage/cache/wgt/__UNI__BAAC5A9/pages/index/index.js
#	unpackage/debug/iOS_debug.ipa
#	unpackage/dist/build/app-plus/app-service.js
#	unpackage/dist/build/app-plus/app-view.js
#	unpackage/dist/build/app-plus/manifest.json
#	unpackage/dist/build/app-plus/pages/index/index.js
#	unpackage/dist/dev/app-plus/app-config-service.js
#	unpackage/dist/dev/app-plus/manifest.json
#	unpackage/dist/dev/app-plus/pages/index/index.js
This commit is contained in:
weipengfei 2024-01-17 10:42:56 +08:00
commit a7c98d28de
23 changed files with 58 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 896 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="io.dcloud.uni_modules.fdm_keepalive">
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>

View File

@ -0,0 +1,3 @@
{
"minSdkVersion": "23"
}

View File

@ -0,0 +1,49 @@
package uts.sdk.modules.fdmKeepalive;
import io.dcloud.uniapp.*;
import io.dcloud.uniapp.extapi.*;
import io.dcloud.uts.*;
import io.dcloud.uts.Map;
import io.dcloud.uts.Set;
import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.Deferred;
import kotlinx.coroutines.Dispatchers;
import kotlinx.coroutines.async;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.provider.Settings;
import io.dcloud.uts.UTSAndroid;
import android.net.Uri;
open class WakeLockHelper {
open var context: Context;
private var wakeLock: PowerManager.WakeLock? = null;
constructor(context: Context){
this.context = context;
}
open fun acquireWakeLock() {
var powerManager = this.context.getSystemService(Context.POWER_SERVICE) as PowerManager;
this.wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyApp::TestWakeLock");
this.wakeLock?.acquire();
}
open fun releaseWakeLock() {
this.wakeLock?.release();
this.wakeLock = null;
}
}
fun addKeepalive() {
val context = UTSAndroid.getAppContext();
val pageName = context!!.getPackageName();
val manager = context!!.getSystemService(Context.POWER_SERVICE) as PowerManager;
if (!manager.isIgnoringBatteryOptimizations(pageName)) {
var jumpUrl: Uri = Uri.parse("package:" + pageName);
var intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, jumpUrl);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
UTSAndroid.getAppContext()!!.startActivity(intent);
}
var wakeCtrl = WakeLockHelper(context);
wakeCtrl.acquireWakeLock();
console.log(manager.isInteractive(), " at uni_modules/fdm-keepalive/utssdk/app-android/index.uts:39");
}
fun addKeepaliveByJs() {
return addKeepalive();
}