I bumped into this problem (the second one) a few days ago and came up with a "temporary" solution (maybe not the cleanest and coolest). Even though this question is old, somebody might have the same problem and find some value here.
Regarding your second question on how you can open and android app automatically when a push notification is received, from inside the service class just put this:
Intent dialogIntent = new Intent(this, myActivity.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent);
Keep in mind that the code from above will cut off the notification sound so it might be a good idea to check the Screen state and play some sound if it's locked:
/* Check if the device is locked, play ring tone and vibrator */
if (!(((PowerManager) getSystemService(Context.POWER_SERVICE)).isScreenOn())){
vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
Sound = MediaPlayer.create(getApplicationContext(), R.raw.sound);
try { Sound.start(); }
catch(Exception e){ Log.i("intentService", "Error Playing sound");}
vibrator.vibrate(3000);
}
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent);
Also, don't forget to release mediaplayer !! just do some research and you'll find an answer, there are different ways but one way could be to wait until the sound is played:
Sound.isPlaying()
And then release:
Sound.release()
P.S: You can set the notificationSound to null and remove the "if" condition so the ringtone will always be played (even when the screen is ON and the app is opened automatically)
setSound(null)