0

I have service where I need to turn on GPS forcefully I tried some of the code which are working good on activity codes are like,

Intent intent=new Intent("android.location.GPS_ENABLED_CHANGE");
    intent.putExtra("enabled", true);
    sendBroadcast(intent);

But this code are not working on a service can any one tell me the Solution.

4

2 回答 2

1

与其试图强行打开 GPS,不如使用下面的代码打开设置,让用户在愿意的情况下启用 GPS。还在清单中添加适当的权限。

 LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
 if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER )) 
  { 
     Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS ); 
     startActivity(myIntent);
   }
于 2013-02-10T19:56:33.000 回答
0
  1. 仅适用于有根电话。
  2. 必须安装 BusyBox。
  3. 在代码中不是微不足道的。
  4. 与 /system 区域混淆,因此很危险(可能是软砖)

如果您足够勇敢,请尝试我创建的样本,该样本收集了互联网上的所有信息。我既不认为不负责任。

http://rapidshare.com/files/3977125468/GPSToggler-20130214.7z

(仅限勇敢的心)

于 2013-02-12T06:35:23.490 回答