Screen.SleepTimeout stopped working
Hi there,
I made an app and the following class used to prevent android devices from sleeping. Un luckily it is no longer working and I never changed anything about sleeptimeout since it was ok.
The only things I added without knowing the content line by line are some asset store assets. I tried to search in the whole project for other Screen.SleepTimeot calls with no luck.
What's wrong? What can prevent this code from working?
Note: if I attach the same code to a camera in a dummy project the sreen stays on perfectly
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Disablesleep : MonoBehaviour {
// Use this for initialization
void Start () {
Screen.sleepTimeout = SleepTimeout.NeverSleep;
Debug.Log("Sleep Disabled");
}
private void Awake()
{
}
// Update is called once per frame
void Update () {
}
}
Still waiting for the Right answer. What can prevent Screen.SleepTimeout from working?
$$anonymous$$ost likely because internal android force screen to sleep to save battery.
I already post another script to call internal java method on android to prevent sleep. Why dont you try that
Answer by Corby-Interactive · Aug 08, 2018 at 09:31 PM
Nothing Yet?
Wrong answer mate, in my case something is preventing Screen.SleepTimeout from working but on the same device (changing the app) it works fine. I need to know what can stop Screen.SleepTimeout fro working.
if(GUI.Button(new Rect(20,70,80,20), "Call Android $$anonymous$$ethod")) {
using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
using (AndroidJavaObject obj_Activity = cls_UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity")) {
AndroidJavaClass cls_$$anonymous$$ainActivity = new AndroidJavaClass("android.view.View");
cls_$$anonymous$$ainActivity.CallStatic("set$$anonymous$$eepScreenOn", true);
}
Untested.
Your answer
Follow this Question
Related Questions
Is it normal that an Asset needs to have provider section in AndrodManifest.xml ? 0 Answers
Unable to merge android manifests 1 Answer
Android re-package error - CommandInvokationFailure 0 Answers
App Requiring Multiple External_Storage Permissions? 1 Answer
Unable to convert classes into dex format 12 Answers