Click "Exit" button of Google Navigation notification from my application - java

I want to "click" the "Exit Navigation" button that appear in the Google Navigation notification from my android application code.
Google Navigation notification:
I know that there is a way to do it because I can do it using a Tasker task, but I don't know how to do it using code from my application.
I have a NotificationListenerService and I can retrieve the text of the notification when onNotificationPosted is received with the following code:
#Override
public void onNotificationPosted(StatusBarNotification sbn) {
Notification notification = sbn.getNotification();
if (!pack.equals("com.google.android.apps.maps")) return;
RemoteViews views = notification.bigContentView;
if (views == null) views = notification.contentView;
if (views == null) return null;
int viewid=0;
List<String> text = new ArrayList<String>();
try
{
Field fieldActions = views.getClass().getDeclaredField("mActions");
fieldActions.setAccessible(true);
#SuppressWarnings("unchecked")
ArrayList<Parcelable> actions = (ArrayList<Parcelable>) fieldActions.get(views);
for (Parcelable p : actions)
{
Parcel parcel = Parcel.obtain();
p.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
int tag = parcel.readInt();
if (tag != 2) continue;
viewid=parcel.readInt();
String methodName = parcel.readString();
if (methodName == null) continue;
else{
if (methodName.equals("setText"))
{
parcel.readInt();
String t = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel).toString().trim();
text.add(t);
Log.w(TAG,"viewID: "+viewid+"setText: "+t);
}
}
parcel.recycle();
}
} catch (Exception e)
{
Log.e(TAG, e.toString());
}
return text;
}
But I didn't find a way to retrieve the actions ("buttons") of the notification.
Thanks!

It's quite simple. Just get the Action Buttons from that notification like this.
Notification notification = sbn.getNotification();
Notification.Action[] actions = notification.actions;
And because this notification has only one action button, you simply do:
actions[0].actionIntent.send();
AFTER you checked that's a Google Maps notification. You did this here:
if (!pack.equals("com.google.android.apps.maps")) return;
So complete code should look like this:
Notification notification = sbn.getNotification();
Notification.Action[] actions = notification.actions;
if (!pack.equals("com.google.android.apps.maps")) return;
actions[0].actionIntent.send();
Should work. Hope I can help you :)

Related

How to Freeze/Lock android Camera X preview with Flash Light updates on taking picture?

I am implementing Camera X. The issue i am facing is to implement a mechanism to lock/freeze camera preview when picture is captured. Currently i have implement a workaround but it doesn't work well if the flash light is on while capturing. I get a frame from previewView (PreviewView) previewView.getBitmap() as before capturing the image and then display in an captureImage (ImageView). But the the freeze frame not show flash light update. My current code is below
private void capturePhoto() {
showProgress(true);
// Get the Information to be used & stored with Image
ContentValues contentValues = getImageSaveInfo();
Uri externalUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
ImageCapture.OutputFileOptions options = new ImageCapture.OutputFileOptions
.Builder(getContentResolver(), externalUri, contentValues)
.build();
// Play the Capture Sound when a picture is captured.
playCameraShutterSound();
// Display current frame From Preview in ImageView.
freezePreview(true);
imageCapture.takePicture(options,
ContextCompat.getMainExecutor(this),
new ImageCapture.OnImageSavedCallback() {
#Override
public void onImageSaved(#NonNull ImageCapture.OutputFileResults results) {
ToastUtility.successToast(getApplicationContext(),
"Photo Capture Successfully");
// Update Last Taken Image View with new Image
getLastTakenImage();
if (results.getSavedUri() != null) {
Log.d(TAG, "Image Saved At -> " + results.getSavedUri().toString());
}
showProgress(false);
freezePreview(false);
}
#Override
public void onError(#NonNull ImageCaptureException exception) {
ToastUtility.errorToast(getApplicationContext(),
"Photo Couldn't Capture");
Log.d(TAG, "Image Capture Error -> " + exception.getMessage());
showProgress(false);
freezePreview(false);
}
});
}
private void freezePreview(boolean value) {
if (value) {
Bitmap bitmap = mainBinding.previewView.getBitmap();
Glide.with(getApplicationContext())
.load(bitmap).into(mainBinding.captureImage);
mainBinding.captureImage.setVisibility(View.VISIBLE);
mainBinding.previewView.setVisibility(View.INVISIBLE);
} else {
mainBinding.previewView.setVisibility(View.VISIBLE);
mainBinding.captureImage.setVisibility(View.INVISIBLE);
}
}
The flash is triggered at some point after takePicture() is called, there isn't a callback for it in CameraX, so there isn't a direct way to know when it's fired.
You can instead use camera2 interop to indirectly check for the flash state. You can add a session CaptureCallback to ImageCapture's config, then inside the callback's onCaptureCompleted, check if the flash state of the total result is FIRED.
// Override onCaptureCompleted to check for the flash state
CameraCaptureSession.CaptureCallback sessionCaptureCallback = //... ;
// Initialize an ImageCapture builder
ImageCapture.Builder configBuilder = new ImageCapture.Builder();
// Add the session CaptureCallback to it
new Camera2Interop.Extender<>(configBuilder)
.setSessionCaptureCallback(sessionCaptureCallback);
// Build the ImageCapture use case
ImageCapture useCase = configBuilder.build();

How to build a notification in android and implement click listener?

Hello friends i am creating mp3 player application my application is successfully build i want implement click event notification when user goes on background they control media from notification panel my notification also build successfully but problem is that how control music and change image on notification .addaction() when user click on pause the image change to play and when song is play image back change to pause and media player is also and i am also want get songs title, and artist here my code you can easily understand!
public void play(int songindex) {
song = songList.get(songindex);
try {
if (mediaPlayer != null) {
mediaPlayer.release();
mediaPlayer = null;
}
Uri uri = Uri.parse("file:///" + song.getGetpath());
mediaPlayer = MediaPlayer.create(mContext, uri);
title.setText(song.getTitle());
artist.setText(song.getArtist());
notificationTitleText=title.getText();
notificationDescText=artist.getText();
handler = VisualizerDbmHandler.Factory.newVisualizerHandler(getApplicationContext(), mediaPlayer);
audioVisualization.linkTo(handler);
mediaPlayer.start();
seekBar.setProgress(0);
seekBar.setMax(100);
updateProgressBar();
if (mediaPlayer != null && mediaPlayer.isPlaying()) {
play.setVisibility(View.GONE);
pause.setVisibility(View.VISIBLE);
play_main.setVisibility(View.GONE);
pause_main.setVisibility(View.VISIBLE);
Animation aniRotate = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate);
rotate.startAnimation(aniRotate);
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
if (checked) {
mediaPlayer.setLooping(true);
mediaPlayer.start();
} else if (isShuffle) {
// shuffle is on - play a random song
Random rand = new Random();
currentSongIndex = rand.nextInt((songList.size() - 1) - 0 + 1) + 0;
play(currentSongIndex);
} else {
// no repeat or shuffle ON - play next song
if (currentSongIndex < (songList.size() - 1)) {
play(currentSongIndex + 1);
currentSongIndex = currentSongIndex + 1;
} else {
// play first song
play(0);
currentSongIndex = 0;
}
}
}
});
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "" + e, Toast.LENGTH_SHORT).show();
}
}
public void shownotification(){
Bitmap largeImage = BitmapFactory.decodeResource(getResources(),R.drawable.dog);
Notification channel = new NotificationCompat.Builder(getApplicationContext(),CHANNEL_ID_1)
.setSmallIcon(R.drawable.ic_music)
.setContentTitle(notificationTitleText
)
.setContentText(notificationDescText)
.setLargeIcon(largeImage)
.addAction(R.drawable.ic_like,"like",null)
.addAction(R.drawable.ic_prev,"prev",null)
.addAction(R.drawable.ic_pause,"pause",null)
.addAction(R.drawable.ic_next,"next",null)
.addAction(R.drawable.ic_dislike,"dislike",null)
.setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle().
setShowActionsInCompactView(1,2,3))
.build();
mNotificationManagerCompat.notify(1,channel);
}
gettext()method is working fine but it work on first when any clicked event is happen if song play oncomplete and next song is not get text value
I am assuming that you are playing songs from an Activity but this will also work for a service.
Put this in your activity or service
private final BroadcastReceiver receiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals("com.mypackage.ACTION_PAUSE_MUSIC")){
//Do whatever you want. Ex. Pause
}
//Similarly this can be done for all actions
}};
Make your show notification method like this
public void shownotification(){
Bitmap largeImage = BitmapFactory.decodeResource(getResources(),R.drawable.dog);
Intent pauseIntent = new Intent("com.mypackage.ACTION_PAUSE_MUSIC");
PendingIntent pausePendingIntent = PendingIntent.getBroadcast(this, 1, pauseIntent, 0);
// Similarly you can create an intent and pending intent pair for each action you want just change the string in intent constructor
Notification channel = new NotificationCompat.Builder(getApplicationContext(),CHANNEL_ID_1)
.setSmallIcon(R.drawable.ic_music)
.setContentTitle(notificationTitleText
)
.setContentText(notificationDescText)
.setLargeIcon(largeImage)
.addAction(R.drawable.ic_like,"like",null)
.addAction(R.drawable.ic_prev,"prev",null)
.addAction(R.drawable.ic_pause,"pause",pausePendingIntent) //like this attach every action with respective pending intent
.addAction(R.drawable.ic_next,"next",null)
.addAction(R.drawable.ic_dislike,"dislike",null)
.setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
.setShowActionsInCompactView(1,2,3))
.build();
mNotificationManagerCompat.notify(1,channel);}
I want to add one more thing to #Kumar Manas answer
i.e We need to register reciever that is being created in activity.
private final BroadcastReceiver receiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals("com.mypackage.ACTION_PAUSE_MUSIC")){
//Do whatever you want. Ex. Pause
}
//Similarly this can be done for all actions
}};
To register your Reciever add these lines in onCreate()
IntentFilter intentFilter=new IntentFilter();
intentFilter.addAction("com.mypackage.ACTION_PAUSE_MUSIC");
registerReceiver(receiver,intentFilter);
Note: You can add as many actions you want
You may get your answer by following this tutorial "Android Music Player Controls on Lock Screen and Notifications"

