Skip to content

Instantly share code, notes, and snippets.

@codeInBit
Created February 9, 2017 08:05
Show Gist options
  • Save codeInBit/17850be458a6898928c3c2c5fe7ba8d6 to your computer and use it in GitHub Desktop.
Save codeInBit/17850be458a6898928c3c2c5fe7ba8d6 to your computer and use it in GitHub Desktop.
@Override
protected void onResume() { //will be called in any cases
super.onResume();
// getIntent() should always return the most recent intent hence a viable candidate for
// displaying messages from notifications
//Make provisions to receive the intent and parse the expected response in a desired format
if(getIntent().hasExtra(PushIt.TYPE)){
String notification_type= getIntent().getStringExtra(PushIt.TYPE);//detect message type
String payload= getIntent().getStringExtra(PushIt.PAYLOAD);//extract message payload
String time= getIntent().getStringExtra(PushIt.TIME_RECEIVED);//extract receipt time
if(notification_type.equalsIgnoreCase(PushIt.TYPE_TEXT)){
//TOAST THE TEXT NOTIFICATION
Toast.makeText(this,payload+"\n Received: "+time,Toast.LENGTH_LONG).show();
} else if (notification_type.equalsIgnoreCase(PushIt.TYPE_IMAGE)){
//SET AN IMAGEVIEW TO DISPLAY THE RECEIVED BITMAP
Bitmap bitmap= PushIt.loadImage(payload);
imageView.setImageBitmap(bitmap);
}else if (notification_type.equalsIgnoreCase(PushIt.TYPE_AUDIO)){
//LOAD THE AUDIO AND START PLAYING IT
PushIt.loadAudio(payload);
}else if (notification_type.equalsIgnoreCase(PushIt.TYPE_VIDEO)){
imageView.setVisibility(View.INVISIBLE);
videoView.setVisibility(View.VISIBLE);
//LOAD VIDEO INTO VIDEOVIEW AND PLAY;
videoView.setVideoPath(payload);// viable candidate for a try catch ;)
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
videoView.start();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment