404000b806ff1e79da0d56233768cc0085625fe1.svn-base 7.9 KB

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