|
|
@@ -23,6 +23,8 @@ import android.support.v7.app.AlertDialog;
|
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
|
|
|
+import com.usai.redant.apexdrivers.detail.DetailActivity;
|
|
|
+import com.usai.redant.apexdrivers.home.HomeFragment;
|
|
|
import com.usai.redant.apexdrivers.network.Network;
|
|
|
import com.usai.redant.apexdrivers.receiver.ApexDriverAlarmReceiver;
|
|
|
import com.usai.redant.apexdrivers.utils.OperationQueue;
|
|
|
@@ -33,6 +35,8 @@ import org.json.JSONObject;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
|
+import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
|
|
+
|
|
|
public class ApexDriverApplication extends Application {
|
|
|
|
|
|
public final static String secretKey = "usai";
|
|
|
@@ -543,8 +547,12 @@ public class ApexDriverApplication extends Application {
|
|
|
break;
|
|
|
case BackgroundReportTypeAllow: {
|
|
|
|
|
|
- String location = null;
|
|
|
- reportLocationForOrder(location,orderId);
|
|
|
+ Location location = getCurrentLocation();
|
|
|
+ String latlon = "-999,-999";
|
|
|
+ if (location != null) {
|
|
|
+ latlon = location.getLatitude() + "," + location.getLongitude();
|
|
|
+ }
|
|
|
+ reportLocationForOrder(latlon,orderId);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
@@ -552,13 +560,107 @@ public class ApexDriverApplication extends Application {
|
|
|
|
|
|
public void receiveNotification(JSONObject notification) {
|
|
|
|
|
|
+ if (notification != null) {
|
|
|
+
|
|
|
+ JSONObject aps = notification.optJSONObject("aps");
|
|
|
+ if (aps != null) {
|
|
|
+
|
|
|
+ int report_location = aps.optInt("report-location",0);
|
|
|
+ final String orderID = aps.optString("order-id");
|
|
|
+
|
|
|
+ if (report_location != 0) {
|
|
|
+
|
|
|
+ reportLocationForOrder(orderID);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ int is_order = aps.optInt("is-order",0);
|
|
|
+ if (is_order != 0) {
|
|
|
+
|
|
|
+ sendBroadcast(new Intent(HomeFragment.HomeReloadBroadcastAction));
|
|
|
+
|
|
|
+ boolean isActive = true; // 程序是否在前台
|
|
|
+ if (isActive) {
|
|
|
+ // 弹窗提示
|
|
|
+
|
|
|
+ final int orderType = aps.optInt("order-type");
|
|
|
+ final String orderType2 = aps.optString("order-type2");
|
|
|
+ final String statusNo = aps.optString("status-no");
|
|
|
+ int required = aps.optInt("required");
|
|
|
+ String msg = aps.optString("message");
|
|
|
+ if (TextUtils.isEmpty(msg)) {
|
|
|
+ msg = orderID + " status changed,view detail?";
|
|
|
+ }
|
|
|
+
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
|
|
|
+ builder.setTitle("Message");
|
|
|
+ builder.setMessage(msg);
|
|
|
+ if (required == 0) {
|
|
|
+ builder.setNegativeButton("Cancel",null);
|
|
|
+ }
|
|
|
+ builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ showDetail(orderID,orderType,orderType2,statusNo);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.show();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 发通知
|
|
|
+ popLocalNotification(notification);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- public void popLocalNotification(String title, String msg) {
|
|
|
+ public void popLocalNotification(JSONObject notification) {
|
|
|
+
|
|
|
+ if (notification == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject aps = notification.optJSONObject("aps");
|
|
|
+ if (aps == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int id = aps.optInt("id");
|
|
|
+ JSONObject alert = aps.optJSONObject("alert");
|
|
|
+ String title = null,msg = null;
|
|
|
+ if (alert != null) {
|
|
|
|
|
|
+ title = alert.optString("title");
|
|
|
+ msg = alert.optString("body");
|
|
|
+ }
|
|
|
|
|
|
- Intent intent = new Intent();
|
|
|
- PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
|
|
|
+ if (TextUtils.isEmpty(title) || TextUtils.isEmpty(msg)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+// final String orderID = aps.optString("order-id");
|
|
|
+// final int orderType = aps.optInt("order-type");
|
|
|
+// final String orderType2 = aps.optString("order-type2");
|
|
|
+// final String statusNo = aps.optString("status-no");
|
|
|
+//
|
|
|
+// Intent intent = DetailActivity.build(getApplicationContext(),orderID,orderType,orderType2,statusNo);
|
|
|
+// intent.putExtra("goHome",true);
|
|
|
+ Intent intent = new Intent(getApplicationContext(),MainActivity.class);
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
+ intent.putExtra("aps",aps.toString());
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * requestCode: 需要保证不同,否则id不通的intent取到的extra也是同一个
|
|
|
+ * */
|
|
|
+ int requestCode = id;
|
|
|
+ PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), requestCode, intent,FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
//1.获取系统通知的管理者
|
|
|
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
|
@@ -571,22 +673,28 @@ public class ApexDriverApplication extends Application {
|
|
|
nm.createNotificationChannel(channel);
|
|
|
|
|
|
noti = new NotificationCompat.Builder(this, CHANNEL_ID)
|
|
|
- .setContentTitle("我是大的标题")
|
|
|
- .setContentText("我是内容")
|
|
|
+ .setContentTitle(title)
|
|
|
+ .setContentText(msg)
|
|
|
.setSmallIcon(R.drawable.icon_50)
|
|
|
.setContentIntent(contentIntent)
|
|
|
.build();
|
|
|
} else {
|
|
|
|
|
|
noti = new Notification.Builder(this)
|
|
|
- .setContentTitle("我是大的标题")
|
|
|
- .setContentText("我是内容")
|
|
|
+ .setContentTitle(title)
|
|
|
+ .setContentText(msg)
|
|
|
.setSmallIcon(R.drawable.icon_50)
|
|
|
.setContentIntent(contentIntent)
|
|
|
.build();
|
|
|
|
|
|
}
|
|
|
|
|
|
- nm.notify(1, noti);
|
|
|
+ nm.notify(id, noti);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void showDetail(String orderId, int type, String type2, String statusNo) {
|
|
|
+
|
|
|
+ Intent intent = DetailActivity.build(getApplicationContext(),orderId,type,type2,statusNo);
|
|
|
+ startActivity(intent);
|
|
|
}
|
|
|
}
|