在我写这篇code接收位置更新 -
PendingIntent launchIntent = PendingIntent.getBroadcast(背景下,5000,意图,0);
manager.requestLocationUpdates(selectProvider(),0,0,launchIntent);
我选择GPS供应商,如果其可用,否则网络供应商。有没有一种方法,我可以切换回的GPS一个,如果它被后来启用?
系统是否播出的意图时,GPS提供商启用或禁用?莫非我建立了一个侦听一样的吗?
解决方案 公共无效onStatusChanged(字符串商,INT地位,捆绑演员){
// TODO自动生成方法存根
}
公共无效onProviderEnabled(字符串提供商){
Toast.makeText(这一点,已启用新的供应商+供应商,
Toast.LENGTH_LONG).show();
}
公共无效onProviderDisabled(字符串提供商){
Toast.makeText(这一点,GPS断开,Toast.LENGTH_LONG);
Toast.makeText(getApplicationContext(),保持通话,
Toast.LENGTH_LONG);
Toast.makeText(这一点,请接通GPS。+供应商,
Toast.LENGTH_LONG).show();
}
I write this code to receive location updates -
PendingIntent launchIntent = PendingIntent.getBroadcast(context, 5000, intent, 0);
manager.requestLocationUpdates(selectProvider(), 0, 0, launchIntent);
I select the gps provider if its available, otherwise the network provider. Is there a way I could switch back to the gps one if it gets enabled later?
Does the system broadcast an intent when gps provider is enabled or disabled? Could I set up a listener for the same?
解决方案public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
Toast.makeText(this, "Enabled new provider " + provider,
Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String provider) {
Toast.makeText(this, "GPS disconnected", Toast.LENGTH_LONG);
Toast.makeText(getApplicationContext(), "Connected",
Toast.LENGTH_LONG);
Toast.makeText(this, "Please Switch on GPS." + provider,
Toast.LENGTH_LONG).show();
}