Android Music Player Notification with Progress Bar

I'm developing music player notification with progress bar . Somehow I managed to show progress with Handler but now the problem is after some time whole android system freezes. And then rebooting the system is only a solution.
I'm new in android and this is my first app, please help me to complete my first app. I will be very thankful to you.
Here is Screenshot of Music Player Notification with Progress Bar
I've attached screenshot of notification and here is my code. These codes are running in media player foreground service
Some global variables:
private static RemoteViews views;
private static RemoteViews bigViews;
private static Notification status;
private static final int NOTIFICATION_ID = 101;
public Handler mSeekbarUpdateHandler= new Handler();
This is Runnable code:
public Runnable mUpdateseekbar=new Runnable() {
#Override
public void run() {
if(mediaPlayer != null) {
bigViews.setProgressBar(R.id.progressBar, mediaPlayer.getDuration(), mediaPlayer.getCurrentPosition(), false);
bigViews.setTextViewText(R.id.time_start, timeConvert(mediaPlayer.getCurrentPosition()));
}
startForeground(NOTIFICATION_ID, status);
mSeekbarUpdateHandler.postDelayed(this,1000);
}};
Now calling handler:
#Override
public void onPlay() {
super.onPlay();
resumeMedia();
buildNotification(PlaybackStatus.PLAYING);
mSeekbarUpdateHandler.postDelayed(mUpdateseekbar,0);
//also calling this Handler from method onSkipToNext() and previous. it means when changing song also calling Handler each time.
Finally build notification code:
private void buildNotification(PlaybackStatus playbackStatus)
{
//This section containing long code which works fine so no need to make post longer.
}
when running this code after few minute system becomes slow and finally freeze.
After removing Handler no problem occurs in notification but my progress bar not updating.
}
I have successfully solved this issue by every time Re-building whole notification in the Runnable ...
I have replaced above Runnable code with the following code...
public Runnable mUpdateseekbar = new Runnable() {
#Override
public void run() {
if (mediaPlayer.isPlaying()) {
buildNotification(PlaybackStatus.PLAYING);
}
mSeekbarUpdateHandler.postDelayed(this, 1000);
}
};
And here's the buildNotification method..
private void buildNotification(PlaybackStatus playbackStatus) {
RemoteViews views;
RemoteViews bigViews;
Notification status;
try {
int notificationAction = android.R.drawable.ic_media_pause;
PendingIntent play_pauseAction = null;
if (playbackStatus == PlaybackStatus.PLAYING) {
notificationAction = R.drawable.noty_pause;
play_pauseAction = playbackAction(1);
} else if (playbackStatus == PlaybackStatus.PAUSED) {
notificationAction = R.drawable.noty_play;
play_pauseAction = playbackAction(0);
}
views = new RemoteViews(getPackageName(),
R.layout.status_bar);
bigViews = new RemoteViews(getPackageName(),
R.layout.status_bar_expanded);
views.setImageViewBitmap(R.id.status_bar_album_art,
largeIcon);
bigViews.setImageViewBitmap(R.id.status_bar_album_art,
largeIcon);
views.setImageViewResource(R.id.status_bar_playPause,
notificationAction);
bigViews.setImageViewResource(R.id.status_bar_play,
notificationAction);
bigViews.setProgressBar(R.id.progressBar, mediaPlayer.getDuration(), mediaPlayer.getCurrentPosition(), false);
views.setTextViewText(R.id.status_bar_track_name, activeAudio.getTitle());
bigViews.setTextViewText(R.id.status_bar_track_name, activeAudio.getTitle());
views.setTextViewText(R.id.status_bar_artist_name, activeAudio.getAlbum() + "-" + activeAudio.getArtist());
bigViews.setTextViewText(R.id.status_bar_artist_name, activeAudio.getAlbum() + "-" + activeAudio.getArtist());
views.setTextViewText(R.id.status_bar_metadata, displayMeta);
bigViews.setTextViewText(R.id.status_bar_album_name, displayMeta);
bigViews.setTextViewText(R.id.track_num, (audioIndex + 1) + "/" + audioList.size());
bigViews.setTextViewText(R.id.end_time, timeConvert(mediaPlayer.getDuration()));
bigViews.setTextViewText(R.id.time_start, timeConvert(mediaPlayer.getCurrentPosition()));
views.setOnClickPendingIntent(R.id.status_bar_playPause, play_pauseAction);
bigViews.setOnClickPendingIntent(R.id.status_bar_play, play_pauseAction);
views.setOnClickPendingIntent(R.id.status_bar_next, playbackAction(2));
bigViews.setOnClickPendingIntent(R.id.status_bar_next, playbackAction(2));
views.setOnClickPendingIntent(R.id.status_bar_previous, playbackAction(3));
bigViews.setOnClickPendingIntent(R.id.status_bar_prev, playbackAction(3));
bigViews.setOnClickPendingIntent(R.id.status_bar_ff, playbackAction(5));
bigViews.setOnClickPendingIntent(R.id.status_bar_rev, playbackAction(6));
bigViews.setOnClickPendingIntent(R.id.status_bar_collapse, playbackAction(4));
views.setOnClickPendingIntent(R.id.status_stop,playbackAction(4));
status = new Notification.Builder(this).build();
status.contentView = views;
status.bigContentView = bigViews;
status.flags = Notification.FLAG_ONGOING_EVENT;
status.visibility = Notification.VISIBILITY_PUBLIC;
status.tickerText = activeAudio.getTitle();
if (playbackStatus==PlaybackStatus.PLAYING) {
status.icon = R.drawable.notyskeep;
} else {
status.icon = R.drawable.noty_small_blue;
}
status.priority = Notification.PRIORITY_MAX;
status.contentIntent = playbackAction(8);
startForeground(NOTIFICATION_ID, status);
} catch (Throwable e) {
Toast.makeText(getApplicationContext(), "Exception raised:" + e, Toast.LENGTH_LONG).show();
}
}

