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


Java PutDataRequest类代码示例

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


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

示例1: onConfigurationAddedOrEdited

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
/**
 * Synchronizes the UART configurations between handheld and wearables.
 * Call this when configuration has been created or altered.
 * @return pending result
 */
public PendingResult<DataApi.DataItemResult> onConfigurationAddedOrEdited(final long id, final UartConfiguration configuration) {
	if (mGoogleApiClient == null || !mGoogleApiClient.isConnected())
		return null;

	final PutDataMapRequest mapRequest = PutDataMapRequest.create(Constants.UART.CONFIGURATIONS + "/" + id);
	final DataMap map = mapRequest.getDataMap();
	map.putString(Constants.UART.Configuration.NAME, configuration.getName());
	final ArrayList<DataMap> commands = new ArrayList<>(UartConfiguration.COMMANDS_COUNT);
	for (Command command : configuration.getCommands()) {
		if (command != null && command.isActive()) {
			final DataMap item = new DataMap();
			item.putInt(Constants.UART.Configuration.Command.ICON_ID, command.getIconIndex());
			item.putString(Constants.UART.Configuration.Command.MESSAGE, command.getCommand());
			item.putInt(Constants.UART.Configuration.Command.EOL, command.getEolIndex());
			commands.add(item);
		}
	}
	map.putDataMapArrayList(Constants.UART.Configuration.COMMANDS, commands);
	final PutDataRequest request = mapRequest.asPutDataRequest();
	return Wearable.DataApi.putDataItem(mGoogleApiClient, request);
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:27,代码来源:UARTConfigurationSynchronizer.java

示例2: putConfigDataItem

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
/**
 * Overwrites the current config {@link DataItem}'s {@link DataMap} with {@code newConfig}.
 * If the config DataItem doesn't exist, it's created.
 */
public static void putConfigDataItem(GoogleApiClient googleApiClient, DataMap newConfig) {
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_WITH_FEATURE);
    DataMap configToPut = putDataMapRequest.getDataMap();
    configToPut.putAll(newConfig);
    PutDataRequest putDataRequest = putDataMapRequest.asPutDataRequest();
    putDataRequest.setUrgent();
    Wearable.DataApi.putDataItem(googleApiClient, putDataRequest)
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(DataApi.DataItemResult dataItemResult) {
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "putDataItem result status: " + dataItemResult.getStatus());
                    }
                }
            });
}
 
开发者ID:marcouberti,项目名称:adrenaline_watch_face,代码行数:21,代码来源:WatchFaceUtil.java

示例3: sendData

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
private void sendData(ArrayList<Story> storiesToSend) {
    if(storiesToSend == null || storiesToSend.size() == 0){
        return;
    }
    PutDataMapRequest dataMap = PutDataMapRequest.create(Tools.WEAR_PATH);
    DataMap dataMapToPut = dataMap.getDataMap();
    JSONArray contentList = new JSONArray();
    for(Story story : storiesToSend){
        contentList.put(story.toJSONObject());
    }

    dataMapToPut.putString(Tools.WEAR_KEY, contentList.toString());
    PutDataRequest request = dataMap.asPutDataRequest();
    PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mGoogleAppiClient, request);
    pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
        @Override
        public void onResult(DataApi.DataItemResult dataItemResult) {
            mGoogleAppiClient.disconnect();
        }
    });

}
 
开发者ID:tajchert,项目名称:SpritzerWear,代码行数:23,代码来源:StorySender.java

示例4: getUpdateRequest

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
/**
 * Obtain a {@link PutDataRequest} to update a league's current state.
 *
 * @param account the account which owns the team competing in the league
 * @param league a proto describing the league
 * @param matchup a proto describing the account's team's current matchup
 * @param logo an Asset containing the user's logo image. The image should be square with size
 *             {@link com.jeffpdavidson.fantasywear.common.R.dimen#logo_size}.
 * @param opponentLogo an Asset containing the user's opponent's logo image. The image should be
 *                     square with size
 *                     {@link com.jeffpdavidson.fantasywear.common.R.dimen#logo_size}.
 * @param forceUpdate if true, will ensure that listening devices see the update even if no
 *                    fields have changed since the last update. Use conservatively as this will
 */
