ibeacon の検出にaltbeacon lib を使用しています。サービスを開始してアクティビティからibeaconを検出すると、ibeaconの検出は完全に問題ありません。
バックグラウンドで同じ操作を開始したい(STICKYサービス)。このドキュメントに従いました。ibeacons を検出していますが、問題は時間にあります。検出に時間がかかりすぎています。以下のように検出するための期間を保持しました。
public class Ibeaconpocsuper extends Application implements BootstrapNotifier {
private RegionBootstrap regionBootstrap;
@Override
public void onCreate() {
super.onCreate();
init();
}
private void init() {
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.setBackgroundScanPeriod(1100l);
beaconManager.setBackgroundBetweenScanPeriod(1100l);
Region region = new Region("com.exe", null, null, null);
regionBootstrap = new RegionBootstrap(this, region);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
@Override
public void didDetermineStateForRegion(int arg0, Region arg1) {
// TODO Auto-generated method stub
}
@Override
public void didEnterRegion(Region arg0) {
showNotification() ;
}
@Override
public void didExitRegion(Region arg0) {
// TODO Auto-generated method stub
}
private void showNotification() {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setContentTitle("My notification")
.setContentText("Contentttttttt").setAutoCancel(true);
Intent intent = new Intent(this, IbeaconNotificationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}