Skip to content

Instantly share code, notes, and snippets.

Intent intent = new Intent(FENCE_RECEIVER_ACTION);
intent.setClass(context, GeoFenceAwarenessReceiver.class);
// Creates pending intent to handle geo fence event
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, FENCE_REQUEST_CODE, intent, 0);
<android.support.design.widget.TextInputLayout
android:id="@+id/textEmailLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email_address"
android:labelFor="@+id/textEmail">
<EditText android:id="@+id/textEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cursorVisible="true"
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AP.Widget.EditText" parent="Widget.AppCompat.EditText">
<item name="android:textAppearance">
@style/AP.TextAppearance.AppCompat.Input.Value
</item>
<item name="android:textColor">@color/AP_P_Grey</item>
<item name="android:importantForAutofill">
noExcludeDescendants
</item>
android {
compileSdkVersion 'android-27'
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 18
targetSdkVersion 27
}
}
<receiver android:name=".GeoFenceOnBootCompleteReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Awareness.FenceApi.updateFences(googleApiClient,
new FenceUpdateRequest.Builder()
.removeFence(id)
.build())
.setResultCallback(resultCallback);
@Override
public void onReceive(Context context, Intent intent) {
FenceState fenceState = FenceState.extract(intent);
String geoFenceKey = fenceState.getFenceKey();
switch (fenceState.getCurrentState()) {
case FenceState.TRUE:
Timber.d("fence %s detected", geoFenceKey);
break;
case FenceState.FALSE:
Timber.d("fence %s false", geoFenceKey);
ResultCallback<Status> resultCallback = status -> {
if (status.isSuccess()) {
Timber.d("Fence %s was successfully registered", geoFence.getId());
databaseManager.save(geoFence);
} else {
Timber.e("Fence %s could not be registered: %s", geoFence.getId(), status);
}
};
Intent intent = new Intent(FENCE_RECEIVER_ACTION);
intent.setClass(context, GeoFenceAwarenessReceiver.class);
// Creates pending intent to handle geo fence event
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, FENCE_REQUEST_CODE, intent, 0);
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context)
.addApi(Awareness.API)
.build();
Awareness.FenceApi.updateFences(googleApiClient,
new FenceUpdateRequest.Builder()
.addFence(id, awarenessFence, pendingIntent)
.build())
.setResultCallback(resultCallback);