public static PutDataRequest getUpdateRequest(Account account, League league, Matchup matchup,
        Asset logo, Asset opponentLogo, boolean forceUpdate) {
    PutDataMapRequest request =
            PutDataMapRequest.create(getLeagueUri(account, league).toString());
    DataMap map = request.getDataMap();
    map.putInt(KEY_APP_VERSION, BuildConfig.VERSION_CODE);
    map.putString(KEY_MATCHUP, WireUtil.encodeToString(matchup));
    map.putAsset(KEY_LOGO, logo);
    map.putAsset(KEY_OPPONENT_LOGO, opponentLogo);
    if (forceUpdate) {
        // Play services suppresses updates if the payload exactly matches the last one, so when
        // forcing an update, include the current time to guarantee a unique payload.
        map.putLong(KEY_TIMESTAMP, System.currentTimeMillis());
    }
    return request.asPutDataRequest();
}
 
开发者ID:jpd236,项目名称:fantasywear,代码行数:31,代码来源:LeagueData.java

示例5: insert

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
/**
 * This method is called when someone wants to insert something
 * into our content provider.
 */
@Override
public Uri insert(Uri uri, ContentValues values) {
    // you can't choose your own task id
    if( values.containsKey(COLUMN_TASKID))
        throw new UnsupportedOperationException();

    long id = db.insertOrThrow(DATABASE_TABLE, null,
            values);
    getContext().getContentResolver().notifyChange(uri, null);

    // Save to google Play for wearable support
    PutDataMapRequest dataMap = PutDataMapRequest.create(
            PLAY_BASE_URL + "/" + id);
    DataMap map = dataMap.getDataMap();
    map.putLong(COLUMN_TASKID, id);
    map.putString(COLUMN_TITLE, values.getAsString(COLUMN_TITLE));
    map.putLong(COLUMN_DATE_TIME, values.getAsLong(COLUMN_DATE_TIME));
    map.putString(COLUMN_NOTES, values.getAsString(COLUMN_NOTES));
    PutDataRequest request = dataMap.asPutDataRequest();
    Wearable.DataApi.putDataItem(googleApiClient, request);


    return ContentUris.withAppendedId(uri, id);
}
 
开发者ID:emmby,项目名称:easy-a,代码行数:29,代码来源:TaskProvider.java

示例6: putNotification

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
@WorkerThread
public void putNotification(String title, String textShort, String textLong, @Nullable Bitmap photo, Uri contactUri, @Nullable String phoneNumber) {
    Log.d();
    // First remove any old notification
    Wearable.DataApi.deleteDataItems(mGoogleApiClient, createUri(PATH_NOTIFICATION)).await();

    // Create new notification
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_NOTIFICATION);

    DataMap dataMap = putDataMapRequest.getDataMap();
    dataMap.putString(EXTRA_TITLE, title);
    dataMap.putString(EXTRA_TEXT_SHORT, textShort);
    dataMap.putString(EXTRA_TEXT_LONG, textLong);
    if (photo != null) dataMap.putAsset(EXTRA_PHOTO, createAssetFromBitmap(photo));
    byte[] contactUriBytes = ParcelableUtil.parcel(contactUri);
    dataMap.putByteArray(EXTRA_CONTACT_URI, contactUriBytes);
    if (phoneNumber != null) dataMap.putString(EXTRA_PHONE_NUMBER, phoneNumber);

    PutDataRequest request = putDataMapRequest.asPutDataRequest();
    Wearable.DataApi.putDataItem(mGoogleApiClient, request).await();
}
 
开发者ID:BoD,项目名称:DoorCodeNotifier,代码行数:22,代码来源:WearHelper.java

示例7: onConfigurationAddedOrEdited

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
/**
 * Synchronizes the UART configurations between handheld and wearables.
 * Call this when configuration has been created or altered.
 * @return pending result
 */
public PendingResult<DataApi.DataItemResult> onConfigurationAddedOrEdited(final long id, final UartConfiguration configuration) {
	if (!hasConnectedApi())
		return null;

	final PutDataMapRequest mapRequest = PutDataMapRequest.create(Constants.UART.CONFIGURATIONS + "/" + id);
	final DataMap map = mapRequest.getDataMap();
	map.putString(Constants.UART.Configuration.NAME, configuration.getName());
	final ArrayList<DataMap> commands = new ArrayList<>(UartConfiguration.COMMANDS_COUNT);
	for (Command command : configuration.getCommands()) {
		if (command != null && command.isActive()) {
			final DataMap item = new DataMap();
			item.putInt(Constants.UART.Configuration.Command.ICON_ID, command.getIconIndex());
			item.putString(Constants.UART.Configuration.Command.MESSAGE, command.getCommand());
			item.putInt(Constants.UART.Configuration.Command.EOL, command.getEolIndex());
			commands.add(item);
		}
	}
	map.putDataMapArrayList(Constants.UART.Configuration.COMMANDS, commands);
	final PutDataRequest request = mapRequest.asPutDataRequest();
	return Wearable.DataApi.putDataItem(mGoogleApiClient, request);
}
 
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Toolbox,代码行数:27,代码来源:UARTConfigurationSynchronizer.java

示例8: buildDataRequest

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
/**
 * Builds a {@link com.google.android.gms.wearable.PutDataRequest} which holds a JSON
 * representation of the feedback collected.
 */
private PutDataRequest buildDataRequest() throws JSONException {
    PutDataMapRequest putDataMapRequest = PutDataMapRequest
            .create(HomeListenerService.PATH_RESPONSE);
    DataMap dataMap = putDataMapRequest.getDataMap();

    JSONArray jsonArray = new JSONArray();
    if (!responses.isEmpty()) {
        JSONObject sessionObj = new JSONObject();
        sessionObj.put("s", mSessionId);
        jsonArray.put(0, sessionObj);
        int i = 1;
        for (Integer key : responses.keySet()) {
            JSONObject obj = new JSONObject();
            obj.put("q", key);
            obj.put("a", responses.get(key));
            jsonArray.put(i++, obj);
        }
    }
    String response = jsonArray.toString();
    LOGD(TAG, "JSON representation of the response: " + response);
    dataMap.putString("response", response);
    return putDataMapRequest.asPutDataRequest();
}
 
开发者ID:The-WebOps-Club,项目名称:saarang-iosched,代码行数:28,代码来源:PagerActivity.java

示例9: updateWearWeather

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
private void updateWearWeather(int weather_id, double high_temp, double low_temp){
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(WEATHER_PATH).setUrgent();
    putDataMapRequest.getDataMap().putInt(WEATHER_ID, weather_id);
    Log.d(LOG_TAG, "value of weather put : "+weather_id);
    putDataMapRequest.getDataMap().putDouble(HIGH_TEMP, high_temp);
    putDataMapRequest.getDataMap().putDouble(LOW_TEMP, low_temp);
    PutDataRequest putDataRequest = putDataMapRequest.asPutDataRequest().setUrgent();
    PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mWearClient, putDataRequest);

    pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
        @Override
        public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
            if (dataItemResult.getStatus().isSuccess()) {
                Log.d(LOG_TAG, "Data item set: " + dataItemResult.getDataItem().getUri());

            } else {
                Log.d(LOG_TAG, "Error in sending data to watch");
            }
        }

    });
}
 
开发者ID:rashikaranpuria,项目名称:ubiquitous,代码行数:23,代码来源:SunshineSyncIntentService.java

示例10: alarmCommand

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
private void alarmCommand(Intent intent) {
    AlarmCommand commandData = intent.getParcelableExtra(KEY_COMMAND_DATA);

    LiteAlarmCommand liteAlarmCommand = new LiteAlarmCommand(commandData);

    PutDataRequest putDataRequest = PutDataRequest.create(CommPaths.COMMAND_ALARM);
    putDataRequest.setData(ParcelPacker.getData(liteAlarmCommand));

    if (commandData.getIcon() != null) {
        putDataRequest.putAsset(CommPaths.ASSET_ICON, Asset.createFromBytes(commandData.getIcon()));
    }
    if (commandData.getBackgroundBitmap() != null) {
        putDataRequest.putAsset(CommPaths.ASSET_BACKGROUND, Asset.createFromBytes(commandData.getBackgroundBitmap()));
    }

    putDataRequest.setUrgent();

    Wearable.DataApi.putDataItem(googleApiClient, putDataRequest).await();
}
 
开发者ID:matejdro,项目名称:WearVibrationCenter,代码行数:20,代码来源:WatchCommander.java

示例11: sendTrackingStatusDataMap

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
/**
 * Send the current status of the step count tracking weather it is running or not. This message
 * is important and we should have guarantee of delivery to maintain the state of tracking status
 * on the phone. That is why we are using DataMap to communicate. So, if the phone is not connected
 * the message won't get lost. As soon as the phone connects, this status message will pass to the
 * phone application.
 *
 * @param isTracking true if the tracking is running
 */
private void sendTrackingStatusDataMap(boolean isTracking) {
    PutDataMapRequest dataMapRequest = PutDataMapRequest.create(STEP_TRACKING_STATUS_PATH);

    dataMapRequest.getDataMap().putBoolean("status", isTracking);
    dataMapRequest.getDataMap().putLong("status-time", System.currentTimeMillis());

    PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
    Wearable.DataApi.putDataItem(mGoogleApiClient, putDataRequest)
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
                    //check if the message is delivered?
                    //If the status is failed, that means that the currently device is
                    //not connected. The data will get deliver when phone gets connected to the watch.
                    Log.d("Data saving", dataItemResult.getStatus().isSuccess() ? "Success" : "Failed");
                }
            });

}
 
