当前位置: 首页>>代码示例>>Java>>正文


Java Awareness类代码示例

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


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

示例1: registerFence

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

import com.google.android.gms.awareness.Awareness; //导入依赖的package包/类
/**
 * Get the current weather condition at current location.
 */
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
private void getWeather() {
    //noinspection MissingPermission
    Awareness.SnapshotApi.getWeather(mGoogleApiClient)
            .setResultCallback(new ResultCallback<WeatherResult>() {
                @Override
                public void onResult(@NonNull WeatherResult weatherResult) {
                    if (!weatherResult.getStatus().isSuccess()) {
                        Toast.makeText(SnapshotApiActivity.this, "Could not get weather.", Toast.LENGTH_LONG).show();
                        return;
                    }

                    //parse and display current weather status
                    Weather weather = weatherResult.getWeather();
                    String weatherReport = "Temperature: " + weather.getTemperature(Weather.CELSIUS)
                            + "\nHumidity: " + weather.getHumidity();
                    ((TextView) findViewById(R.id.weather_status)).setText(weatherReport);
                }
            });
}
 
开发者ID:kevalpatel2106,项目名称:android-samples,代码行数:24,代码来源:SnapshotApiActivity.java

示例4: getHeadphoneStatus

import com.google.android.gms.awareness.Awareness; //导入依赖的package包/类
/**
 * Check weather the headphones are plugged in or not? This is under snapshot api category.
 */
private void getHeadphoneStatus() {
    Awareness.SnapshotApi.getHeadphoneState(mGoogleApiClient)
            .setResultCallback(new ResultCallback<HeadphoneStateResult>() {
                @Override
                public void onResult(@NonNull HeadphoneStateResult headphoneStateResult) {
                    if (!headphoneStateResult.getStatus().isSuccess()) {
                        Toast.makeText(SnapshotApiActivity.this, "Could not get headphone state.", Toast.LENGTH_LONG).show();
                        return;
                    }
                    HeadphoneState headphoneState = headphoneStateResult.getHeadphoneState();

                    //display the status
                    TextView headphoneStatusTv = (TextView) findViewById(R.id.headphone_status);
                    headphoneStatusTv.setText(headphoneState.getState() == HeadphoneState.PLUGGED_IN ? "Plugged in." : "Unplugged.");
                }
            });
}
 
开发者ID:kevalpatel2106,项目名称:android-samples,代码行数:21,代码来源:SnapshotApiActivity.java

示例5: addFence

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

示例6: removeFence

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

示例7: onPause

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

示例8: getWeatherSnapshot

import com.google.android.gms.awareness.Awareness; //导入依赖的package包/类
/**
 * Helper method to retrieve weather data using the Snapshot API.  Since Weather is protected
 * by a runtime permission, this snapshot code is going to be called in multiple places:
 * {@link #printSnapshot()} when the permission has already been accepted, and
 * {@link #onRequestPermissionsResult(int, String[], int[])} when the permission is requested
 * and has been granted.
 */
private void getWeatherSnapshot() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
        Awareness.getSnapshotClient(this).getWeather()
                .addOnSuccessListener(new OnSuccessListener<WeatherResponse>() {
                    @Override
                    public void onSuccess(WeatherResponse weatherResponse) {
                        Weather weather = weatherResponse.getWeather();
                        weather.getConditions();
                        mLogFragment.getLogView().println("Weather: " + weather);
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Log.e(TAG, "Could not get weather: " + e);
                    }
                });
    }
}
 
开发者ID:googlesamples,项目名称:android-play-awareness,代码行数:28,代码来源:MainActivity.java

示例9: unregisterFenceRequest

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

示例10: onCreate

import com.google.android.gms.awareness.Awareness; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_snapshot);

    mGoogleApiClient = new GoogleApiClient.Builder(SnapshotActivity.this)
            .addApi(Awareness.API)
            .build();
    mGoogleApiClient.connect();

    mUserActivityTextView = (TextView) findViewById(R.id.userActivityTextView);
    mLocationTextView = (TextView) findViewById(R.id.locationTextView);
    mBeaconTextView = (TextView) findViewById(R.id.beaconTextView);
    mPlacesTextView = (TextView) findViewById(R.id.placesTextView);
    mTimeTextView = (TextView) findViewById(R.id.timeTextView);
    mWeatherTextView = (TextView) findViewById(R.id.weatherTextView);
    mHeadphonesTextView = (TextView) findViewById(R.id.action1TextView);

    mSnapshotButton = (Button) findViewById(R.id.snapshotButton);
    mSnapshotButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            getSnapshots();
        }
    });
}
 
