How to access android system settings with Unity

Minapps

Member
Joined
Aug 13, 2019
Messages
7
Programming Experience
Beginner
I'm making an app and need to be able to check if settings like : Bluetooth/Phone Rotation/Flashlight/Plane Mode/GPS/Phone Brightness/Silent Mode, are activated on an android phone.

I haven't found any way to do it within Unity, using C#. I found ways to do it using Xamarin but none of them work with Unity (or maybe I haven't done it right), the only way I found is using Java and making it into a plugin and call it in a C# script. But I can't find a clear way to make this work. If this is the only solution could you please explain how to do it, all the documentation I find is from old versions from 2014.

I think there is a simple solution for this but I simply can't find it. And the manifest part is not a problem, I'll add the permissions needed.
 
I've just searched up everything you are looking for and I have found About 204,000 results for flashlight, About 1,240,000 results for phone rotation, About 4,530,000 results for Bluetooth, About 4,580,000 results for GPS, About 806,000 results for phone brightness, About 1,020,000 results for airplane mode, and About 765,000 results for silent mode.

And I haven't even began looking up the original classes for these features yet which would clearly explain how to do this, and you're telling us you can't find anything? You clearly aren't looking very hard.
 
Wow! You're a genius! I think I may not be looking with the right key words ? Could you tell me the key words you used ? For example I used "c# android flashlight" and sure I ended up with 143,000 results but they "all" (most of them) talk about Xamarin or java or Android Studio or how to turn on and off the flashlight.
I've been looking for 2 days and didn't find any thing that's why I came here, not because I'm lazy and not bothered to look for solutions in documents and learn how to do it myself.
I'm new to programming so maybe like you said, the solution is right in front of my eyes, but written in a different/better way.
So yeah looks like I'm going to have to look some more.
 
It doesn't take a genius to use google, bing or yahoo, it only takes someone with some common sense. Well Jes; lets think about this. Most of the adapters you would need to access will have the ability to turn on and off a feature, so if someone is explaining on one of your results how to do that, do you not think it is prudent to check for the current state of the adapters properties too?

You can access the adapter for bluetooth BluetoothAdapter btoothAdapt = BluetoothAdapter.getDefaultAdapter();
For some of the functionality you will need admin permissions. And you can check .isEnabled() to get its current state. You can inherit the admin permissions through "android.permission.BLUETOOTH_ADMIN"

All of what you need is available in the docs : https://developer.android.com/reference/android/bluetooth/BluetoothAdapter - If you're making an app, why are you not making it cross platform by using Xamarin : Cross-Platform Guidance - Xamarin
 
Oh ok I didnt know you could do that in C#! Thank you! Meanwhile I've found that I can make plugins/modules (I don't know which is the right term) for Unity. So I made one with Android Studio and it works, I found that much easier! Nevertheless thank you for your help.
 
You're very welcome.

Btw, I'd really advise Xamarin, as you will likely run into a few problems later on with the newer Samsung devices who are using all the latest modern API's, so ensure you use the latest API's available or your application may not be compatible with the later devices. If your application becomes successful, you will later regret passing up the opportunity to use a multi-platform system.

Of course, you can always come back and ask the forums if you are unsure of something.
 
Ok thank you, I'll do that when I'll have better programming skills, for now I'm just programming for fun and discover what you can do and how you can do things. Thanks
 

Latest posts

Back
Top Bottom