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


Java Message类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:sourceallies,项目名称:zonebeacon,代码行数:21,代码来源:TransferActivity.java

示例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);
    }
}
 
开发者ID:stkent,项目名称:calling-card,代码行数:17,代码来源:NearbyActivity.java

示例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);
    }
}
 
开发者ID:stkent,项目名称:calling-card,代码行数:17,代码来源:NearbyActivity.java

示例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");
    }
}
 
开发者ID:Rashwan,项目名称:Reactive-Popular-Movies,代码行数:22,代码来源:NearbyMoviesPresenter.java

示例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);
}
 
开发者ID:hkurokawa,项目名称:RxNearby,代码行数:23,代码来源:MainActivity.java

示例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);
            }
        }
    });
}
 
开发者ID:hkurokawa,项目名称:RxNearby,代码行数:17,代码来源:ApiClientWrapper.java

示例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();
    }
}
 
开发者ID:hkurokawa,项目名称:RxNearby,代码行数:25,代码来源:MessagePublishOperator.java

示例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");
}
 
开发者ID:miguelespinoza,项目名称:react-native-nearby,代码行数:30,代码来源:NearbyModule.java

示例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));
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:8,代码来源:NearbyMessageIntentService.java

示例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));
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:8,代码来源:NearbyMessageIntentService.java

示例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;
    }
}
 
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Beacon-for-Eddystone,代码行数:14,代码来源:BeaconsFragment.java


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