0

I am using altbeacon lib for detecting ibeacons. If I detect ibeacons from activity by starting service its detecting ibeacons perfectly fine.

Now I want to start the same operation in background(STICKY service). I followed this document. It is detecting ibeacons but problem is with time. It is taking too long to detect. I kept period to detect as below.

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());

}

}

Dhrupal
  • 1,863
  • 1
  • 23
  • 38

0 Answers0