本文整理汇总了Java中com.google.android.gms.awareness.fence.FenceUpdateRequest类的典型用法代码示例。如果您正苦于以下问题:Java FenceUpdateRequest类的具体用法?Java FenceUpdateRequest怎么用?Java FenceUpdateRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FenceUpdateRequest类属于com.google.android.gms.awareness.fence包,在下文中一共展示了FenceUpdateRequest类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: registerFence
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
protected void registerFence(final String fenceKey, final AwarenessFence fence) {
Awareness.FenceApi.updateFences(
client,
new FenceUpdateRequest.Builder()
.addFence(fenceKey, fence, myPendingIntent) //Add fence to the pendingIntent
.build())
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.e(fenceKey, "Fence was successfully registered.");
} else {
Log.e(fenceKey, "Fence could not be registered: " + status);
}
}
});
}
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:18,代码来源:AwarenessMotionUpdatesProvider.java
示例2: unregisterFence
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
protected void unregisterFence(final String fenceKey) {
Awareness.FenceApi.updateFences(
client,
new FenceUpdateRequest.Builder()
.removeFence(fenceKey)
.build()).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.e("Fence", "Fence " + fenceKey + " successfully removed.");
} else {
Log.e("Fence", "Fence " + fenceKey + " can not be removed.");
}
}
});
}
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:18,代码来源:AwarenessMotionUpdatesProvider.java
示例3: addFence
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
/**
* Add a fence to the Google API
* If not connected, this will only trigger a connection.
* This call requires that the following granted permissions:
* - ACCESS_FINE_LOCATION if one of the fence is a {@link StorableLocationFence}
* - ACTIVITY_RECOGNITION if one of the fence is a {@link StorableActivityFence}
* @param id the unique id of the fence.
* @param fence the fence to store
* @param pendingIntentClassName the class name of the pending intent to call when the fence will be valid.
* @param status the status that will be called when the addition fails or succeed.
* @return true if add has been asked, false otherwise.
*/
boolean addFence(@NonNull String id, @NonNull AwarenessFence fence,
@NonNull String pendingIntentClassName, ResultCallback<Status> status) {
if (mGoogleApiClient.isConnected()) {
FenceUpdateRequest.Builder requestBuilder = new FenceUpdateRequest.Builder()
.addFence(id, fence, createRequestPendingIntent(pendingIntentClassName));
Awareness.FenceApi.updateFences(mGoogleApiClient, requestBuilder.build())
.setResultCallback(status);
return true;
} else {
connect();
return false;
}
}
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:28,代码来源:GapiFenceManager.java
示例4: removeFence
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
/**
* Ask to remove a fence from the Google API.
* @param fenceId The id of the fence to remove.
* @param status the status that will be called when the addition fails or succeed.
* @return true if remove has been asked, false otherwise.
*/
boolean removeFence(@NonNull String fenceId, ResultCallback<Status> status) {
if (mGoogleApiClient.isConnected()) {
FenceUpdateRequest.Builder requestBuilder = new FenceUpdateRequest.Builder()
.removeFence(fenceId);
Awareness.FenceApi.updateFences(mGoogleApiClient, requestBuilder.build())
.setResultCallback(status);
Log.i(TAG, "Removed " + fenceId);
return true;
} else {
connect();
return false;
}
}
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:23,代码来源:GapiFenceManager.java
示例5: onPause
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
@Override
protected void onPause() {
// Unregister the fence:
Awareness.getFenceClient(this).updateFences(new FenceUpdateRequest.Builder()
.removeFence(FENCE_KEY)
.build())
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.i(TAG, "Fence was successfully unregistered.");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Fence could not be unregistered: " + e);
}
});
super.onPause();
}
开发者ID:googlesamples,项目名称:android-play-awareness,代码行数:22,代码来源:MainActivity.java
示例6: unregisterFenceRequest
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
private void unregisterFenceRequest(GoogleApiClient googleApiClient, ObservableEmitter<Boolean> emitter) {
FenceUpdateRequest fenceUpdateRequest = new FenceUpdateRequest.Builder()
.removeFence(OBSERVABLE_FENCE)
.build();
Awareness.FenceApi.updateFences(googleApiClient, fenceUpdateRequest)
.setResultCallback(status -> {
if (!status.isSuccess()) {
emitter.onError(new ClientException("Error removing observable fence. " + status.getStatusMessage()));
}
if (googleApiClient.isConnecting() || googleApiClient.isConnected()) {
googleApiClient.disconnect();
}
emitter.onComplete();
});
}
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:18,代码来源:ObservableFence.java
示例7: addHeadphoneFence
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
private void addHeadphoneFence() {
Intent intent = new Intent(MY_FENCE_RECEIVER_ACTION);
PendingIntent mFencePendingIntent = PendingIntent.getBroadcast(FenceActivity.this,
10001,
intent,
0);
AwarenessFence headphoneFence = HeadphoneFence.during(HeadphoneState.PLUGGED_IN);
Awareness.FenceApi.updateFences(
mGoogleApiClient,
new FenceUpdateRequest.Builder()
.addFence(HEADPHONE_FENCE_KEY, headphoneFence, mFencePendingIntent)
.build())
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Fence was successfully registered.");
} else {
Log.e(TAG, "Fence could not be registered: " + status);
}
}
});
}
开发者ID:obaro,项目名称:UsingAwarenessAPI,代码行数:25,代码来源:FenceActivity.java
示例8: addHeadphoneAndLocationFence
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
private void addHeadphoneAndLocationFence() {
Intent intent = new Intent(MY_FENCE_RECEIVER_ACTION);
PendingIntent mFencePendingIntent = PendingIntent.getBroadcast(FenceActivity.this,
10001,
intent,
0);
AwarenessFence headphoneFence = HeadphoneFence.during(HeadphoneState.PLUGGED_IN);
AwarenessFence activityFence = DetectedActivityFence.during(DetectedActivityFence.WALKING);
AwarenessFence jointFence = AwarenessFence.and(headphoneFence, activityFence);
Awareness.FenceApi.updateFences(
mGoogleApiClient,
new FenceUpdateRequest.Builder()
.addFence(HEADPHONE_AND_WALKING_FENCE_KEY,
jointFence, mFencePendingIntent)
.build())
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Headphones AND Walking Fence was successfully registered.");
} else {
Log.e(TAG, "Headphones AND Walking Fence could not be registered: " + status);
}
}
});
}
开发者ID:obaro,项目名称:UsingAwarenessAPI,代码行数:28,代码来源:FenceActivity.java
示例9: onClientConnected
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
private void onClientConnected(GoogleApiClient googleApiClient) {
FenceUpdateRequest fenceRequest = new FenceUpdateRequest.Builder()
.removeFence(name)
.build();
Awareness.FenceApi.updateFences(googleApiClient, fenceRequest)
.setResultCallback(status -> {
if (!status.isSuccess()) {
onClientError(new ClientException("Unable to unregister fence. " + status.getStatusMessage()));
}
googleApiClient.disconnect();
});
}
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:14,代码来源:UnregisterBackgroundFenceAction.java
示例10: subscribe
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
@Override
public void subscribe(ObservableEmitter<Boolean> emitter) throws Exception {
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
FenceState state = FenceState.extract(intent);
boolean result = state.getCurrentState() == FenceState.TRUE;
emitter.onNext(result);
}
};
context.registerReceiver(receiver, new IntentFilter(RECEIVER_ACTION));
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, fence.hashCode(), new Intent(RECEIVER_ACTION), 0);
FenceUpdateRequest fenceUpdateRequest = new FenceUpdateRequest.Builder()
.addFence(OBSERVABLE_FENCE, fence, pendingIntent)
.build();
Awareness.FenceApi.updateFences(googleApiClient, fenceUpdateRequest)
.setResultCallback(status -> {
if (!status.isSuccess()) {
emitter.onError(new ClientException("Error adding observable fence. " + status.getStatusMessage()));
}
emitter.onComplete();
});
emitter.setCancellable(() -> {
context.unregisterReceiver(receiver);
unregisterFenceRequest(googleApiClient, emitter);
});
}
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:32,代码来源:ObservableFence.java
示例11: onClientConnected
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
private void onClientConnected(GoogleApiClient googleApiClient) {
FenceUpdateRequest fenceRequest = new FenceUpdateRequest.Builder()
.addFence(name, fence, FenceReceiver.createPendingIntent(context, fence.hashCode(), data))
.build();
Awareness.FenceApi.updateFences(googleApiClient, fenceRequest)
.setResultCallback(status -> {
if (!status.isSuccess()) {
onClientError(new ClientException("Adding fence failed. " + status.getStatusMessage()));
}
googleApiClient.disconnect();
});
}
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:14,代码来源:RegisterBackgroundFenceAction.java
示例12: addHeadphoneOrLocationFence
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
private void addHeadphoneOrLocationFence() {
Intent intent = new Intent(MY_FENCE_RECEIVER_ACTION);
PendingIntent mFencePendingIntent = PendingIntent.getBroadcast(FenceActivity.this,
10001,
intent,
0);
AwarenessFence headphoneFence = HeadphoneFence.during(HeadphoneState.PLUGGED_IN);
AwarenessFence activityFence = DetectedActivityFence.during(DetectedActivityFence.WALKING);
AwarenessFence orFence = AwarenessFence.or(headphoneFence, activityFence);
Awareness.FenceApi.updateFences(
mGoogleApiClient,
new FenceUpdateRequest.Builder()
.addFence(HEADPHONE_OR_WALKING_FENCE_KEY,
orFence, mFencePendingIntent)
.build())
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Headphones OR Walking Fence was successfully registered.");
} else {
Log.e(TAG, "Headphones OR Walking Fence could not be registered: " + status);
}
}
});
}
开发者ID:obaro,项目名称:UsingAwarenessAPI,代码行数:29,代码来源:FenceActivity.java
示例13: setupFences
import com.google.android.gms.awareness.fence.FenceUpdateRequest; //导入依赖的package包/类
/**
* Sets up {@link AwarenessFence}'s for the sample app, and registers callbacks for them
* with a custom {@link BroadcastReceiver}
*/
private void setupFences() {
// DetectedActivityFence will fire when it detects the user performing the specified
// activity. In this case it's walking.
AwarenessFence walkingFence = DetectedActivityFence.during(DetectedActivityFence.WALKING);
// There are lots of cases where it's handy for the device to know if headphones have been
// plugged in or unplugged. For instance, if a music app detected your headphones fell out
// when you were in a library, it'd be pretty considerate of the app to pause itself before
// the user got in trouble.
AwarenessFence headphoneFence = HeadphoneFence.during(HeadphoneState.PLUGGED_IN);
// Combines multiple fences into a compound fence. While the first two fences trigger
// individually, this fence will only trigger its callback when all of its member fences
// hit a true state.
AwarenessFence walkingWithHeadphones = AwarenessFence.and(walkingFence, headphoneFence);
// We can even nest compound fences. Using both "and" and "or" compound fences, this
// compound fence will determine when the user has headphones in and is engaging in at least
// one form of exercise.
// The below breaks down to "(headphones plugged in) AND (walking OR running OR bicycling)"
AwarenessFence exercisingWithHeadphonesFence = AwarenessFence.and(
headphoneFence,
AwarenessFence.or(
walkingFence,
DetectedActivityFence.during(DetectedActivityFence.RUNNING),
DetectedActivityFence.during(DetectedActivityFence.ON_BICYCLE)));
// Now that we have an interesting, complex condition, register the fence to receive
// callbacks.
// Register the fence to receive callbacks.
Awareness.getFenceClient(this).updateFences(new FenceUpdateRequest.Builder()
.addFence(FENCE_KEY, exercisingWithHeadphonesFence, mPendingIntent)
.build())
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.i(TAG, "Fence was successfully registered.");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Fence could not be registered: " + e);
}
});
}
开发者ID:googlesamples,项目名称:android-play-awareness,代码行数:53,代码来源:MainActivity.java
注:本文中的com.google.android.gms.awareness.fence.FenceUpdateRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论