Get Android Notification To Appear As Banner

I've looked fairly extensively across a wide range of terminology ("banner", "pop down", "notification type") and I can't seem to find clarity on what I 'think' is a very common issue. So if there is a very obvious solution I missed due to my lack of terminology please advice.
The problem is this:
I want an Android notification to appear as a "banner" that drops down from the top of the screen (if banner is the wrong word for this please advise). I went through the Docs and didn't seem to across a setting that toggles this behaviour. Here is an example of what I would like:
I have the notification working but it currently only showing up inside the drawer. It's not popping down from the drawer (which is what I want).
Here is my code, if you can advise how I can make it also appear as a banner I would greatly appreciate it:
public void createNotification(Context context, Bundle extras)
{
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String appName = getAppName(this);
Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.putExtra("pushBundle", extras);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
int defaults = Notification.DEFAULT_ALL;
if (extras.getString("defaults") != null) {
try {
defaults = Integer.parseInt(extras.getString("defaults"));
} catch (NumberFormatException e) {}
}
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setDefaults(defaults)
.setSmallIcon(context.getApplicationInfo().icon)
.setWhen(System.currentTimeMillis())
.setContentTitle("NotificationTitle")
.setTicker(extras.getString("title"))
.setContentIntent(contentIntent)
.setAutoCancel(true);
String messageJson = extras.getString("data");
JSONObject parsed;
String message = null;
try {
parsed = new JSONObject(messageJson);
message = parsed.getString("message");
} catch (JSONException e) {
e.printStackTrace();
}
if (message != null) {
mBuilder.setContentText(message);
} else {
mBuilder.setContentText("Notification");
}
String msgcnt = extras.getString("msgcnt");
if (msgcnt != null) {
mBuilder.setNumber(Integer.parseInt(msgcnt));
}
int notId = 0;
try {
notId = Integer.parseInt(extras.getString("notId"));
}
catch(NumberFormatException e) {
Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage());
}
catch(Exception e) {
Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage());
}
mNotificationManager.notify((String) appName, notId, mBuilder.build());
}
See: http://developer.android.com/design/patterns/notifications.html
You want a Heads-Up Notifications. This requires you to set the priority with the Notifications Builder (.setPriority) to high or max.
http://developer.android.com/design/patterns/notifications.html#correctly_set_and_manage_notification_priority
The app in background basically doesn't call onMessageReceived() method.
Only when notification doesn't have notification key, the app in background call onMessageReceived() method.
So, do not use notification key.
{
"to": "/topics/notice",
"notification": {
"title": "title",
"body": "body"
},
"data": {
"url": "https://your-url.dev"
}
}
only use data key.
{
"to": "/topics/notice",
"data": {
"title": "title",
"body": "body"
"url": "https://your-url.dev"
}
}
And set priority to max.
notificationBuilder.setContentTitle(title)
// ...
.setPriority(NotificationCompat.PRIORITY_MAX)
// ...
;
Then, you'll archive what you want.
Orion Granatir is right.
For Xamarin.Android developers, here is the code:
//Create the notification
var notification = new Notification(Resource.Drawable.icon, title);
//Auto-cancel will remove the notification once the user touches it
notification.Flags = NotificationFlags.AutoCancel;
notification.Sound = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
notification.Defaults = NotificationDefaults.Vibrate | NotificationDefaults.Lights;
notification.BigContentView = new Android.Widget.RemoteViews(AppSettings.Instance.PackageName, Resource.Layout.notification_template_big_media);
notification.LargeIcon = BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon);
notification.Priority = (int)Android.App.NotificationPriority.Max;//A notification that is at least Notification.PriorityHigh is more likely to be presented as a heads-up notification.
You basically need to understand how WindowManager works.
You get the
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
then you want to get the root view and use the method addView(view, params) if you want to add a view.
Take a look at this cool article, which might help your use case.

