e38e1d33da3ba8c6b5460676dbca020cdde48406.svn-base 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. package eVVM.apk.jpush;
  2. import android.app.Service;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.media.MediaPlayer;
  6. import android.os.Bundle;
  7. import android.os.Vibrator;
  8. import android.util.Log;
  9. import org.greenrobot.eventbus.EventBus;
  10. import org.json.JSONObject;
  11. import cn.jpush.android.api.CmdMessage;
  12. import cn.jpush.android.api.CustomMessage;
  13. import cn.jpush.android.api.JPushInterface;
  14. import cn.jpush.android.api.JPushMessage;
  15. import cn.jpush.android.api.NotificationMessage;
  16. import cn.jpush.android.service.JPushMessageReceiver;
  17. import eVVM.apk.R;
  18. import eVVM.apk.helper.SPUtils;
  19. import eVVM.apk.ui.event.ReviewEvent;
  20. import eVVM.apk.ui.toreview.VnToreViewActivity;
  21. /**
  22. * Created by Android Studio.
  23. * User: zbb
  24. * Date: 2019/6/6
  25. * Describe: EvvmPushReceiver
  26. */
  27. public class EvvmPushReceiver extends JPushMessageReceiver {
  28. private static final String TAG = "PushMessageReceiver";
  29. @Override
  30. public void onMessage(Context context, CustomMessage customMessage) {
  31. Log.e(TAG, "[onMessage] " + customMessage);
  32. processCustomMessage(context, customMessage);
  33. }
  34. @Override
  35. public void onNotifyMessageOpened(Context context, NotificationMessage message) {
  36. Log.e(TAG, "[onNotifyMessageOpened] " + message);
  37. try {
  38. JSONObject extrasJson = new JSONObject(message.notificationExtras);
  39. //打开自定义的Activity
  40. if (message.notificationContent.equals("您有一个需复核请立即处理") || message.notificationContent.equals("您有一只预警疫苗")) {
  41. Intent in = new Intent(context, VnToreViewActivity.class);
  42. Bundle bundle = new Bundle();
  43. bundle.putString(JPushInterface.EXTRA_NOTIFICATION_TITLE, message.notificationTitle);
  44. bundle.putString(JPushInterface.EXTRA_ALERT, message.notificationContent);
  45. in.putExtras(bundle);
  46. in.putExtra("VnchipNumber", "" + extrasJson.getString("chipNumber"));
  47. in.putExtra("toreviewid", extrasJson.getString("reviewId"));
  48. in.putExtra("rsReviewType", message.notificationContent.equals("您有一个需复核请立即处理") ? 1
  49. : (message.notificationContent.equals("您有一只预警疫苗") ? 2 : 0));
  50. in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  51. in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
  52. context.startActivity(in);
  53. }
  54. } catch (Throwable throwable) {
  55. }
  56. }
  57. @Override
  58. public void onMultiActionClicked(Context context, Intent intent) {
  59. Log.e(TAG, "[onMultiActionClicked] 用户点击了通知栏按钮");
  60. String nActionExtra = intent.getExtras().getString(JPushInterface.EXTRA_NOTIFICATION_ACTION_EXTRA);
  61. //开发者根据不同 Action 携带的 extra 字段来分配不同的动作。
  62. if (nActionExtra == null) {
  63. Log.d(TAG, "ACTION_NOTIFICATION_CLICK_ACTION nActionExtra is null");
  64. return;
  65. }
  66. if (nActionExtra.equals("my_extra1")) {
  67. Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮一");
  68. } else if (nActionExtra.equals("my_extra2")) {
  69. Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮二");
  70. } else if (nActionExtra.equals("my_extra3")) {
  71. Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮三");
  72. } else {
  73. Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮未定义");
  74. }
  75. }
  76. //private MediaPlayer mMediaPlayer;
  77. @Override
  78. public void onNotifyMessageArrived(Context context, NotificationMessage message) {
  79. Log.e(TAG, "[onNotifyMessageArrived] " + message);
  80. EventBus.getDefault().postSticky(new ReviewEvent(message.notificationContent.equals("您有一个需复核请立即处理") ? 1
  81. : (message.notificationContent.equals("您有一只预警疫苗") ? 2 : 0)));//刷新
  82. if (message.notificationContent.equals("您有一只预警疫苗")) {
  83. try {
  84. MediaPlayer mMediaPlayer = MediaPlayer.create(context, R.raw.niyouyizhiyujing);
  85. mMediaPlayer.start();
  86. } catch (IllegalStateException e) {
  87. e.printStackTrace();
  88. }
  89. } else if (message.notificationContent.equals("您有一个需复核请立即处理")) {
  90. try {
  91. MediaPlayer mMediaPlayer = MediaPlayer.create(context, R.raw.niyouyigexyfyhe);
  92. mMediaPlayer.start();
  93. } catch (IllegalStateException e) {
  94. e.printStackTrace();
  95. }
  96. } else if (message.notificationContent.equals("您申请复核的疫苗有了新回复,请及时查看")) {
  97. try {
  98. MediaPlayer mMediaPlayer = MediaPlayer.create(context, R.raw.youhuifu);
  99. mMediaPlayer.start();
  100. } catch (IllegalStateException e) {
  101. e.printStackTrace();
  102. }
  103. }
  104. Vibrator vib = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);
  105. vib.vibrate(new long[]{100, 200}, -1);
  106. }
  107. @Override
  108. public void onNotifyMessageDismiss(Context context, NotificationMessage message) {
  109. Log.e(TAG, "[onNotifyMessageDismiss] " + message);
  110. }
  111. @Override
  112. public void onRegister(Context context, String registrationId) {
  113. Log.e(TAG, "[onRegister] " + registrationId);
  114. if (registrationId != null && !registrationId.equals("")) {
  115. SPUtils.put("pushToken", registrationId);
  116. }
  117. }
  118. @Override
  119. public void onConnected(Context context, boolean isConnected) {
  120. Log.e(TAG, "[onConnected] " + isConnected);
  121. }
  122. @Override
  123. public void onCommandResult(Context context, CmdMessage cmdMessage) {
  124. Log.e(TAG, "[onCommandResult] " + cmdMessage);
  125. }
  126. @Override
  127. public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
  128. TagAliasOperatorHelper.getInstance().onTagOperatorResult(context, jPushMessage);
  129. super.onTagOperatorResult(context, jPushMessage);
  130. }
  131. @Override
  132. public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage) {
  133. TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context, jPushMessage);
  134. super.onCheckTagOperatorResult(context, jPushMessage);
  135. }
  136. @Override
  137. public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
  138. TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context, jPushMessage);
  139. super.onAliasOperatorResult(context, jPushMessage);
  140. }
  141. @Override
  142. public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
  143. TagAliasOperatorHelper.getInstance().onMobileNumberOperatorResult(context, jPushMessage);
  144. super.onMobileNumberOperatorResult(context, jPushMessage);
  145. }
  146. //send msg to MainActivity
  147. private void processCustomMessage(Context context, CustomMessage customMessage) {
  148. /*if (MainActivity.isForeground) {
  149. String message = customMessage.message;
  150. String extras = customMessage.extra;
  151. Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
  152. msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);
  153. if (!ExampleUtil.isEmpty(extras)) {
  154. try {
  155. JSONObject extraJson = new JSONObject(extras);
  156. if (extraJson.length() > 0) {
  157. msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras);
  158. }
  159. } catch (JSONException e) {
  160. }
  161. }
  162. LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
  163. }*/
  164. }
  165. }