正在查看: WeatherSense v1.8.9 应用的 MyCustomMessageService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: WeatherSense v1.8.9 应用的 MyCustomMessageService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.emax.weather.umeng;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import com.emax.weahter.R;
import com.emax.weather.base.RxBus;
import com.emax.weather.bean.AlarmEventType;
import com.emax.weather.bean.RxBusEvent;
import com.emax.weather.ui.activity.MainActivity;
import com.ezon.health.utils_lib.SharedPre;
import com.ezon.health.utils_lib.SharedPreUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.umeng.message.PushAgent;
import com.umeng.message.UTrack;
import com.umeng.message.UmengMessageHandler;
import com.umeng.message.UmengMessageService;
import com.umeng.message.entity.UMessage;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;
public class MyCustomMessageService extends UmengMessageService {
private static final String TAG = "MyCustomMessageService";
public void onMessage(Context context, Intent intent) {
Log.i(TAG, "lyq onMessage");
try {
String stringExtra = intent.getStringExtra("body");
UMessage uMessage = new UMessage(new JSONObject(stringExtra));
Log.i(TAG, "lyq 非离线 onMessage message.display_type:" + uMessage.display_type + " body:" + stringExtra);
if ("notification".equals(uMessage.display_type)) {
handleNotificationMessage(uMessage);
String string = new JSONObject(uMessage.extra).getString("weather_content");
if (!TextUtils.isEmpty(string)) {
dealData(string);
RxBusEvent rxBusEvent = new RxBusEvent();
rxBusEvent.setUpdateTheData(MainActivity.UPDATE_NOTIFICATION);
RxBus.getInstance().post(rxBusEvent);
}
} else if ("custom".equals(uMessage.display_type)) {
handleCustomMessage(uMessage);
}
} catch (Exception e) {
Log.i(TAG, "lyq onMessage message exception");
e.printStackTrace();
}
}
private void dealData(String str) {
List arrayList;
try {
System.out.println("lyq alarm 收到报警数据 str:" + str);
AlarmEventType alarmEventType = (AlarmEventType) new Gson().fromJson(str, AlarmEventType.class);
alarmEventType.setOffLine(false);
String string = SharedPreUtils.getString(this, SharedPre.Alarm.ALARM_INFO);
if (!TextUtils.isEmpty(string)) {
arrayList = (List) new Gson().fromJson(string, new TypeToken<ArrayList<AlarmEventType>>() {
}.getType());
if (arrayList == null) {
arrayList = new ArrayList();
arrayList.add(alarmEventType);
System.out.println("lyq alarm 本地报警数据不为空 解析出来却为空 add");
} else {
int i = -1;
for (int i2 = 0; i2 < arrayList.size(); i2++) {
if (((AlarmEventType) arrayList.get(i2)).getEventData().getType() == alarmEventType.getEventData().getType()) {
i = i2;
}
}
if (i != -1) {
arrayList.set(i, alarmEventType);
} else {
arrayList.add(alarmEventType);
}
System.out.println("lyq alarm 本地报警数据不为空 解析出来不为空 isSame(不为-1说明重复):" + i);
}
} else {
arrayList = new ArrayList();
arrayList.add(alarmEventType);
System.out.println("lyq alarm 本地报警数据为空 add");
}
if (arrayList != null && arrayList.size() > 0) {
String json = new Gson().toJson(arrayList);
System.out.println("lyq alarm 保存至本地的报警数据:" + json);
SharedPreUtils.putString(this, SharedPre.Alarm.ALARM_INFO, json);
return;
}
SharedPreUtils.putString(this, SharedPre.Alarm.ALARM_INFO, "");
} catch (Exception e) {
e.printStackTrace();
}
}
private void handleCustomMessage(UMessage message) {
Log.i(TAG, "handleCustomMessage: " + message.getRaw().toString());
}
private void handleNotificationMessage(UMessage msg) {
Notification.Builder builder;
NotificationManager notificationManager = (NotificationManager) getSystemService("notification");
if (Build.VERSION.SDK_INT >= 26) {
String notificationChannelName = PushAgent.getInstance(this).getNotificationChannelName();
if (notificationManager.getNotificationChannel("upush_default") == null) {
notificationManager.createNotificationChannel(new NotificationChannel("upush_default", notificationChannelName, 3));
}
builder = new Notification.Builder(this, "upush_default");
} else {
builder = new Notification.Builder(this);
}
builder.setContentTitle(msg.title).setContentText(msg.text).setTicker(msg.ticker).setWhen(System.currentTimeMillis()).setSmallIcon(R.drawable.app_logo).setAutoCancel(true);
Notification notification = builder.getNotification();
PendingIntent clickPendingIntent = getClickPendingIntent(this, msg);
notification.deleteIntent = getDismissPendingIntent(this, msg);
notification.contentIntent = clickPendingIntent;
notificationManager.notify((int) SystemClock.elapsedRealtime(), notification);
UTrack.getInstance().trackMsgShow(msg, notification);
}
public PendingIntent getClickPendingIntent(Context context, UMessage msg) {
Intent intent = new Intent(context, (Class<?>) MainActivity.class);
intent.setPackage(context.getPackageName());
intent.setFlags(268435456);
intent.putExtra("body", msg.getRaw().toString());
return PendingIntent.getActivity(context, (int) System.currentTimeMillis(), intent, Build.VERSION.SDK_INT >= 23 ? 335544320 : 268435456);
}
public PendingIntent getDismissPendingIntent(Context context, UMessage msg) {
return new UmengMessageHandler().getDismissPendingIntent(context, msg);
}
}