本文整理汇总了Java中com.google.android.gms.awareness.fence.HeadphoneFence类的典型用法代码示例。如果您正苦于以下问题:Java HeadphoneFence类的具体用法?Java HeadphoneFence怎么用?Java HeadphoneFence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HeadphoneFence类属于com.google.android.gms.awareness.fence包,在下文中一共展示了HeadphoneFence类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addHeadphoneFence
import com.google.android.gms.awareness.fence.HeadphoneFence; //导入依赖的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
示例2: addHeadphoneAndLocationFence
import com.google.android.gms.awareness.fence.HeadphoneFence; //导入依赖的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
示例3: getAwarenessFence
import com.google.android.gms.awareness.fence.HeadphoneFence; //导入依赖的package包/类
@Override
AwarenessFence getAwarenessFence(Context ctx) {
switch (mTriggerType) {
case STATE:
return HeadphoneFence.during(mHeadphoneState);
case PLUGGING_IN:
return HeadphoneFence.pluggingIn();
case UNPLUGGING:
return HeadphoneFence.unplugging();
}
return null;
}
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:13,代码来源:StorableHeadphoneFence.java
示例4: subscribeToBackgroundFence
import com.google.android.gms.awareness.fence.HeadphoneFence; //导入依赖的package包/类
private void subscribeToBackgroundFence() {
disposables.add(BackgroundFence.query(this)
.subscribe(
fenceStateMap -> {
if (!fenceStateMap.getFenceKeys().contains(ExampleFenceReceiver.HEADPHONES)) {
AwarenessFence fence = HeadphoneFence.during(HeadphoneState.PLUGGED_IN);
BackgroundFence.register(this, ExampleFenceReceiver.HEADPHONES, fence);
}
},
throwable -> logError(throwable, "query")
)
);
}
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:14,代码来源:MainActivity.java
示例5: addHeadphoneOrLocationFence
import com.google.android.gms.awareness.fence.HeadphoneFence; //导入依赖的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
示例6: setupFences
import com.google.android.gms.awareness.fence.HeadphoneFence; //导入依赖的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.HeadphoneFence类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论