本文整理汇总了Java中com.google.android.gms.nearby.messages.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于com.google.android.gms.nearby.messages包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessage
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
private void sendMessage(String broadcast, Message message) {
Intent intent;
Bundle bundle;
switch (broadcast){
case Utils.DISPLAY_NOTIFICATION:
intent = new Intent(Utils.NEW_MESSAGE_FOUND);
intent.putExtra(Utils.NEW_MESSAGE_FOUND, message);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
displayNotification(message);
break;
case Utils.REMOVE_NOTIFICATION:
intent = new Intent(Utils.MESSAGE_LOST);
intent.putExtra(Utils.MESSAGE_LOST, message);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
updateNotification(message);
break;
}
}
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Beacon-for-Eddystone,代码行数:19,代码来源:NearbyBackgroundService.java
示例2: onFound
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
/**
* Handle the message when it is found from another device.
*
* @param message the message that was found.
*/
public void onFound(Message message) {
try {
Toast.makeText(this, getString(R.string.found_settings), Toast.LENGTH_SHORT).show();
DataSource dataSource = getDataSource();
dataSource.open();
dataSource.insertDatabaseJson(new JSONObject(GzipUtil.ungzip(message.getContent())));
dataSource.close();
startActivity(new Intent(this, MainActivity.class));
finish();
} catch (Exception e) {
throw new RuntimeException("unable to uncompress message contents", e);
}
}
示例3: onFound
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
@Override
public void onFound(final Message message) {
try {
final User user = GSON.fromJson(new String(message.getContent()), User.class);
if (!nearbyUsers.contains(user)) {
Log.d(TAG, "Discovered " + user.getName());
nearbyUsers.add(user);
refreshUsersViews();
}
} catch (final JsonSyntaxException e) {
Log.e(TAG, "Invalid message received: " + new String(message.getContent()));
Log.e(TAG, "Invalid message exception:", e);
}
}
示例4: onLost
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
@Override
public void onLost(final Message message) {
try {
final User user = GSON.fromJson(new String(message.getContent()), User.class);
if (nearbyUsers.contains(user)) {
Log.d(TAG, "Lost " + user.getName());
nearbyUsers.remove(user);
refreshUsersViews();
}
} catch (final JsonSyntaxException e) {
Log.e(TAG, "Invalid message reported as lost: " + new String(message.getContent()));
Log.e(TAG, "Invalid message exception:", e);
}
}
示例5: publish
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
private void publish(List<Long> ids, GoogleApiClient mGoogleApiClient){
Timber.d("publishing");
if (mGoogleApiClient.isConnected()){
String idsString = adapter.toJson(ids);
Timber.d("Converted: %s",idsString);
mActiveMessage = new Message(idsString.getBytes());
Nearby.Messages.publish(mGoogleApiClient,mActiveMessage)
.setResultCallback(status -> {
if (status.isSuccess()){
Timber.d("published successfully.");
}else {
Timber.d("didn't publish successfully.");
}
});
}else {
Timber.d("couldn't publish because google client is disconnected");
}
}
示例6: onCreate
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
final String msg = "Hi! This is #" + (messageID++) + " message.";
sendMessageSubject.onNext(new Message(msg.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Failed to serialize message.", e);
}
}
});
contentView = (ViewGroup) findViewById(R.id.content);
}
示例7: publish
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
public void publish(final Message message, final ResultHandler handler) {
Nearby.Messages.getPermissionStatus(apiClient).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
if (publishingMessage != null) {
unpublish(null);
}
publishingMessage = message;
Nearby.Messages.publish(apiClient, message).setResultCallback(new ResultCallbackAdapter(handler));
} else {
handler.onError(status);
}
}
});
}
示例8: onNext
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
@Override
public void onNext(final Message message) {
if (apiClient.isConnected()) {
publish(message);
} else {
apiClient.setOnConnectedListener(new ApiClientWrapper.ConnectionListener() {
@Override
public void onConnected(Bundle bundle) {
publish(message);
}
@Override
public void onConnectionSuspended(int causeCode) {
Exceptions.throwOrReport(new ApiConnectionSuspendedException(causeCode), MessagePublishSubscriber.this);
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Exceptions.throwOrReport(new ApiConnectionFailedException(connectionResult), MessagePublishSubscriber.this);
}
});
apiClient.connect();
}
}
示例9: nearbyPublish
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
private void nearbyPublish(String message) {
PublishOptions options = new PublishOptions.Builder()
.setStrategy(PUB_SUB_STRATEGY)
.setCallback(new PublishCallback() {
@Override
public void onExpired() {
super.onExpired();
Log.i(TAG, "No longer publishing");
}
}).build();
Log.i(TAG, "Publishing message: " + message);
mActiveMessage = new Message(message.getBytes());
Nearby.Messages.publish(mGoogleApiClient, mActiveMessage, options)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Published successfully.");
emitSubscription("publish.onResult", "Published successfully.");
} else {
Log.i(TAG, "Could not publish, status = " + status);
emitSubscription("publish.onResultErr", "Could not publish, status = " + status);
}
}
});
Log.i(TAG, "Publish was successful");
}
示例10: onFound
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
@Override
public void onFound(Message message) {
String url = PhysicalWebBleClient.getInstance().getUrlFromMessage(message);
if (url != null) {
UrlManager.getInstance().addUrl(new UrlInfo(url));
}
}
示例11: onLost
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
@Override
public void onLost(Message message) {
String url = PhysicalWebBleClient.getInstance().getUrlFromMessage(message);
if (url != null) {
UrlManager.getInstance().removeUrl(new UrlInfo(url));
}
}
示例12: displayNotification
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
private void displayNotification(Message message){
if (!checkIfnearbyDeviceAlreadyExists(new String(message.getContent(), Charset.forName("UTF-8")))) {
Log.i(Utils.TAG, "Adding message");
mNearbyDevicesMessageList.add(message);
Log.i(Utils.TAG, "count after adding: " + mNearbyDevicesMessageList.size());
createNotification();
}
}
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Beacon-for-Eddystone,代码行数:9,代码来源:NearbyBackgroundService.java
示例13: updateNotification
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
private void updateNotification(Message message){
if (checkIfnearbyDeviceAlreadyExists(new String(message.getContent(), Charset.forName("UTF-8")))) {
Log.i(Utils.TAG, "removing message: " + message);
removeLostNearbyMessage(new String(message.getContent(), Charset.forName("UTF-8")));
Log.i(Utils.TAG, "count after removing: " + mNearbyDevicesMessageList.size());
createNotification();
}
}
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Beacon-for-Eddystone,代码行数:9,代码来源:NearbyBackgroundService.java
示例14: loadNearbyMessageListForNotification
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
private ArrayList<Message> loadNearbyMessageListForNotification(){
final ArrayList<Message> nearbyMessageList = new ArrayList<>();
for(int i = 0; i < mNearbyDevicesMessageList.size(); i++){
nearbyMessageList.add(mNearbyDevicesMessageList.get(i));
}
return nearbyMessageList;
}
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Beacon-for-Eddystone,代码行数:8,代码来源:NearbyBackgroundService.java
示例15: onReceive
import com.google.android.gms.nearby.messages.Message; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
final Message message = intent.getParcelableExtra(action);
switch (action) {
case NEW_MESSAGE_FOUND:
updateBeaconsAdapter(message);
break;
case MESSAGE_LOST:
removeLostNearbyMessage(new String(message.getContent()));
break;
}
}