• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AwarenessFence类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.android.gms.awareness.fence.AwarenessFence的典型用法代码示例。如果您正苦于以下问题:Java AwarenessFence类的具体用法?Java AwarenessFence怎么用?Java AwarenessFence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AwarenessFence类属于com.google.android.gms.awareness.fence包,在下文中一共展示了AwarenessFence类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: registerFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的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: getAwarenessFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
@Override
AwarenessFence getAwarenessFence(Context ctx) {
    if (ActivityCompat.checkSelfPermission(ctx,
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        switch (mTransitionType) {
            case ENTER_TYPE:
                return LocationFence.entering(mLatitude, mLongitude, mRadius);
            case EXIT_TYPE:
                return LocationFence.exiting(mLatitude, mLongitude, mRadius);
            case IN_TYPE:
                return LocationFence.in(mLatitude, mLongitude, mRadius, mDwellTimeMillis);
        }
    }

    return null;
}
 
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:17,代码来源:StorableLocationFence.java


示例3: addFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的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: subscribeToBackgroundFenceWithData

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
private void subscribeToBackgroundFenceWithData() {
    long now = System.currentTimeMillis();
    long in5seconds = now + 5000;
    long in10seconds = now + 10000;

    Bundle bundle = new Bundle();
    bundle.putLong("start", now);

    disposables.add(BackgroundFence.query(this)
            .subscribe(
                    fenceStateMap -> {
                        if (!fenceStateMap.getFenceKeys().contains(ExampleFenceReceiver.TIME)) {
                            AwarenessFence fence = TimeFence.inInterval(in5seconds, in10seconds);
                            BackgroundFence.registerWithData(this, ExampleFenceReceiver.TIME, fence, bundle);
                        }
                    },
                    throwable -> logError(throwable, "query")
            )
    );
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:21,代码来源:MainActivity.java


示例5: addHeadphoneFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的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


示例6: addHeadphoneAndLocationFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的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


示例7: getAwarenessFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的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


示例8: getAwarenessFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
@RequiresPermission("com.google.android.gms.permission.ACTIVITY_RECOGNITION")
@Override
AwarenessFence getAwarenessFence(Context ctx) {
    switch (mTransitionType) {
        case DURING_TYPE:
            return DetectedActivityFence.during(mActivityTypes);
        case START_TYPE:
            return DetectedActivityFence.starting(mActivityTypes);
        case STOP_TYPE:
            return DetectedActivityFence.stopping(mActivityTypes);
    }
    return null;
}
 
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:14,代码来源:StorableActivityFence.java


示例9: getAwarenessFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
@Override
AwarenessFence getAwarenessFence(Context ctx) {
    switch (mTimingType) {
        case ABSOLUTE:
            return TimeFence.inInterval(mStartTime, mStopTime);
        case DAILY:
            return TimeFence.inDailyInterval(mTimeZone, mStartTime, mStopTime);
        case DAY_OF_WEEK:
            return TimeFence.inIntervalOfDay(mDayOfWeek, mTimeZone, mStartTime, mStopTime);
        case TIME_INTERVAL:
            if (ActivityCompat.checkSelfPermission(ctx,
                    Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                return TimeFence.inTimeInterval(mTimeInterval);
            }
            break;
        case TIME_INSTANT:
            return TimeFence.aroundTimeInstant(mTimeInstant, mStartOffset, mStopOffset);
        case MONDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_MONDAY, mTimeZone, mStartTime, mStopTime);
        case TUESDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_TUESDAY, mTimeZone, mStartTime, mStopTime);
        case WEDNESDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_WEDNESDAY, mTimeZone, mStartTime, mStopTime);
        case THURSDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_THURSDAY, mTimeZone, mStartTime, mStopTime);
        case FRIDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_FRIDAY, mTimeZone, mStartTime, mStopTime);
        case SATURDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_SATURDAY, mTimeZone, mStartTime, mStopTime);
        case SUNDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_SUNDAY, mTimeZone, mStartTime, mStopTime);

    }
    return null;
}
 
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:36,代码来源:StorableTimeFence.java


