Unity version: 2022.3.30f1
Windows version: 10 64 Bit Pro
Watch: TicWatch Pro 3
Hello,
I’m desperately trying to solve this issue:
After like 30 seconds (when the display is off) my app is not in foreground anymore.
I always need to re-open it again.
From what I understand I have to copy the AndroidManifest into assets\Plugins\Android
and add the line:
I tried multiple varations, but it either:
- could not get compiled
- crashed immediately after starting on the watch
- app went into background after 30 seconds.
I know it is possible to keep the display on, but this should be that last option since it’s not that good for the battery.
Here is one of the things I tried:
C:\Unity Projects\Wear-Project\Assets\Plugins\Android\src\main\java\com\example\weartest\MainActivity.java
package com.example.weartest;
import android.app.Activity;
import android.os.Bundle;
import android.os.PowerManager;
import android.content.Context;
public class MainActivity extends Activity {
private PowerManager.WakeLock wakeLock;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "weartest::MyWakelockTag");
}
@Override
protected void onResume() {
super.onResume();
if (wakeLock != null && !wakeLock.isHeld()) {
wakeLock.acquire();
}
}
@Override
protected void onPause() {
super.onPause();
if (wakeLock != null && wakeLock.isHeld()) {
wakeLock.release();
}
}
}
My AndroidManifest.xml, which is placed under C:\Unity Projects\Wear-Project\Assets\Plugins\Android:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="6"
android:versionName="1.5"
package="com.example.weartest"
platformBuildVersionCode="22"
platformBuildVersionName="5.1.1-1819727">
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="22" />
<uses-feature
android:name="android.hardware.type.watch" />
<uses-permission
android:name="android.permission.VIBRATE" />
<uses-permission
android:name="android.permission.WAKE_LOCK" />
<application
android:theme="@ref/0x01030128"
android:allowBackup="true">
<uses-library
android:name="com.google.android.wearable"
android:required="false" />
<activity
android:label="@ref/0x7f070021"
android:name="com.example.weartest.MainActivity">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="android.support.wearable.activity.ConfirmationActivity" />
</application>
</manifest>
Maybe there is an easier way to implement that function?
Am I on the right way anyway?
Thanks for the help!
Best regards