Skip to content

Commit

Permalink
Wakelock
Browse files Browse the repository at this point in the history
  • Loading branch information
The Judge committed Sep 15, 2024
1 parent 1a930a7 commit 863e0dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pojlib.android">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application android:allowNativeHeapPointerTagging="false"/>
</manifest>
8 changes: 8 additions & 0 deletions src/main/java/pojlib/UnityPlayerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.PowerManager;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Window;
Expand All @@ -22,6 +23,7 @@
public class UnityPlayerActivity extends ActivityGroup implements IUnityPlayerLifecycleEvents
{
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code
private PowerManager.WakeLock wakeLock;

// Override this in your custom UnityPlayerActivity to tweak the command line arguments passed to the Unity Android Player
// The command line arguments are passed as a string, separated by spaces
Expand Down Expand Up @@ -49,6 +51,11 @@ protected String updateUnityCommandLineArguments(String cmdLine)
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);

PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"QCXR::DownloadFailPrevention");
wakeLock.acquire();

String cmdLine = updateUnityCommandLineArguments(getIntent().getStringExtra("unity"));
getIntent().putExtra("unity", cmdLine);

Expand Down Expand Up @@ -111,6 +118,7 @@ public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
@Override protected void onDestroy ()
{
mUnityPlayer.destroy();
wakeLock.release();
super.onDestroy();
}

Expand Down

0 comments on commit 863e0dc

Please sign in to comment.