示例10: addFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
@Override
boolean addFence(@NonNull String id, @NonNull AwarenessFence fence, @NonNull String pendingIntentClassName, ResultCallback<Status> status) {
    if (isConnected) {
        addResultDict.put(id, status);
    }
    return isConnected();
}
 
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:8,代码来源:StorableFenceManagerTest.java


示例11: RegisterBackgroundFenceAction

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
private RegisterBackgroundFenceAction(Context context,
                                      String name,
                                      AwarenessFence fence,
                                      @Nullable Bundle data) {
    this.context = context;
    this.name = name;
    this.fence = fence;
    this.data = data;

    Servant.actions(context, Awareness.API, this::onClientConnected, this::onClientError);
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:12,代码来源:RegisterBackgroundFenceAction.java


示例12: subscribeToBackgroundFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的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


示例13: subscribeToRuntimeFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
private void subscribeToRuntimeFence() {
    long now = System.currentTimeMillis();
    long inHalfASecond = now + 500;
    long inASecond = now + 1000;
    AwarenessFence fence = TimeFence.inInterval(inHalfASecond, inASecond);
    disposables.add(
            ObservableFence.create(this, fence)
                    .subscribe(
                            isTrue -> Log.e("TEST", "Runtime Fence: " + isTrue),
                            throwable -> logError(throwable, "observable fence")
                    )
    );
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:14,代码来源:MainActivity.java


示例14: addHeadphoneOrLocationFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的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


示例15: setupFences

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的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


示例16: ObservableFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
private ObservableFence(Context context, GoogleApiClient client, AwarenessFence fence) {
    this.context = context;
    this.googleApiClient = client;
    this.fence = fence;
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:6,代码来源:ObservableFence.java


示例17: registerWithData

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
/**
 * Registers the given fence with extra data to be delivered on callbacks.
 * <p>
 * Will receive updates in the background.
 *
 * @param context context to use
 * @param name    name of the fence
 * @param fence   fence to register
 * @param data    data to attach to the fence
 */
static void registerWithData(Context context,
                             String name,
                             AwarenessFence fence,
                             @Nullable Bundle data) {
    new RegisterBackgroundFenceAction(context.getApplicationContext(), name, fence, data);
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:17,代码来源:RegisterBackgroundFenceAction.java


示例18: create

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
/**
 * Creates an observable fence that will deliver status updates as an {@link Observable}.
 *
 * Unsubscribing from the resulting {@link io.reactivex.disposables.Disposable} will also unregister the fence.
 *
 * @param context context to use
 * @param fence the fence to register
 * @return Observable state updates to the fences state where {@code true} means that the fence
 * condition is valid
 */
public static Observable<Boolean> create(Context context, AwarenessFence fence) {
    return Servant.observable(context.getApplicationContext(), Awareness.API)
            .flatMap(client -> Observable.create(new ObservableFence(context, client, fence)));
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:15,代码来源:ObservableFence.java


示例19: register

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
/**
 * Registers the given fence to receive background updates.
 *
 * @param context context to use
 * @param name    name of the fence
 * @param fence   fence to register
 */
static void register(Context context, String name, AwarenessFence fence) {
    new RegisterBackgroundFenceAction(context.getApplicationContext(), name, fence, null);
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:11,代码来源:RegisterBackgroundFenceAction.java


示例20: register

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
/**
 * Registers a background fence that will receive status callbacks via a {@link FenceReceiver}
 * that should be extended in the application and registered in the AndroidManifest.xml.
 * <p>
 * Once the state of the fence changes, the fence status will be sent to the receiver where you
 * can act on the fence results.
 * <p>
 * If you need to attach additional data to your fence result, consider calling
 * {@link #registerWithData(Context, String, AwarenessFence, Bundle)}.
 *
 * @param context        Context to use for registering the fence
 * @param name           name of the fence to register. Should be unique
 * @param awarenessFence The fence description
 */
public static void register(Context context, String name, AwarenessFence awarenessFence) {
    RegisterBackgroundFenceAction.register(context, name, awarenessFence);
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:18,代码来源:BackgroundFence.java



注:本文中的com.google.android.gms.awareness.fence.AwarenessFence类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java KeyValueStore类代码示例发布时间:2022-05-23
下一篇:
Java RexFieldAccess类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap