Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to warm up Android device to 40 degrees via Unity?

I wish to create an Android app that will act as a "hand warmer". I am using GPS calls, vibration, flashlight and I am also using multiple threads to run code in a loop. Battery consumption is high but it is not enough.

When I use this app it takes about 10 minutes in order to go from 25 degrees to 33. My goal is to reach 40 degrees in the shortest time possible.

So, how can I read the device temp via C# code, and how to reach 40 degrees of heat and stay there?

like image 758
Tal Angel Avatar asked Mar 11 '17 12:03

Tal Angel


People also ask

How do I enable USB debugging in Unity?

Go to Settings > Developer options, then enable USB debugging. After you have navigated to the build number using the instructions above, tap on the build number seven times.

Can you run Unity games on Android?

To use Unity to create a game experience for players on Android, follow these steps: Download and install the Unity Hub. Start the Unity Hub. On the Installs tab, add a version of the Unity Editor that supports 64-bit apps.


1 Answers

You don't need the flashlight or vibrator to do this as the app will be annoying to most people since these two would be switched on even when not needed.

Use techniques that shouldn't affect the user physically but is capable of generating heat.

how can I read the device temp via C# code

You first need to check if the device has a thermometer sensor before you should read the sensor. As for reading sensor from Android with C#, you have to write that with Java code then call that function from C#.

You can use the already made Unity-Android-Sensor-Plugin plugin for this.

private AndroidJavaObject plugin;

void Start ()
{
#if UNITY_ANDROID
    plugin = new AndroidJavaClass("jp.kshoji.unity.sensor.UnitySensorPlugin").CallStatic<AndroidJavaObject>("getInstance");

    //Init the ambienttemperature sensor
    if (plugin != null) 
    {
        plugin.Call("startSensorListening", "ambienttemperature");
    }
#endif
}

To read the ambient temperature sensors later on in the Update function:

float[] sensorValue = plugin.Call<float[]>("getSensorValues", "ambienttemperature");

Battery consumption is high but it is not enough.

These are techniques to use to heat up your mobile device.

Brightness:

1.Change the brightness to the highest value. Now, disable auto dim so that the screen led is always shining.

Networking:

2.Create multiple(4 to 5) TCP server with with each one running in their own Threads and also with different ports on the device.

Now, create the-same amount of TCP client and connect to the server with the ports and IPAddress.Loopback as the IP.

In a while loop, randomly generate about 13k float numbers, convert it to byte array then send it to each client and server continuously. When you receive it convert that byte array back to float then do absolutely nothing with the result. Repeat and rinse.

Audio:

3.Load 5 or 6 audio files to audio file, set the it to loop then set the volume to 0. Play all the audio.

Video:

4.Load 5 or 6 animations, set it to loop then play it. It may not be visible on the screen but as long as it is playing, it do fine.

Video:

5.Load 3 videos with Unity's new VidepPlayer, disable audio, connect the video to RawImage. Set the alpha of other RawImage to 0 so that it is not visible. Play video and let decoding do the job.

Senors:

6.Enable accelerometer and gyro sensors poll it every frame in the Update function.

7.Enable GPS and read poll it every frame in the Update function.

8.Enable Bluetooth and do a continuous search for other devices every second.

9.Enable the front and back camera, pull Textures from them but do nothing with it.


how to reach 40 degrees of heat and stay there?

Putting it together:

Put everything described above in a function or its own class.

1.Write a simple class with an int variable called level. This level variable should be used to determine which actions described above should be running.

2.When app is started, change the level to 9 then enable/start each technique described above. If the temperature reaches around 38, decrease the level to about 5. When the level is decreased, you stop running running anything under, so in this case,you should stop polling accelerometer, gyro, GPS ,Bluetooth and cameras then disable them.

3.If the temperature is above 40, decrease the level. If it is below 40, increase the level. This is how you keep the temperature around ~40 degrees.

4.Even better, you may have to make your own PID controller that uses those techniques above for this. It will take time to get it right but this is possibly the best way to go about this.

TIP:

For each stuff you do, check the frame rate. If the frame-rate is below 6, stop. If you don't, Android may kill the app for not being responsive.


NOTE:

Write a simple function that detects some certain devices mentioned in the comment section. Make sure that this app does not run on these app or your "hand warmer" app could become a "hand warmer && amputator" app.

like image 156
Programmer Avatar answered Oct 19 '22 23:10

Programmer