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

Java Awareness类代码示例

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

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



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


示例16: init

import com.google.android.gms.awareness.Awareness; //导入依赖的package包/类
@Override
public void init(Context context) {
    client = new GoogleApiClient.Builder(context)
            .addApi(Awareness.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    client.connect();

    HandlerThread googleHandleThread = new HandlerThread("googleHandleThread");
    googleHandleThread.start();
    googleHandler = new Handler(googleHandleThread.getLooper()){
        @Override
        public void handleMessage(Message msg) {
            Awareness.SnapshotApi.getDetectedActivity(client)
                    .setResultCallback(new ResultCallback<DetectedActivityResult>(){
                        @Override
                        public void onResult(@NonNull DetectedActivityResult detectedActivityResult) {
                            handleResult(detectedActivityResult);
                        }
                    });
            Message newMsg = new Message();
            newMsg.what = 0;
            googleHandler.sendMessageDelayed(newMsg, 5000);
        }
    };
}
 
开发者ID:TalkingData,项目名称:Myna,代码行数:28,代码来源:AwarenessImpl.java


示例17: buildApiClient

import com.google.android.gms.awareness.Awareness; //导入依赖的package包/类
/**
 * Build the google api client to use awareness apis.
 */
private void buildApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(CombineFenceApiActivity.this)
            .addApi(Awareness.API)
            .addConnectionCallbacks(this)
            .build();
    mGoogleApiClient.connect();
}
 
开发者ID:kevalpatel2106,项目名称:android-samples,代码行数:11,代码来源:CombineFenceApiActivity.java


示例18: buildApiClient

import com.google.android.gms.awareness.Awareness; //导入依赖的package包/类
/**
 * Build the google api client to use awareness apis.
 */
private void buildApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(SnapshotApiActivity.this)
            .addApi(Awareness.API)
            .addConnectionCallbacks(this)
            .build();
    mGoogleApiClient.connect();
}
 
开发者ID:kevalpatel2106,项目名称:android-samples,代码行数:11,代码来源:SnapshotApiActivity.java


示例19: getPlace

import com.google.android.gms.awareness.Awareness; //导入依赖的package包/类
/**
 * Get the nearby places using Snapshot apis. We are going to display only first 5 places to the user in the list.
 */
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
private void getPlace() {
    //noinspection MissingPermission
    Awareness.SnapshotApi.getPlaces(mGoogleApiClient)
            .setResultCallback(new ResultCallback<PlacesResult>() {
                @Override
                public void onResult(@NonNull final PlacesResult placesResult) {
                    if (!placesResult.getStatus().isSuccess()) {
                        Toast.makeText(SnapshotApiActivity.this, "Could not get places.", Toast.LENGTH_LONG).show();
                        return;
                    }

                    //get the list of all like hood places
                    List<PlaceLikelihood> placeLikelihoodList = placesResult.getPlaceLikelihoods();

                    // Show the top 5 possible location results.
                    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.current_place_container);
                    linearLayout.removeAllViews();
                    if (placeLikelihoodList != null) {
                        for (int i = 0; i < 5 && i < placeLikelihoodList.size(); i++) {
                            PlaceLikelihood p = placeLikelihoodList.get(i);

                            //add place row
                            View v = LayoutInflater.from(SnapshotApiActivity.this).inflate(R.layout.row_nearby_place, linearLayout, false);
                            ((TextView) v.findViewById(R.id.place_name)).setText(p.getPlace().getName());
                            ((TextView) v.findViewById(R.id.place_address)).setText(p.getPlace().getAddress());
                            linearLayout.addView(v);
                        }
                    } else {
                        Toast.makeText(SnapshotApiActivity.this, "Could not get nearby places.", Toast.LENGTH_LONG).show();
                    }
                }
            });
}
 
开发者ID:kevalpatel2106,项目名称:android-samples,代码行数:38,代码来源:SnapshotApiActivity.java


示例20: getLocation

import com.google.android.gms.awareness.Awareness; //导入依赖的package包/类
/**
 * Get user's current location. We are also displaying Google Static map.
 */
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
private void getLocation() {
    //noinspection MissingPermission
    Awareness.SnapshotApi.getLocation(mGoogleApiClient)
            .setResultCallback(new ResultCallback<LocationResult>() {
                @Override
                public void onResult(@NonNull LocationResult locationResult) {
                    if (!locationResult.getStatus().isSuccess()) {
                        Toast.makeText(SnapshotApiActivity.this, "Could not get location.", Toast.LENGTH_LONG).show();
                        return;
                    }

                    //get location
                    Location location = locationResult.getLocation();
                    ((TextView) findViewById(R.id.current_latlng)).setText(location.getLatitude() + ", " + location.getLongitude());

                    //display the time
                    TextView timeTv = (TextView) findViewById(R.id.latlng_time);
                    SimpleDateFormat sdf = new SimpleDateFormat("h:mm a dd-MM-yyyy", Locale.getDefault());
                    timeTv.setText("as on: " + sdf.format(new Date(location.getTime())));

                    //Load the current map image from Google map
                    String url = "https://maps.googleapis.com/maps/api/staticmap?center="
                            + location.getLatitude() + "," + location.getLongitude()
                            + "&zoom=20&size=400x250&key=" + getString(R.string.api_key);
                    Picasso.with(SnapshotApiActivity.this).load(url).into((ImageView) findViewById(R.id.current_map));
                }
            });
}
 
开发者ID:kevalpatel2106,项目名称:android-samples,代码行数:33,代码来源:SnapshotApiActivity.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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