Sultaan
Sultaan

Reputation: 1

Can we switch on GPS/Location in Android using Native code in UNITY , programatically?

Right now the user is being send to setting to switch on GPS manually. I want the location to be enabled inside the app, no manually.

            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
            AndroidJavaObject context = currentActivity.Call<AndroidJavaObject>("getApplicationContext");
            AndroidJavaObject locationManager = context.Call<AndroidJavaObject>("getSystemService", "location");

            if (locationManager != null)
            {
                AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent", "android.settings.LOCATION_SOURCE_SETTINGS");
                currentActivity.Call("startActivity", intent);
            }

Upvotes: 0

Views: 54

Answers (0)

Related Questions