开发者ID:kevalpatel2106,项目名称:android-samples,代码行数:29,代码来源:TrackActivity.java

示例12: notifyWear

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
private void notifyWear(String newBgColor) {
    PutDataMapRequest dataMapRequest = PutDataMapRequest.create("/bg_change");

    dataMapRequest.getDataMap().putString("new_color", newBgColor);

    PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
    Wearable.DataApi.putDataItem(mGoogleApiClient, putDataRequest)
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
                    //check if the message is delivered?
                    //If the status is failed, that means that the currently device is
                    //not connected. The data will get deliver when phone gets connected to the watch.
                    Log.d("Data saving", dataItemResult.getStatus().isSuccess() ? "Success" : "Failed");
                }
            });
}
 
开发者ID:kevalpatel2106,项目名称:android-samples,代码行数:18,代码来源:WatchFaceConfigActivity.java

示例13: sendData

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
private void sendData(Asset asset) {
    if (asset == null) {
        return;
    }
    PutDataMapRequest dataMap = PutDataMapRequest.create(WEAR_PATH);
    byte[] arr = asset.getData();
    dataMap.getDataMap().putByteArray(DATA_ASSET_FILE, arr);
    dataMap.getDataMap().putLong("timestamp", Calendar.getInstance().getTimeInMillis());
    PutDataRequest request = dataMap.asPutDataRequest();
    PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mGoogleAppiClient, request);
    pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
        @Override
        public void onResult(DataApi.DataItemResult dataItemResult) {
            Log.d(TAG, "onResult result:" + dataItemResult.getStatus());
        }
    });
}
 
开发者ID:LadyViktoria,项目名称:wearDrip,代码行数:18,代码来源:FileSender.java

示例14: sendData

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
private void sendData() {
    ArrayList<Double> tempValues = ForecastFragment.getTempValues();
    Log.v("TAG", tempValues.size()+"");
    final DataMap dataMap = new DataMap();
    dataMap.putDouble("max", tempValues.get(0));
    dataMap.putDouble("min", tempValues.get(1));
    dataMap.putInt("icon", ForecastFragment.getIconId());
    dataMap.putLong("timestamp", System.currentTimeMillis());

    new Thread( new Runnable() {
        @Override
        public void run() {
            PutDataMapRequest dataMapRequest = PutDataMapRequest.create(MOBILE_MESSAGE_PATH).setUrgent();
            dataMapRequest.getDataMap().putAll(dataMap);
            PutDataRequest request = dataMapRequest.asPutDataRequest();

            DataApi.DataItemResult result = Wearable.DataApi.putDataItem(mApiClient, request).await();
            if(result.getStatus().isSuccess()){
                Log.v("TAG", "Sent successfully");
            }else {
                Log.v("TAG", "Failed to send");
            }
        }
    }).start();
}
 
开发者ID:sahilandroid19,项目名称:WearApp,代码行数:26,代码来源:MessageListenerService.java

示例15: putData

import com.google.android.gms.wearable.PutDataRequest; //导入依赖的package包/类
/**
 * Method that puts String data into the Wearable.DataApi layer.
 *
 * @param context
 * @param key key value of the data
 * @param data the data as string
 * @param path the path to store
 * @return Obsservable that emits the result
 */
public static Observable<DataApi.DataItemResult> putData(Context context, final String key, final String data, final String path) {
    return getGoogleApiClient(context)
            .flatMap(new Func1<GoogleApiClient, Observable<DataApi.DataItemResult>>() {
                @Override
                public Observable<DataApi.DataItemResult> call(final GoogleApiClient googleApiClient) {
                    return Observable.create(new Observable.OnSubscribe<DataApi.DataItemResult>() {
                        @Override
                        public void call(final Subscriber<? super DataApi.DataItemResult> subscriber) {
                            PutDataMapRequest putDataMapReq = PutDataMapRequest.create(path);
                            putDataMapReq.getDataMap().putString(key, data);
                            PutDataRequest putDataReq = putDataMapReq.asPutDataRequest();
                            Wearable.DataApi.putDataItem(googleApiClient, putDataReq).setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                                @Override
                                public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
                                    subscriber.onNext(dataItemResult);
                                    subscriber.onCompleted();
                                }
                            });
                        }
                    });
                }
            });
}
 
开发者ID:T-MobileNL,项目名称:Smartwatch,代码行数:33,代码来源:DatalayerUtil.java


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