Java Android中的地理围栏服务

Java Android中的地理围栏服务,java,android,geofencing,android-geofence,geofence,Java,Android,Geofencing,Android Geofence,Geofence,我正在开发一个与geofence相关的android应用程序,我尝试在进入geofence时使用广播接收器获取通知,我将仅在应用程序运行时工作,然后我尝试使用服务获取通知,但现在进入geofence时没有通知 这是密码 ** package com.example.fypautosilenceapp; 导入android.app.Service; 导入android.content.Context; 导入android.content.Intent; 导入android.media.AudioM

我正在开发一个与geofence相关的android应用程序,我尝试在进入geofence时使用广播接收器获取通知,我将仅在应用程序运行时工作,然后我尝试使用服务获取通知,但现在进入geofence时没有通知

这是密码

**

package com.example.fypautosilenceapp;
导入android.app.Service;
导入android.content.Context;
导入android.content.Intent;
导入android.media.AudioManager;
导入android.os.IBinder;
导入android.util.Log;
导入android.widget.Toast;
导入androidx.annotation.Nullable;
导入com.google.android.gms.location.geofense;
导入com.google.android.gms.location.GeofencingEvent;
导入java.util.List;
公共类GeofenceService扩展了服务{
私有静态最终字符串TAG=“GeofenceBroadcastRecive”;
AudioManager AudioManager;
@可空
@凌驾
公共IBinder onBind(意向){
NotificationHelper NotificationHelper=新的NotificationHelper(getApplicationContext());
GeofencingEvent GeofencingEvent=GeofencingEvent.fromIntent(intent);
if(geofencingEvent.hasError()){
Toast.makeText(getApplicationContext(),“地理围栏有错误”,Toast.LENGTH_SHORT.show();
Log.d(标记“OnRecive:Error recive geofrance event…”);
}
List geofenceslist=geofencingEvent.getTriggeringGeofences();
//Location geofencelocation=geofencingEvent.getTriggeringLocation();
用于(土工围栏土工围栏:土工围栏列表){
Log.d(标记“OnRecive:+geofinence.getRequestId());
}
int transionType=geofencingEvent.getGeofenceTransition();
开关(转换型){
案例Geopfence.Geopfence\u过渡\u输入:
//Toast.makeText(getApplicationContext(),“输入地理围栏”,Toast.LENGTH\u SHORT.show();
notificationHelper.sendHighPriorityNotification(“输入地理围栏”,“MapsActivity.class”);
//audioManager.setRingerMode(audioManager.RINGER\u模式\u静音);
打破
案例Geofence.Geofence_过渡_出口:
//Toast.makeText(getApplicationContext(),“退出地理围栏”,Toast.LENGTH\u SHORT.show();
notificationHelper.sendHighPriorityNotification(“退出地理围栏”,MapsActivity.class);
//audioManager.setRingerMode(audioManager.RINGER\u模式\u正常);
打破
案例Geofence.Geofence_过渡_驻留:
//Toast.makeText(getApplicationContext(),“Enter Dwell”,Toast.LENGTH_SHORT.show();
notificationHelper.sendHighPriorityNotification(“输入Dewell”、“MapsActivity.class”);
//audioManager.setRingerMode(audioManager.RINGER\u模式\u静音);
打破
}
返回null;
}
}

**

我已经检查了这个,但我不明白该如何连接服务和广播接收器
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;
    }
}