How to launch specific activity from GooglePlayGames invitation

I'm trying to create a new android application that is comprised of multiple mini-games. The launcher activity extends BaseGameActivity and has a sign-in button and a ListView containing all the possible games that can be played.
Inside of a mini-game activity (also extends BaseGameActivity), how can I get it to create a notification which will launch a specific Activity? Currently, when I call invitePlayersToGame, the invitation that gets sent is for the full application (Mini-Games) and not the individual game (specific dice game).
public void invitePlayersToGame(View pView) {
Intent intent = Games.RealTimeMultiplayer.getSelectOpponentsIntent(getApiClient(), 1, 1);
intent.putExtra("gameName", "Patman Yahtzee");
startActivityForResult(intent, RC_SELECT_PLAYERS);
}
Is there a way to get the notification to generate with a specific message? Is there a way to get notification to open directly to the mini-game activity without going to the main launcher activity first?
Any help is appreciated. Thanks!
You can send sendReliableMessage for method handshaking.
First enter a room (quickgame or send invite).
public void openInvitationIntent() {
// launch the player selection screen
// minimum: 1 other player; maximum: 1 other players
Intent intent = Games.RealTimeMultiplayer.getSelectOpponentsIntent(mGoogleApiClient, 1, 1);
startActivityForResult(intent, RC_SELECT_PLAYERS);
}
onConnected:
#Override
public void onConnected(Bundle connectionHint) {
// QuickGame
if (mGameMode == 1) {
Log.d(TAG, "onConnected() called. Sign in successful!");
Log.d(TAG, "Sign-in succeeded.");
startQuickGame();
// register listener so we are notified if we receive an invitation to play
// while we are in the game
if (connectionHint != null) {
Log.d(TAG, "onConnected: connection hint provided. Checking for invite.");
Invitation inv = connectionHint.getParcelable(Multiplayer.EXTRA_INVITATION);
if (inv != null && inv.getInvitationId() != null) {
// retrieve and cache the invitation ID
Log.d(TAG, "onConnected: connection hint has a room invite!");
acceptInviteToRoom(inv.getInvitationId());
return;
}
}
}
// Send request
else if (mGameMode == 0) {
// request code for the "select players" UI
// can be any number as long as it's unique
invitationInbox();
}
// request accepted
else {
mIncomingInvitationId = getIntent().getExtras().getString(AppConstants.RC_INVITATION_ID);
RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
roomConfigBuilder.setInvitationIdToAccept(mIncomingInvitationId);
Games.RealTimeMultiplayer.join(mGoogleApiClient, roomConfigBuilder.build());
// prevent screen from sleeping during handshake
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}
After this, you can send model class (includes what you need).
private void broadcastMessage(ModelGameRecievedMessage broadcastedMessage, boolean isFinal) {
try {
if ( mParticipants != null && broadcastedMessage != null) {
byte[] bytes = Utils.serialize(broadcastedMessage);
// Send to every other participant.
for (Participant p : mParticipants) {
if (p.getParticipantId().equals(mMyId)) {
continue;
}
if (p.getStatus() != Participant.STATUS_JOINED) {
continue;
}
if (mRoomId != null) {
if (isFinal) {
// final score notification must be sent via reliable broadcastedMessage
Games.RealTimeMultiplayer.sendReliableMessage(mGoogleApiClient, null, bytes,
mRoomId, p.getParticipantId());
} else {
// it's an interim score notification, so we can use unreliable
Games.RealTimeMultiplayer.sendUnreliableMessage(mGoogleApiClient, bytes,
mRoomId, p.getParticipantId());
}
}
}
Logy.l("broadcastedMessage.getMessageTypeId(); " + broadcastedMessage.getMessageTypeId());
Logy.l("broadcastedMessage.getMessage(); " + broadcastedMessage.getMessage());
}
} catch (IOException e) {
e.printStackTrace();
}
}
finally you can reach the data on other devices:
#Override
public void onRealTimeMessageReceived(RealTimeMessage rtm) {
byte[] bufy = rtm.getMessageData();
ModelGameRecievedMessage recievedMessage = null;
try {
recievedMessage = (ModelGameRecievedMessage) Utils.deserialize(bufy);
Logy.l("recievedMessage.getMessageTypeId(); " + recievedMessage.getMessageTypeId());
Logy.l("recievedMessage.getMessage(); " + recievedMessage.getMessage());
} catch (Exception e) {
Logy.e("Exception onRealTimeMessageReceived deserialize: " + e);
}
switch (recievedMessage.getMessageTypeId()) {
case AppConstants.RC_MULTI_START_TIMEMILIS_MULTIPLAYER:
....

Categories

Resources