开发者ID:obaro,项目名称:UsingAwarenessAPI,代码行数:27,代码来源:SnapshotActivity.java

示例11: addHeadphoneFence

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

示例12: addHeadphoneAndLocationFence

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

示例13: provide

import com.google.android.gms.awareness.Awareness; //导入依赖的package包/类
@Override
    protected void provide() {
        Thread thread = Thread.currentThread();
        Thread.UncaughtExceptionHandler wrapped = thread.getUncaughtExceptionHandler();
        if (!(wrapped instanceof GoogleApiFixUncaughtExceptionHandler)) {
            GoogleApiFixUncaughtExceptionHandler handler = new GoogleApiFixUncaughtExceptionHandler(wrapped);
            thread.setUncaughtExceptionHandler(handler);
        }
//        Thread thread = Thread.currentThread();
//        thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
//            @Override
//            public void uncaughtException(Thread thread, Throwable throwable) {
//                System.out.println(thread.getName() + " throws exception: " + throwable);
//            }
//        });

            client = new GoogleApiClient.Builder(getContext())                              //Establish Connection
                    .addApi(Awareness.API)
                    .build();
            client.connect();
            walkingFence = DetectedActivityFence.during(DetectedActivityFence.WALKING);     //Create Fence
            onFootFence = DetectedActivityFence.during(DetectedActivityFence.ON_FOOT);
            runningFence = DetectedActivityFence.during(DetectedActivityFence.RUNNING);

            intent = new Intent(FENCE_RECEIVER_ACTION);                                     //Set up the intent and intent filter
            myFillter = new IntentFilter(FENCE_RECEIVER_ACTION);
            myPendingIntent = PendingIntent.getBroadcast(getContext(), 0, intent, 0);           //Set up the pendingIntent
            myFenceReceiver = new FenceReceiver();                                              //Set up the receiver
            getContext().registerReceiver(myFenceReceiver, myFillter);
            registerFence(WALKINGFENCE, walkingFence);                                       //register the fences
            registerFence(TILTINGFENCE, tiltingFence);
            registerFence(ONFOOTFENCE, onFootFence);
            registerFence(RUNNINGFENCE, runningFence);
    }
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:35,代码来源:AwarenessMotionUpdatesProvider.java

示例14: initAwarenessClient

import com.google.android.gms.awareness.Awareness; //导入依赖的package包/类
private void initAwarenessClient() {
    if (awarenessApiClient == null || !awarenessApiClient.isConnected()) {
        awarenessApiClient = new GoogleApiClient.Builder(getApplicationContext())
                .addApi(Awareness.API)
                .build();
        awarenessApiClient.connect();
    }
}
 
开发者ID:Pavou,项目名称:Stalker,代码行数:9,代码来源:MainActivity.java

示例15: onMapReady

import com.google.android.gms.awareness.Awareness; //导入依赖的package包/类
@Override
public void onMapReady(final GoogleMap googleMap) {
    googleMap.getUiSettings().setAllGesturesEnabled(false);

    googleMap.setMaxZoomPreference(20.0f);
    googleMap.setMinZoomPreference(10.0f);
    final LatLng[] currentLocation = new LatLng[1];


    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    Awareness.SnapshotApi.getLocation(awarenessApiClient)
            .setResultCallback(new ResultCallback<LocationResult>() {
                @Override
                public void onResult(@NonNull LocationResult locationResult) {
                    if (!locationResult.getStatus().isSuccess()) {
                        Log.e("", "Could not get location.");
                        return;
                    }
                    Location location = locationResult.getLocation();
                    currentLocation[0] = new LatLng(location.getLatitude(), location.getLongitude());
                    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLocation[0], 12.0f));
                    googleMap.animateCamera(CameraUpdateFactory.zoomTo(16.0f), 3000, null);
                }
            });
}
 
开发者ID:Pavou,项目名称:Stalker,代码行数:28,代码来源:MainActivity.java


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