How do I find out if the GPS of an Android device is enabled

后端 未结 10 1831
暖寄归人
暖寄归人 2020-11-22 08:36

On an Android Cupcake (1.5) enabled device, how do I check and activate the GPS?

10条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 09:18

    This method will use the LocationManager service.

    Source Link

    //Check GPS Status true/false
    public static boolean checkGPSStatus(Context context){
        LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE );
        boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        return statusOfGPS;
    };
    

提交回复
热议问题