不废话,需求:当接收到推送消息时,播放apk自带的声音,怎么办?
首先接入极光推送,我前几篇文章已经讲了,不会的自己去看。在MyReceiver里的public void onReceive(Context context, Intent intent)判断消息类型,然后使用MediaPlayer播放assets或者raw目录的音频文件。
if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Log.e(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
Log.e(TAG, "[MyReceiver] 接收到推送下来的通知");
int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
Log.e(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
openRawMusicS(context);
}
/**
* 打开raw目录下的音乐mp3文件
*/
private void openRawMusicS(Context context) {
// mediaPlayer1 = MediaPlayer.create(this, R.raw.please_get_close);
mediaPlayer1