0
There’s some specific code to enable the GPS, but I haven’t found it yet.
What I saw online was:
however, this code is in JAVA.
Whatever he could ride in Delphi was:
var
poke : JIntent;
begin
poke.setClassName(StringToJString('com.android.settings'),StringToJString('com.android.settings.widget.SettingsAppWidgetProvider'));
poke.addCategory(StringToJString('android.intent.category.ALTERNATIVE'));
poke.setData(TJnet_Uri.JavaClass.parse(StringToJString('3')));
SharedActivity.sendBroadcast(poke);
end;
Second code I got to activate is:
TJSettings_Secure.JavaClass.putString(SharedActivityContext.getContentResolver,
TJSettings_Secure.JavaClass.LOCATION_PROVIDERS_ALLOWED,
TJLocationManager.JavaClass.GPS_PROVIDER);
Third was:
TJSettings_Secure.JavaClass.setLocationProviderEnabled(
SharedActivityContext.getContentResolver,
TJLocationManager.JavaClass.GPS_PROVIDER,
true);
The fourth was:
Intent := TJIntent.JavaClass.init(TJLocationManager.JavaClass.GPS_PROVIDER);
intent.putExtra(StringToJString('enabled'), true);
SharedActivity.sendBroadcast(intent);
All of them apparently require permission to enable and deal directly with the android Settings.
The error I got was (in all):
java.lang.SecurityException: Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS
In my options, permissions are normally enabled:
Not to mention I also tried to put the permissions directly in the Android Manifest.
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
Does anyone have any tips for me?
Ramon, you wouldn’t have to wear one
JString
within thesetClassName
?– Wakim
Wakim, follow the full post. Please take a look :D
– Ramon Ruan
Ramon, this permission is only for system apps or firmware, you’ll have to see another way. I never used Delphi to develop for Android, I’ll try to search something to see if it helps.
– Wakim
No way to change the firmware via code? according to my research, it was to have worked from the moment I set true in WRITE_SECURE_SETTINGS.
– Ramon Ruan
No no, this code even works, but only apps that belong to the system or are firmware apps (made by device manufacturers) can have this
permission
(WRITE_SECURE_SETTINGS
). I have an app that enables and disables theGPS
, so there must be some other way.– Wakim
But your app is in Delphi or Java?
– Ramon Ruan
Having an app is to have downloaded on Google Play. The app is the
Extended Settings
. It enables and disables gps. So you should have an alternative.– Wakim
Surely there must be, I must be asking is the wrong question.
– Ramon Ruan
Wait a little longer, someone must know how to do this.
– Wakim
therefore I searched, there is no solution to activate/deactivate GPS programmatically, it is a security flaw (https://code.google.com/p/android/issues/detail?id=35924) that was corrected in version 4.4 only, but there is a code that can work (I am not sure) with API smaller than 4.4. The app I told you about (
Settings Extended
) redirects me to the configuration ofLocation
in the device settings. I made this Gist for the two examples: https://gist.github.com/wakim/3cf3c31ed39048bd7b50. They are in Java, but you can try to convert to Delphi.– Wakim
Anyone else has any tips to give?
– Ramon Ruan