package eVVM.apk.jpush; import android.app.Service; import android.content.Context; import android.content.Intent; import android.media.MediaPlayer; import android.os.Bundle; import android.os.Vibrator; import android.util.Log; import org.greenrobot.eventbus.EventBus; import org.json.JSONObject; import cn.jpush.android.api.CmdMessage; import cn.jpush.android.api.CustomMessage; import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushMessage; import cn.jpush.android.api.NotificationMessage; import cn.jpush.android.service.JPushMessageReceiver; import eVVM.apk.R; import eVVM.apk.helper.SPUtils; import eVVM.apk.helper.SoundPoolHelper; import eVVM.apk.ui.event.ReviewEvent; import eVVM.apk.ui.toreview.VnToreViewActivity; /** * Created by Android Studio. * User: zbb * Date: 2019/6/6 * Describe: EvvmPushReceiver */ public class EvvmPushReceiver extends JPushMessageReceiver { private static final String TAG = "PushMessageReceiver"; @Override public void onMessage(Context context, CustomMessage customMessage) { Log.e(TAG, "[onMessage] " + customMessage); processCustomMessage(context, customMessage); } @Override public void onNotifyMessageOpened(Context context, NotificationMessage message) { Log.e(TAG, "[onNotifyMessageOpened] " + message); try { JSONObject extrasJson = new JSONObject(message.notificationExtras); //打开自定义的Activity if (message.notificationContent.equals("您有一个需复核请立即处理") || message.notificationContent.equals("您有一只预警疫苗")) { Intent in = new Intent(context, VnToreViewActivity.class); Bundle bundle = new Bundle(); bundle.putString(JPushInterface.EXTRA_NOTIFICATION_TITLE, message.notificationTitle); bundle.putString(JPushInterface.EXTRA_ALERT, message.notificationContent); in.putExtras(bundle); in.putExtra("VnchipNumber", "" + extrasJson.getString("chipNumber")); in.putExtra("toreviewid", extrasJson.getString("reviewId")); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(in); } } catch (Throwable throwable) { } } @Override public void onMultiActionClicked(Context context, Intent intent) { Log.e(TAG, "[onMultiActionClicked] 用户点击了通知栏按钮"); String nActionExtra = intent.getExtras().getString(JPushInterface.EXTRA_NOTIFICATION_ACTION_EXTRA); //开发者根据不同 Action 携带的 extra 字段来分配不同的动作。 if (nActionExtra == null) { Log.d(TAG, "ACTION_NOTIFICATION_CLICK_ACTION nActionExtra is null"); return; } if (nActionExtra.equals("my_extra1")) { Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮一"); } else if (nActionExtra.equals("my_extra2")) { Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮二"); } else if (nActionExtra.equals("my_extra3")) { Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮三"); } else { Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮未定义"); } } private SoundPoolHelper soundPoolHelper; @Override public void onNotifyMessageArrived(Context context, NotificationMessage message) { Log.e(TAG, "[onNotifyMessageArrived] " + message); EventBus.getDefault().postSticky(new ReviewEvent(message.notificationContent.equals("您有一个需复核请立即处理") ? 1 : (message.notificationContent.equals("您有一只预警疫苗") ? 2 : 0)));//刷新 if (message.notificationContent.equals("您有一只预警疫苗")) { try { MediaPlayer mMediaPlayer; mMediaPlayer = MediaPlayer.create(context, R.raw.niyouyizhiyujing); mMediaPlayer.start(); } catch (IllegalStateException e) { e.printStackTrace(); } } else if (message.notificationContent.equals("您有一个需复核请立即处理")) { try { MediaPlayer mMediaPlayer; mMediaPlayer = MediaPlayer.create(context, R.raw.niyouyigexyfyhe); mMediaPlayer.start(); } catch (IllegalStateException e) { e.printStackTrace(); } } else if (message.notificationContent.equals("您申请复核的疫苗有了新回复,请及时查看")) { try { MediaPlayer mMediaPlayer; mMediaPlayer = MediaPlayer.create(context, R.raw.youhuifu); mMediaPlayer.start(); } catch (IllegalStateException e) { e.printStackTrace(); } } Vibrator vib = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE); vib.vibrate(new long[]{100, 200}, -1); } @Override public void onNotifyMessageDismiss(Context context, NotificationMessage message) { Log.e(TAG, "[onNotifyMessageDismiss] " + message); } @Override public void onRegister(Context context, String registrationId) { Log.e(TAG, "[onRegister] " + registrationId); if (registrationId != null && !registrationId.equals("")) { SPUtils.put("pushToken", registrationId); } } @Override public void onConnected(Context context, boolean isConnected) { Log.e(TAG, "[onConnected] " + isConnected); } @Override public void onCommandResult(Context context, CmdMessage cmdMessage) { Log.e(TAG, "[onCommandResult] " + cmdMessage); } @Override public void onTagOperatorResult(Context context, JPushMessage jPushMessage) { TagAliasOperatorHelper.getInstance().onTagOperatorResult(context, jPushMessage); super.onTagOperatorResult(context, jPushMessage); } @Override public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage) { TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context, jPushMessage); super.onCheckTagOperatorResult(context, jPushMessage); } @Override public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) { TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context, jPushMessage); super.onAliasOperatorResult(context, jPushMessage); } @Override public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) { TagAliasOperatorHelper.getInstance().onMobileNumberOperatorResult(context, jPushMessage); super.onMobileNumberOperatorResult(context, jPushMessage); } //send msg to MainActivity private void processCustomMessage(Context context, CustomMessage customMessage) { /*if (MainActivity.isForeground) { String message = customMessage.message; String extras = customMessage.extra; Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION); msgIntent.putExtra(MainActivity.KEY_MESSAGE, message); if (!ExampleUtil.isEmpty(extras)) { try { JSONObject extraJson = new JSONObject(extras); if (extraJson.length() > 0) { msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras); } } catch (JSONException e) { } } LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent); }*/ } }