i have problem with Alt Library I want use BootstrapNotifier. I need launch activity/service or create notification when application not runing. (after first launch) I can detect beacons (Kontakt.io) when application in foreground and background. But need launch create notification when phone is near my beacons when app isn't on foreground and background.
I try download Reference application which work for scanning beacons while application is on foreground and background but BootstrapNotifier not detect beacon when app was killed.
I try this reference application on android 5.1 and 8.1 but not work, still only detect beacons foreground/background.
Please how i can solve my problem? in reference application i change only beacon layout for Kontakt.io "m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"
I was tried Eddystone and iBeacon but its the same.
Thanks for any advice
i use this version of library
implementation 'org.altbeacon:android-beacon-library:2.15'
///////////////////////////////////////////
my Application
public class MyApplicationName extends Application implements BootstrapNotifier {
private static final String TAG = "MyApplicationName";
private RegionBootstrap regionBootstrap;
private BackgroundPowerSaver backgroundPowerSaver;
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "App started up");
BeaconManager beaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(getApplicationContext());
// By default the AndroidBeaconLibrary will only find AltBeacons. If you wish to make it
// find a different type of beacon, you must specify the byte layout for that beacon's
// advertisement with a line like below. The example shows how to find a beacon with the
// same byte layout as AltBeacon but with a beaconTypeCode of 0xaabb. To find the proper
// layout expression for other beacon types, do a web search for "setBeaconLayout"
// including the quotes.
//
beaconManager.getBeaconParsers().clear();
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
// Uncomment the code below to use a foreground service to scan for beacons. This unlocks
// the ability to continually scan for long periods of time in the background on Andorid 8+
// in exchange for showing an icon at the top of the screen and a always-on notification to
// communicate to users that your app is using resources in the background.
//
Notification.Builder builder = new Notification.Builder(this);
builder.setContentTitle("Scanning for Beacons");
Intent intent = new Intent(this, MonitoringActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT
);
builder.setContentIntent(pendingIntent);
beaconManager.enableForegroundServiceScanning(builder.build(), 456);
// For the above foreground scanning service to be useful, you need to disable
// JobScheduler-based scans (used on Android 8+) and set a fast background scan
// cycle that would otherwise be disallowed by the operating system.
//
beaconManager.setEnableScheduledScanJobs(false);
beaconManager.setBackgroundBetweenScanPeriod(0);
beaconManager.setBackgroundScanPeriod(1100);
Log.d(TAG, "setting up background monitoring for beacons and power saving");
// wake up the app when a beacon is seen
Region region = new Region("backgroundRegion",
Identifier.parse("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6"), null, null);
regionBootstrap = new RegionBootstrap(this, region);
// simply constructing this class and holding a reference to it in your custom Application
// class will automatically cause the BeaconLibrary to save battery whenever the application
// is not visible. This reduces bluetooth power usage by about 60%
backgroundPowerSaver = new BackgroundPowerSaver(getApplicationContext());
}
@Override
public void didDetermineStateForRegion(int arg0, Region arg1) {
// Don't care
}
@Override
public void didEnterRegion(Region arg0) {
Log.d(TAG, "Got a didEnterRegion call");
// This call to disable will make it so the activity below only gets launched the first time a beacon is seen (until the next time the app is launched)
// if you want the Activity to launch every single time beacons come into view, remove this call.
//regionBootstrap.disable();
Intent intent = new Intent(this, RangingActivity.class);
// IMPORTANT: in the AndroidManifest.xml definition of this activity, you must set android:launchMode="singleInstance" or you will get two instances
// created when a user launches the activity manually and it gets launched from here.
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
}
@Override
public void didExitRegion(Region arg0) {
// Don't care
}
/////////////// manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.par.servicebeacontest">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <application
android:name=".MyApplicationName"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- Note: the singleInstance below is important to keep two copies of your activity from getting launched on automatic startup -->
<activity
android:name=".RangingActivity"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".MyActivity" />
<activity android:name=".test">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>