This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void requestHint() { | |
HintRequest hintRequest = new HintRequest.Builder() | |
.setPhoneNumberIdentifierSupported(true) | |
.build(); | |
PendingIntent intent = Auth.CredentialsApi.getHintPickerIntent( | |
googleApiClient, hintRequest); | |
try { | |
getActivity().startIntentSenderForResult(intent.getIntentSender(), | |
RESOLVE_HINT, null, 0, 0, 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void startSmsRetriever() { | |
SmsRetrieverClient client = SmsRetriever.getClient(getActivity()); | |
Task<Void> task = client.startSmsRetriever(); | |
task.addOnSuccessListener(aVoid -> { | |
Timber.d("1 Started listening for SMS"); | |
}); | |
task.addOnFailureListener(e -> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void addBroadcastRecieverForSMS() { | |
Timber.d("addBroadcastReceiverForSMS"); | |
IntentFilter intentFilter = new IntentFilter(); | |
intentFilter.addAction(SmsRetriever.SMS_RETRIEVED_ACTION); | |
broadcastReceiver = new BroadcastReceiver() { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
Timber.d("SMS Broadcast receiver onReceive()"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
compile "com.google.android.gms:play-services-auth-api-phone:11.0.8" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AwarenessFence locationFence = LocationFence.entering(lat, long, radius); | |
AwarenessFence walkingFence = DetectedActivityFence.during(DetectedActivityFence.WALKING); | |
AwarenessFence walkingIntoFence = AwarenessFence.and(locationFence, walkingFence); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context) | |
.addApi(Awareness.API) | |
.build(); | |
Awareness.FenceApi.updateFences(googleApiClient, | |
new FenceUpdateRequest.Builder() | |
.addFence(id, awarenessFence, pendingIntent) | |
.build()) | |
.setResultCallback(resultCallback); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Awareness.FenceApi.updateFences(googleApiClient, | |
new FenceUpdateRequest.Builder() | |
.removeFence(id) | |
.build()) | |
.setResultCallback(resultCallback); |