Android device GPS on/off programmatically

后端 未结 5 1147
深忆病人
深忆病人 2020-11-27 07:40

I am using following code for GPS on/off.

//Enable GPS
Intent intent = new Intent(\"android.location.GPS_ENABLED_CHANGE\");
intent.putExtra(\"enabled\", true         


        
5条回答
  •  野性不改
    2020-11-27 08:15

    From my personal experience, I am answering this,

    • The hack code you shown in the your question has been stopped working from Android version 4.4. Your will fire this Exception starting from Kitkat version java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.location.GPS_ENABLED_CHANGE

    • The First answer's code will not work any more, it only display animated GPS icon in notification bar.

    • For The security purpose Google developer has block above both methods which were previously working fine.

    • Hence conclusion is that You can not programmatically start GPS On or Off.

提交回复
热议问题