a76b75851c37dc5019137dd142eb9b68cb67fa9a.svn-base 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  50. in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
  51. context.startActivity(in);
  52. }
  53. } catch (Throwable throwable) {
  54. }
  55. }
  56. @Override
  57. public void onMultiActionClicked(Context context, Intent intent) {
  58. Log.e(TAG, "[onMultiActionClicked] 用户点击了通知栏按钮");
  59. String nActionExtra = intent.getExtras().getString(JPushInterface.EXTRA_NOTIFICATION_ACTION_EXTRA);
  60. //开发者根据不同 Action 携带的 extra 字段来分配不同的动作。
  61. if (nActionExtra == null) {
  62. Log.d(TAG, "ACTION_NOTIFICATION_CLICK_ACTION nActionExtra is null");
  63. return;
  64. }
  65. if (nActionExtra.equals("my_extra1")) {
  66. Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮一");
  67. } else if (nActionExtra.equals("my_extra2")) {
  68. Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮二");
  69. } else if (nActionExtra.equals("my_extra3")) {
  70. Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮三");
  71. } else {
  72. Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮未定义");
  73. }
  74. }
  75. private SoundPoolHelper soundPoolHelper;
  76. @Override
  77. public void onNotifyMessageArrived(Context context, NotificationMessage message) {
  78. Log.e(TAG, "[onNotifyMessageArrived] " + message);
  79. EventBus.getDefault().postSticky(new ReviewEvent(message.notificationContent.equals("您有一个需复核请立即处理") ? 1
  80. : (message.notificationContent.equals("您有一只预警疫苗") ? 2 : 0)));//刷新
  81. if (message.notificationContent.equals("您有一只预警疫苗")) {
  82. try {
  83. MediaPlayer mMediaPlayer;
  84. 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;
  92. mMediaPlayer = MediaPlayer.create(context, R.raw.niyouyigexyfyhe);
  93. mMediaPlayer.start();
  94. } catch (IllegalStateException e) {
  95. e.printStackTrace();
  96. }
  97. } else if (message.notificationContent.equals("您申请复核的疫苗有了新回复,请及时查看")) {
  98. try {
  99. MediaPlayer mMediaPlayer;
  100. mMediaPlayer = MediaPlayer.create(context, R.raw.youhuifu);
  101. mMediaPlayer.start();
  102. } catch (IllegalStateException e) {
  103. e.printStackTrace();
  104. }
  105. }
  106. Vibrator vib = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);
  107. vib.vibrate(new long[]{100, 200}, -1);
  108. }
  109. @Override
  110. public void onNotifyMessageDismiss(Context context, NotificationMessage message) {
  111. Log.e(TAG, "[onNotifyMessageDismiss] " + message);
  112. }
  113. @Override
  114. public void onRegister(Context context, String registrationId) {
  115. Log.e(TAG, "[onRegister] " + registrationId);
  116. if (registrationId != null && !registrationId.equals("")) {
  117. SPUtils.put("pushToken", registrationId);
  118. }
  119. }
  120. @Override
  121. public void onConnected(Context context, boolean isConnected) {
  122. Log.e(TAG, "[onConnected] " + isConnected);
  123. }
  124. @Override
  125. public void onCommandResult(Context context, CmdMessage cmdMessage) {
  126. Log.e(TAG, "[onCommandResult] " + cmdMessage);
  127. }
  128. @Override
  129. public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
  130. TagAliasOperatorHelper.getInstance().onTagOperatorResult(context, jPushMessage);
  131. super.onTagOperatorResult(context, jPushMessage);
  132. }
  133. @Override
  134. public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage) {
  135. TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context, jPushMessage);
  136. super.onCheckTagOperatorResult(context, jPushMessage);
  137. }
  138. @Override
  139. public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
  140. TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context, jPushMessage);
  141. super.onAliasOperatorResult(context, jPushMessage);
  142. }
  143. @Override
  144. public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
  145. TagAliasOperatorHelper.getInstance().onMobileNumberOperatorResult(context, jPushMessage);
  146. super.onMobileNumberOperatorResult(context, jPushMessage);
  147. }
  148. //send msg to MainActivity
  149. private void processCustomMessage(Context context, CustomMessage customMessage) {
  150. /*if (MainActivity.isForeground) {
  151. String message = customMessage.message;
  152. String extras = customMessage.extra;
  153. Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
  154. msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);
  155. if (!ExampleUtil.isEmpty(extras)) {
  156. try {
  157. JSONObject extraJson = new JSONObject(extras);
  158. if (extraJson.length() > 0) {
  159. msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras);
  160. }
  161. } catch (JSONException e) {
  162. }
  163. }
  164. LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
  165. }*/
  166. }
  167. }