현재 블루투스 스캔을하고 있습니다. 즉, 기기를 계속 스캔 할 예정이며 주변에 기기가있는 경우 화면에 표시합니다. 앱이 백그라운드에있는 경우 사용자에게 알림을 표시해야합니다. .앱이 백그라운드에서 Android에있는 경우 알림을 보내려면 어떻게해야하나요?
그리고 내 작업 논리는 다음과 같습니다. 검사 서비스를 시작하는 기본 클래스가 있습니다. 검사 서비스 작업은 검사 된 장치 목록을 반환하는 것입니다. 그리고 주 수업 직업은 결과를 표시/처리하는 것입니다. 내가 알림을 추가해야하는 경우
public class Detector extends Service implements IBeaconConsumer {
protected static final String TAG = "RangingActivity";
private IBeaconManager iBeaconManager;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
iBeaconManager = IBeaconManager.getInstanceForApplication(this);
iBeaconManager.bind(this);
Log.d("test1","bind");
return super.onStartCommand(intent, flags, startId);
}
}
홈페이지
private class DataUpdateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("scanResult")) {
ArrayList<IBeacon> beacons = (ArrayList<IBeacon>) intent.getSerializableExtra("beacons");
for(IBeacon be : beacons){
if (be.getProximityUuid().equals("ebefd083-70a2-47c8-9837-e7b5634df524")) {
if (be.getMajor() == 2) {
a_rssi = be.getRssi();
} else if (be.getMajor() == 1) {
b_rssi = be.getRssi();
}
}
}
if(a_rssi > b_rssi) {
Log.d("test1","at shop");
//at shop,need case handling if more than 1 shop beacon
showAd(R.drawable.offer1);
if (timer != null)
timer.cancel();
timer = null;
timeCount = 0;
Intent msg = new Intent("timerUpdate");
msg.putExtra("timeCount", timeCount);
sendBroadcast(msg);
} else {
Log.d("test1","at park");
//at car park
if (timer == null) {
timer = new Timer(true);
timer.schedule(new MyTimer(), 1000, 1000);
}
}
}
}
}
문제는, 내가 이동해야 않습니다되어
서비스 :
코드는 다음과 같다 프로세스 파트 코드 (주 클래스에 있음)가 서비스를 제공합니까? 그것을 어떻게 성취 할 수 있습니까? 감사합니다.