Hig*_*Pha 8 android location google-api android-pendingintent location-client
我已经开始使用本教程实现Google Location API .
我已经设法让它在我的应用程序中工作得很好,它以正确的间隔更新我的位置等.现在我正在研究如何在设备处于睡眠模式时更新我的位置.根据文档,这种方法是要走的路:
public void requestLocationUpdates (LocationRequest request, PendingIntent callbackIntent);
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何设置此PendingIntent,以及如何处理它?我已经看过如何处理其他类型意图的教程,但我不知道如何将它们应用于此.
您可以通过挂起的意图注册广播接收器或活动。注册广播接收器的示例示例:
String proximitys = "ACTION";
IntentFilter filter = new IntentFilter(proximitys);
registerReceiver(mybroadcast, filter);
Intent intent = new Intent(proximitys);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
locationManager.requestLocationUpdates(provider, mintime, mindistance,
proximityIntent);
Run Code Online (Sandbox Code Playgroud)
您的广播接收器:
public class ProximityIntentReceiver extends BroadcastReceiver {
@SuppressWarnings("deprecation")
@Override
public void onReceive(Context arg0, Intent intent) {
//action to be performed
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6669 次 |
最近记录: |