问题描述
我正在开发一个与地理围栏相关的android应用程序,我尝试在进入geofence时使用broadcast Receiver来获取通知,并且仅在应用程序运行时才能工作,然后尝试通过Service来获取通知,但现在没有通知了进入地理围栏时。
这是代码
**
package com.example.fypautosilenceapp;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.Nullable;
import com.google.android.gms.location.Geofence;
import com.google.android.gms.location.GeofencingEvent;
import java.util.List;
public class GeofenceService extends Service {
private static final String TAG = "GeofencebroadcastRecive";
AudioManager audioManager;
@Nullable
@Override
public IBinder onBind(Intent intent) {
NotificationHelper notificationHelper=new NotificationHelper(getApplicationContext());
GeofencingEvent geofencingEvent=GeofencingEvent.fromIntent(intent);
if(geofencingEvent.hasError()){
Toast.makeText(getApplicationContext(),"Geofence has error",Toast.LENGTH_SHORT).show();
Log.d(TAG,"OnRecive:Error recive geofence event...");
}
List<Geofence> geofenceslist=geofencingEvent.getTriggeringGeofences();
//Location geofencelocation=geofencingEvent.getTriggeringLocation();
for (Geofence geofence:geofenceslist){
Log.d(TAG,"OnRecive:"+geofence.getRequestId());
}
int transtiontype=geofencingEvent.getGeofenceTransition();
switch (transtiontype){
case Geofence.GEOFENCE_TRANSITION_ENTER:
// Toast.makeText(getApplicationContext(),"Enter geofence",Toast.LENGTH_SHORT).show();
notificationHelper.sendHighPriorityNotification("Enter geofence","",MapsActivity.class);
// audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
break;
case Geofence.GEOFENCE_TRANSITION_EXIT:
// Toast.makeText(getApplicationContext(),"Exit geofence",Toast.LENGTH_SHORT).show();
notificationHelper.sendHighPriorityNotification("Exit geofence",MapsActivity.class);
// audioManager.setRingerMode(AudioManager.RINGER_MODE_norMAL);
break;
case Geofence.GEOFENCE_TRANSITION_DWELL:
// Toast.makeText(getApplicationContext(),"Enter Dwell",Toast.LENGTH_SHORT).show();
notificationHelper.sendHighPriorityNotification("Enter Dewell",MapsActivity.class);
// audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
break;
}
return null;
}
}
**
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)