|
|
@@ -17,7 +17,9 @@ import android.content.SharedPreferences;
|
|
|
import android.location.Location;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
import android.os.IBinder;
|
|
|
+import android.os.Looper;
|
|
|
import android.support.v4.app.NotificationCompat;
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
import android.text.TextUtils;
|
|
|
@@ -64,6 +66,8 @@ public class ApexDriverApplication extends Application {
|
|
|
private ApexDriversBackgroundService mService;
|
|
|
private boolean mRequiredLocation = false;
|
|
|
|
|
|
+ private Activity mCurActivity;
|
|
|
+
|
|
|
|
|
|
private OperationQueue networkQueue;
|
|
|
|
|
|
@@ -90,7 +94,7 @@ public class ApexDriverApplication extends Application {
|
|
|
|
|
|
@Override
|
|
|
public void onActivityStarted(Activity activity) {
|
|
|
-
|
|
|
+ mCurActivity = activity;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -522,7 +526,7 @@ public class ApexDriverApplication extends Application {
|
|
|
break;
|
|
|
case BackgroundReportTypeAlways: {
|
|
|
|
|
|
- new AlertDialog.Builder(getApplicationContext())
|
|
|
+ new AlertDialog.Builder(mCurActivity)
|
|
|
.setTitle("Warning")
|
|
|
.setMessage("Report Location For Order:" + orderId)
|
|
|
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
|
|
@@ -558,7 +562,16 @@ public class ApexDriverApplication extends Application {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void receiveNotification(JSONObject notification) {
|
|
|
+ public void receiveNotificationOnMainThread(final JSONObject notification) {
|
|
|
+ new Handler(Looper.getMainLooper()).post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ receiveNotification(notification);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void receiveNotification(JSONObject notification) {
|
|
|
|
|
|
if (notification != null) {
|
|
|
|
|
|
@@ -592,7 +605,7 @@ public class ApexDriverApplication extends Application {
|
|
|
msg = orderID + " status changed,view detail?";
|
|
|
}
|
|
|
|
|
|
- AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(mCurActivity);
|
|
|
builder.setTitle("Message");
|
|
|
builder.setMessage(msg);
|
|
|
if (required == 0) {
|
|
|
@@ -653,7 +666,11 @@ public class ApexDriverApplication extends Application {
|
|
|
// intent.putExtra("goHome",true);
|
|
|
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
- intent.putExtra("aps",aps.toString());
|
|
|
+ intent.putExtra("aps",aps.toString()); // 程序在后台的情况下,点击通知将程序唤醒到前台时,并不能取得extra
|
|
|
+ MainActivity mainActivity = MainActivity.currentMainActivity();
|
|
|
+ if (mainActivity != null) {
|
|
|
+ mainActivity.setAPS(aps);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
@@ -689,6 +706,7 @@ public class ApexDriverApplication extends Application {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ noti.flags |= Notification.FLAG_AUTO_CANCEL;
|
|
|
nm.notify(id, noti);
|
|
|
}
|
|
|
|