enabling GPS programmatically not working

后端 未结 4 1180
生来不讨喜
生来不讨喜 2021-01-28 15:31

I am trying to enable/disable (toggle) GPS programmatically in my app via a button click, but it is not working. Please help. My target devices are not rooted.

Here\'s t

4条回答
  •  不要未来只要你来
    2021-01-28 16:04

    // location manager
    

    LocationManager locationManager; LocationListener locationListener;

    obj_tgl_gps.setOnClickListener(new OnClickListener() {

            public void onClick(View v)
            {
                if (obj_tgl_gps.isChecked())
                {
                    Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
                    intent.putExtra("enabled", true);
                    sendBroadcast(intent);
                }
                else
                {
                    Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
                    intent.putExtra("enabled", false);
                    sendBroadcast(intent);
                }
    
            }
        });
    

提交回复
热议问题