Cardboard virtual reality development skills (3) keep mobile phones always bright

Source: Internet
Author: User

Cardboard virtual reality development skills (3) keep mobile phones always bright
Quickly solves the problem of frequent screen brightness on Android and Ios platforms

We all know that we use Google's Cardboard as the basis to develop virtual reality applications. We need to place our mobile phones in CardBoard or in various glasses boxes, such as the storm magic mirror, then wear glasses to use virtual reality applications, enjoy models, watch panoramic videos, and play somatosensory games. No one wants to be disturbed by frequent mobile phone screen-out, therefore, automatic screen disconnection is a problem that must be solved when developing AR and VR applications.

Taking Android as an example, many may use Unity to call Android JAVA (call some Android Jar packages) or package Unity as an Android program, and then apply for permissions from the Android perspective, restrict the black screen of the system, but if the application itself does not need to call Android Java for in-depth development, it will only do so to keep the mobile phone bright, so as to sacrifice portability and ease of testing, I think this is not worth it. Those who have used Unity to call Android will know that, no matter which method is used in combination with Android development, the development and testing process will be very time-consuming, the process of compiling, packaging, and installation is cumbersome and time-consuming. For example, if Unity calls Android JAVA, Android src must be packaged into a jar package during a test and copied to Unity, if the JNI part has been modified, copy it. so Library to the corresponding location, and then build apk, package it, copy it to the mobile phone, and then test and check logcat. A test may take several minutes, And it will consume patience. You can no longer happily test the debugging information in Unity Editer. Therefore, if there is no need to use Unity to call JAVA or C/C ++, the work that can be done in Unity is better.

Fortunately, Unity provides an interface for eliminating the screen-out, which is very simple to use. So let's take a look at how to quickly solve this problem on the Android and IOS platforms.

Solution to the screen-out problem on the Android platform
Screen.sleepTimeout = SleepTimeout.NeverSleep; 

You only need to let this line of C # code be executed in a script in a specific scenario. Here, you need to pay attention to the scenario issues. For example, this line of code has been executed in a game scenario, but it is not executed in the scoring scenario. It is possible that the screen will be turned off in the scoring scenario. Then, VR users will have to pull their cell phones out of their glasses and press the unlock key.

Solution to the screen-out problem on IOS platform
iPhoneSettings.screenCanDarken = false;

I am not an Apple user. I have never tested an Apple mobile phone, so I will not talk about it here. It is written on the official website...

Conclusion

The original intention of writing the virtual reality glasses development skills series is to bring substantial help to everyone, because it is impossible to cover all aspects, so I will pick out some problems that everyone will encounter to describe, it may be a little short, but there is no theme when a bunch of things are together, so it can only be a little shorter. Please forgive me. About CardBoard virtual reality glasses development, I have already written 1-4 articles in the preliminary series of virtual reality development to help you get started, the English API was also moved from the Google official website outside the Great Wall network. I also translated a Chinese version of the document. The above content is in the category and column of my blog, you can read it by yourself. I hope this content will help you ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.