Просмотр исходного кода

RAUtilsLibrary 后台服务修改完成。

Ray Zhang 7 лет назад
Родитель
Сommit
d54648d3f1

+ 1 - 1
Apex Mobile/app/src/main/AndroidManifest.xml

@@ -2,7 +2,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.usai.apex"
     android:versionCode="16"
-    android:versionName="A180612"> <!-- Copied from Google Maps Library/AndroidManifest.xml. -->
+    android:versionName="A180703"> <!-- Copied from Google Maps Library/AndroidManifest.xml. -->
     <uses-sdk
         android:minSdkVersion="14"
         android:targetSdkVersion="18" />

+ 3 - 7
Apex Mobile/app/src/main/java/com/usai/apex/ShipMap/ShipMap.java

@@ -5,15 +5,12 @@ import android.content.Context;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.graphics.Color;
-import android.location.Location;
-import android.location.LocationManager;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
 import android.support.annotation.CallSuper;
 import android.support.annotation.Nullable;
 import android.util.AttributeSet;
-import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.ImageButton;
@@ -31,7 +28,6 @@ import com.baidu.mapapi.map.MapStatusUpdateFactory;
 import com.baidu.mapapi.map.MapView;
 import com.baidu.mapapi.map.Marker;
 import com.baidu.mapapi.map.MarkerOptions;
-import com.baidu.mapapi.map.UiSettings;
 import com.baidu.mapapi.model.LatLng;
 import com.google.android.gms.maps.CameraUpdate;
 import com.google.android.gms.maps.CameraUpdateFactory;
@@ -316,7 +312,7 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
         if (showCurrent()) {
             if (current != null) {
                 try {
-                    current.put("port","Current");
+                    current.put("port","Vessel");
                 } catch (JSONException e) {
                     e.printStackTrace();
                 }
@@ -462,7 +458,7 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
 
             com.google.android.gms.maps.model.Marker marker = mGoogleMap.addMarker(options);
 
-            if (port.equals("Current")) {
+            if (port.equals("Vessel")) {
                 mCurrentGoogleMarker = marker;
             }
 
@@ -500,7 +496,7 @@ public class ShipMap extends RelativeLayout implements GoogleMap.OnMarkerClickLi
 
             Marker marker = (Marker) mBaiduMap.getMap().addOverlay(markeroption);
 
-            if (port.equals("Current")) {
+            if (port.equals("Vessel")) {
                 mCurrentBaiduMarker = marker;
             }
 

+ 11 - 0
ApexDrivers/RAUtilsLibrary/RAUtilsLibrary.iml

@@ -85,18 +85,29 @@
       <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/attr" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/extractedTypedefs" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/intermediate-jars" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/library_and_local_jars_jni" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/packaged-aidl" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/packaged-classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/packagedAssets" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/packaged_res" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/public_res" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
       <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
     </content>
     <orderEntry type="jdk" jdkName="Android API 27 Platform" jdkType="Android SDK" />
     <orderEntry type="sourceFolder" forTests="false" />

+ 11 - 7
ApexDrivers/RAUtilsLibrary/src/main/AndroidManifest.xml

@@ -20,9 +20,9 @@
     <uses-permission android:name="android.permission.READ_CONTACTS" />
     <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
     <!-- External storage for caching. -->
-    <!--<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />-->
-    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
-    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
+    <!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> -->
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
 
     <application
         android:allowBackup="true"
@@ -31,12 +31,16 @@
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
         android:theme="@style/AppTheme">
-        <!--<service-->
-            <!--android:name=".Service.RAService"-->
-            <!--android:enabled="true"-->
-            <!--android:exported="true" />-->
 
+        <!-- <service -->
+        <!-- android:name=".Service.RAService" -->
+        <!-- android:enabled="true" -->
+        <!-- android:exported="true" /> -->
 
+        <!--<receiver-->
+            <!--android:name=".Receiver.RABroadcastReceiver"-->
+            <!--android:enabled="true"-->
+            <!--android:exported="false"></receiver>-->
     </application>
 
 </manifest>

+ 17 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/Receiver/RABroadcast.java

@@ -0,0 +1,17 @@
+package com.usai.redant.rautils.Receiver;
+
+public class RABroadcast {
+    public static String EVENT_SILENCECOMMAND="REDANT.BROADCAST.EVENT_SILENCECOMMAND";
+    public static String EVENT_PUSHNOTIFICATION="REDANT.BROADCAST.EVENT_PUSHNOTIFICATION";
+    public static String EVENT_RETURN_LOCATION="REDANT.BROADCAST.EVENT_RETURN_LOCATION";
+
+    public static String ACTION_UPLOAD_ADD_TASK="REDANT.BROADCAST.ACTION_UPLOAD_ADD_TASK";
+    public static String ACTION_LOCATION_ENABLE_TRACING="REDANT.BROADCAST.ACTION_LOCATION_ENABLE_TRACING";
+    public static String ACTION_LOCATION_DISABLE_TRACING="REDANT.BROADCAST.ACTION_LOCATION_DISABLE_TRACING";
+    public static String ACTION_LOCATION_REQUEST_LOCATION="REDANT.BROADCAST.ACTION_LOCATION_REQUEST_LOCATION";
+    public static String ACTION_PUSHNOTIFICATION_CHECK="REDANT.BROADCAST.ACTION_PUSHNOTIFICATION_CHECK";
+
+    public static String ACTION_PUSHNOTIFICATION_ENABLE_CHECK="REDANT.BROADCAST.ACTION_PUSHNOTIFICATION_ENABLE_CHECK";
+    public static String ACTION_PUSHNOTIFICATION_DISABLE_CHECK="REDANT.BROADCAST.ACTION_PUSHNOTIFICATION_DISABLE_CHECK";
+
+}

+ 51 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/Receiver/RABroadcastReceiver.java

@@ -0,0 +1,51 @@
+package com.usai.redant.rautils.Receiver;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.text.TextUtils;
+
+import com.usai.redant.rautils.Utils.dbgUtil;
+
+public class RABroadcastReceiver extends BroadcastReceiver {
+
+    PushNotificationCallback notificationCallback=null;
+    private String receiverID = null;
+
+
+
+    public RABroadcastReceiver(String receiverID)
+    {
+        if(receiverID==null)
+            throw new IllegalArgumentException("receiverID can't be null");
+        this.receiverID = receiverID;
+    }
+    public void initPushNotificationCallback(PushNotificationCallback notificationCallback)
+    {
+        this.notificationCallback = notificationCallback;
+    }
+
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        dbgUtil.fileLog(context,"RABroadcastReceiver: onReceive" + intent.getAction());
+
+        if(!(intent.getStringExtra("receiverID").equals(receiverID)|| TextUtils.isEmpty(intent.getStringExtra("receiverID"))))
+            return;
+        if (RABroadcast.EVENT_PUSHNOTIFICATION.equals(intent.getAction())) {
+            if(notificationCallback!=null)
+                notificationCallback.onPushNotification(intent);
+        }
+        else if (RABroadcast.EVENT_SILENCECOMMAND.equals(intent.getAction())) {
+            if(notificationCallback!=null)
+                notificationCallback.onSilentCommand(intent);
+        }
+    }
+
+    public interface PushNotificationCallback {
+        public abstract void onPushNotification(Intent intent);
+        public abstract void onSilentCommand(Intent intent);
+    }
+
+
+}

+ 356 - 268
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/Service/RAService.java

@@ -1,6 +1,10 @@
 package com.usai.redant.rautils.Service;
 
 import android.Manifest;
+import android.app.AlarmManager;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
 import android.app.Service;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -17,54 +21,115 @@ import android.os.AsyncTask;
 import android.os.Binder;
 import android.os.Bundle;
 import android.os.IBinder;
+import android.os.SystemClock;
 import android.support.v4.app.ActivityCompat;
+import android.text.TextUtils;
 import android.util.Log;
 
+import com.usai.redant.rautils.R;
+import com.usai.redant.rautils.Receiver.RABroadcast;
 import com.usai.redant.rautils.Upload.RAUploadManager;
 import com.usai.redant.rautils.Utils.Network;
 import com.usai.redant.rautils.Utils.dbgUtil;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import java.util.ArrayList;
 
 public abstract class RAService extends Service {
 
-    public static final int DEFAULT_TIMEINTERVAL = 60*1000;
-    public static final int DEFAULT_DISTANCE = 60*50;
+    private static final String TAG = "RAService";
+
+    public static final int DEFAULT_LOCATION_TIMEINTERVAL = 60 * 1000;
+    public static final int DEFAULT_DISTANCE = 60 * 50;
+    public static final int DEFAULT_PUSHNOTIFICATION_TIMEINTERVAL = 30 * 1000;
+
     public static final int FLAG_SERVICE_NONE = 0;
     public static final int FLAG_SERVICE_LOCATION = 1 << 1;
     public static final int FLAG_SERVICE_NOTIFICATION = 1 << 2;
     public static final int FLAG_SERVICE_UPLOAD = 1 << 3;
 //    public static final int FLAG_LOCATION_SERVICE = 1<<1;
 
+    // service setup
     protected int service_flag = FLAG_SERVICE_NONE;
     private IntentFilter msgFilter = new IntentFilter();
 
-    private RAUploadManager uploadManager = null;
+    protected abstract void Setup();
+
+    // sub function upload
+    public interface ServiceUpload {
+
+    }
+    public void initServiceUpload(ServiceUpload uploadCallback) {
+        service_flag = service_flag | FLAG_SERVICE_UPLOAD;
+//        this.upload = locationCallback;
+    }
 
+    private RAUploadManager uploadManager = null;
 
+    // sub function location
     LocationListener locationListener = null;
     LocationManager locationManager = null;
-    int locationTracing_timeInterval = DEFAULT_TIMEINTERVAL ;
-    int locationTracing_distance = DEFAULT_DISTANCE ;
+    int locationTracing_timeInterval = DEFAULT_LOCATION_TIMEINTERVAL;
+    int locationTracing_distance = DEFAULT_DISTANCE;
+    //    protected abstract void onLocationChanged(Location location);
+    private ServiceLocation locationCallback = null;
 
-    private checkPushTask	m_task	= null;
+    public interface ServiceLocation {
 
-    class checkPushTask extends AsyncTask<Void, Void, Boolean>
-    {
-        int		errorcode;
-        String	content	= null;
-        Context	mcontext;
 
-        public checkPushTask(Context context)
-        {
+        public abstract  Location RequestCachedLocation();
+//        public abstract void RequestLocation_ByBroadcast(String receiverID);
+
+        public abstract void onLocationChanged(Location location);
+//        public abstract void onLogin();
+//		public abstract void onLogout();
+    }
+
+    public void initServiceLocation(ServiceLocation locationCallback) {
+        service_flag = service_flag | FLAG_SERVICE_LOCATION;
+        this.locationCallback = locationCallback;
+    }
+
+
+    // sub function Notification
+    protected String url_checknotification = null;
+    int pushcheck_timeInterval = DEFAULT_PUSHNOTIFICATION_TIMEINTERVAL;
+    protected static final int NOTIFICATION_TYPE_PUSHNOTIFICATION = 0;
+    protected static final int NOTIFICATION_TYPE_SILENCECOMMAND = 1;
+    protected boolean enable_pushNotification = false;
+
+    //    protected abstract Notification prepareNotification(JSONObject msg);
+//    protected abstract void handleSilenceMessage(JSONObject msg);
+    public interface ServicePushNotification {
+        public abstract Notification prepareNotification(JSONObject msg);
+
+        public abstract void handleSilenceMessage(JSONObject msg);
+    }
+
+    public void initServiceNotification(ServicePushNotification pushNotificationCallback, String url_checknotification) {
+        service_flag = service_flag | FLAG_SERVICE_NOTIFICATION;
+        this.url_checknotification = url_checknotification;
+        this.pushNotificationCallback = pushNotificationCallback;
+    }
+
+    private ServicePushNotification pushNotificationCallback = null;
+    private checkPushTask m_task = null;
+
+    class checkPushTask extends AsyncTask<Void, Void, Boolean> {
+        int errorcode;
+        String content = null;
+        Context mcontext;
+
+        public checkPushTask(Context context) {
             mcontext = context;
         }
 
         @Override
-        protected Boolean doInBackground(Void... params)
-        {
+        protected Boolean doInBackground(Void... params) {
             Log.d("SearchTask", "doInBackground");
-            ;
+
             if (!Network.isNetworkAvailable(getApplication()))
 
             {
@@ -72,13 +137,12 @@ public abstract class RAService extends Service {
                 return false;
             }
             String jstr = "";
-            jstr = Network.check_push(mcontext,new Bundle());
+            jstr = Network.check_push(mcontext, new Bundle(), url_checknotification);
             // if (module_name.equals("Announcements"))
             // jstr = Network.get_announcements(lastid, limit);
             // else
             // jstr = Network.get_marketnews(lastid, limit);
-            if (jstr == null || jstr.length() <= 0)
-            {
+            if (jstr == null || jstr.length() <= 0) {
                 // Log.d(TAG, "json is wrong");
 
                 errorcode = Network.RESULT_NET_ERROR;
@@ -90,157 +154,47 @@ public abstract class RAService extends Service {
         }
 
         @Override
-        protected void onPostExecute(Boolean success)
-        {
+        protected void onPostExecute(Boolean success) {
             String tag = "onPostExec";
-            Log.i( tag, "entry");
+            Log.i(tag, "entry");
             m_task = null;
-            // showProgress(false);
 
-            // switch (errorcode)
-            // {
-            // // case Network.RESULT_NET_NOTAVAILABLE:
-            // // {
-            // // Toast toast = Toast.makeText(
-            // // ApexTrackingApplication.get_instance(),
-            // // getText(R.string.msg_connection_none),
-            // // Toast.LENGTH_LONG);
-            // // toast.setGravity(Gravity.CENTER, 0, 0);
-            // // toast.show();
-            // // break;
-            // // }
-            // // case Network.RESULT_NET_ERROR:
-            // // {
-            // // Toast toast = Toast.makeText(
-            // // ApexTrackingApplication.get_instance(),
-            // // getText(R.string.msg_net_error), Toast.LENGTH_LONG);
-            // // toast.setGravity(Gravity.CENTER, 0, 0);
-            // // toast.show();
-            // // break;
-            // // }
-            // // case Network.RESULT_ERROR:
-            // // // case Network.RESULT_RESPONSE_NULL:
-            // // {
-            // // Toast toast = Toast.makeText(
-            // // ApexTrackingApplication.get_instance(),
-            // // getText(R.string.msg_net_resulterror),
-            // // Toast.LENGTH_LONG);
-            // // toast.setGravity(Gravity.CENTER, 0, 0);
-            // // toast.show();
-            // // break;
-            // // }
-            //
-            // default:
-            // break;
-            // }
-
-            if (success)
-            {
-//                JSONObject jsobj;
-//                //
-//                // array = new JSONArray(json);
-//                try
-//                {
-//                    jsobj = new JSONObject(content);
-//
-//                    String message = jsobj.getString("message");
-//                    String date = jsobj.getString("date");
-//                    String s_id = jsobj.getString("s_id");
-//                    String e_id = jsobj.getString("e_id");
-//                    int count = jsobj.getInt("count");
-//                    SQLiteDatabase db = dbUtil.OpenDB(
-//                            ApexTrackingApplication.get_instance(), null, true);
-//                    db.execSQL("insert into push_message(s_id,e_id,msgcount,message,h_time,user,create_time,read) values('"
-//                            + s_id
-//                            + "','"
-//                            + e_id
-//                            + "',"
-//                            + count
-//                            + ",'"
-//                            + message
-//                            + "','"
-//                            + date
-//                            + "','"
-//                            + ApexTrackingApplication.get_user()
-//                            + "',"
-//                            + System.currentTimeMillis() + ",0)");
-//                    dbUtil.CloseDB(db);
-//
-//                    boolean bnotify = mcontext.getSharedPreferences("setting",
-//                            0).getBoolean("notifications_new_message", true);
-//                    if (bnotify)
-//                    {
-//
-//                        boolean bsound = mcontext.getSharedPreferences(
-//                                "setting", 0).getBoolean(
-//                                "notifications_new_message_sound", true);
-//                        boolean bvibrate = mcontext.getSharedPreferences(
-//                                "setting", 0).getBoolean(
-//                                "notifications_new_message_vibrate", true);
-//                        NotificationManager nManager = (NotificationManager) mcontext
-//                                .getSystemService(Context.NOTIFICATION_SERVICE);
-//
-////						Notification notification = new Notification(
-////								R.drawable.ic_launcher,
-////								mcontext.getString(R.string.str_notification_title),
-////								System.currentTimeMillis());
-//                        Intent intent = new Intent(mcontext,
-//                                FunctionSelectActivity.class);
-//                        intent.putExtra("launcher", "notification");
-//
-//                        PendingIntent pintent = PendingIntent.getActivity(
-//                                mcontext, 0, intent,
-//                                PendingIntent.FLAG_UPDATE_CURRENT);
-//
-//
-//                        Notification.Builder builder = new Notification.Builder(mcontext);//新建Notification.Builder对象
-//                        String ntitle = "";
-//                        int number = ApexTrackingApplication.ncount++;
-//                        if (number > 1)
-//                            ntitle=number
-//                                    + " "
-//                                    + ApexTrackingApplication
-//                                    .get_instance()
-//                                    .getString(
-//                                            R.string.str_mnotification_title);
-//                        else
-//                            ntitle = ApexTrackingApplication
-//                                    .get_instance()
-//                                    .getString(
-//                                            R.string.str_notification_title);
-//
-//                        builder.setContentTitle(ntitle);//设置标题
-//                        builder.setContentText(ApexTrackingApplication
-//                                .get_instance()
-//                                .getString(
-//                                        R.string.str_notification_text)
-//                                + date);//设置内容
-//                        builder.setSmallIcon(R.drawable.ic_launcher);//设置图片
-//                        builder.setContentIntent(pintent);//执行intent
-//                        Notification notification = builder.getNotification();//将builder对象转换为普通的notifications
-//
-//                        if (bsound && bvibrate)
-//                            notification.defaults = Notification.DEFAULT_ALL;
-//                        else if (bsound)
-//                            notification.defaults = Notification.DEFAULT_SOUND
-//                                    | Notification.DEFAULT_LIGHTS;
-//                        else if (bvibrate)
-//                            notification.defaults = Notification.DEFAULT_VIBRATE
-//                                    | Notification.DEFAULT_LIGHTS;
-//                        notification.flags = Notification.FLAG_AUTO_CANCEL;
-//                        notification.number = number;
-//
-//                        nManager.notify(R.layout.activity_apex, notification);
-//                    }
-//
-//
-//
-//                }
-//                catch (JSONException e)
-//                {
-//                    // TODO Auto-generated catch block
-//                    e.printStackTrace();
-//                }
+
+            if (success) {
+                JSONObject jsobj;
+                //
+                // array = new JSONArray(json);
+                try {
+                    jsobj = new JSONObject(content);
+
+                    int count = jsobj.getInt("count");
+
+                    for (int i = 0; i < count; i++) {
+                        JSONObject msg = jsobj.getJSONObject("msg_" + i);
+                        int type = msg.getInt("type");
+                        if (type == NOTIFICATION_TYPE_SILENCECOMMAND) {
+
+                            pushNotificationCallback.handleSilenceMessage(msg);
+                            Intent intent = new Intent(RABroadcast.EVENT_SILENCECOMMAND);
+                            intent.putExtra("msg", msg.toString());
+                            sendBroadcast(intent);
+
+                        } else {
+                            pushNotification(msg);
+
+                            Intent intent = new Intent(RABroadcast.EVENT_PUSHNOTIFICATION);
+                            intent.putExtra("msg", msg.toString());
+                            sendBroadcast(intent);
+
+
+                        }
+                    }
+
+
+                } catch (JSONException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
 
             }
 
@@ -248,17 +202,87 @@ public abstract class RAService extends Service {
         }
 
         @Override
-        protected void onCancelled()
-        {
+        protected void onCancelled() {
             m_task = null;
             // showProgress(false);
         }
     }
-    public void checkpush(Context context)
-    {
 
-        if (m_task != null)
-        {
+
+    public void pushNotification(JSONObject msg) {
+
+        if (enable_pushNotification) {
+
+            boolean bsound = true;
+//                    mcontext.getSharedPreferences(
+//                    "setting", 0).getBoolean(
+//                    "notifications_new_message_sound", true);
+            boolean bvibrate = true;
+//            mcontext.getSharedPreferences(
+//                    "setting", 0).getBoolean(
+//                    "notifications_new_message_vibrate", true);
+            NotificationManager nManager = (NotificationManager)
+                    getSystemService(Context.NOTIFICATION_SERVICE);
+
+/*
+       此部分在虚函数 prepareNotificaiton 中实现
+            Intent intent = new Intent(mcontext,
+                    FunctionSelectActivity.class);
+            intent.putExtra("launcher", "notification");
+
+            PendingIntent pintent = PendingIntent.getActivity(
+                    this, 0, intent,
+                    PendingIntent.FLAG_UPDATE_CURRENT);
+
+
+            Notification.Builder builder = new Notification.Builder(mcontext);//新建Notification.Builder对象
+            String ntitle = "";
+            int number = ApexTrackingApplication.ncount++;
+            if (number > 1)
+                ntitle=number
+                        + " "
+                        + ApexTrackingApplication
+                        .get_instance()
+                        .getString(
+                                R.string.str_mnotification_title);
+            else
+                ntitle = ApexTrackingApplication
+                        .get_instance()
+                        .getString(
+                                R.string.str_notification_title);
+
+            builder.setContentTitle(ntitle);//设置标题
+            builder.setContentText(ApexTrackingApplication
+                    .get_instance()
+                    .getString(
+                            R.string.str_notification_text)
+                    + date);//设置内容
+            builder.setSmallIcon(R.drawable.ic_launcher);//设置图片
+            builder.setContentIntent(pintent);//执行intent
+
+
+            */
+            Notification notification = pushNotificationCallback.prepareNotification(msg);//builder.getNotification();//将builder对象转换为普通的notifications
+            notification.defaults = Notification.DEFAULT_ALL;
+
+//            if (bsound && bvibrate)
+//                notification.defaults = Notification.DEFAULT_ALL;
+//            else if (bsound)
+//                notification.defaults = Notification.DEFAULT_SOUND
+//                        | Notification.DEFAULT_LIGHTS;
+//            else if (bvibrate)
+//                notification.defaults = Notification.DEFAULT_VIBRATE
+//                        | Notification.DEFAULT_LIGHTS;
+            notification.flags = Notification.FLAG_AUTO_CANCEL;
+//            notification.number = number; //number 是不是不需要了?
+
+            nManager.notify(R.layout.support_simple_spinner_dropdown_item, notification);
+        }
+    }
+
+    public void checkpush(Context context) {
+
+        if (m_task != null) {
             return;
         }
         // mStatusMessageView.setText(R.string.str_Loading);
@@ -277,10 +301,6 @@ public abstract class RAService extends Service {
     }
 
 
-    protected abstract void Setup();
-
-    protected abstract void onLocationChanged(Location location);
-
     @Override
     public IBinder onBind(Intent intent) {
 //         TODO: Return the communication channel to the service.
@@ -336,19 +356,20 @@ public abstract class RAService extends Service {
 
         msgFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
 
-        if ((service_flag & FLAG_SERVICE_UPLOAD) == 1) {
-            uploadManager = new RAUploadManager();
+        if ((service_flag & FLAG_SERVICE_UPLOAD) == FLAG_SERVICE_UPLOAD) {
+            uploadManager = new RAUploadManager(getApplicationContext());
 //            msgFilter.addAction("REDANT.POP.RESET_LOCATION");
 //            msgFilter.addAction("REDANT.POP.QUERY_UPLOAD_STATE");
             msgFilter.addAction("REDANT.BROADCAST.ACTION_UPLOAD_ADD_TASK");
 //            msgFilter.addAction("REDANT.BROADCAST.UPLOAD_MODIFY_QUEUE");
 //            msgFilter.addAction("REDANT.BROADCAST.UPLOAD_RETRY_UPLOAD");
         }
-        if ((service_flag & FLAG_SERVICE_LOCATION) == 1) {
+        if ((service_flag & FLAG_SERVICE_LOCATION) == FLAG_SERVICE_LOCATION) {
 
-            msgFilter.addAction("REDANT.BROADCAST.ACTION_LOCATION_ENABLE_TRACING");
-            msgFilter.addAction("REDANT.BROADCAST.ACTION_LOCATION_DISABLE_TRACING");
-            msgFilter.addAction("REDANT.BROADCAST.ACTION_LOCATION_REQUEST_LOCATION");
+
+            msgFilter.addAction(RABroadcast.ACTION_LOCATION_ENABLE_TRACING);
+            msgFilter.addAction(RABroadcast.ACTION_LOCATION_DISABLE_TRACING);
+            msgFilter.addAction(RABroadcast.ACTION_LOCATION_REQUEST_LOCATION);
 //            msgFilter.addAction("REDANT.BROADCAST.RESET_LOCATION");
             locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
 
@@ -376,20 +397,24 @@ public abstract class RAService extends Service {
                 // 当坐标改变时触发此函数,如果Provider传进相同的坐标,它就不会被触发
                 @Override
                 public void onLocationChanged(Location location) {
-                    onLocationChanged(location);
+                    locationCallback.onLocationChanged(location);
 
                 }
             };
 
 
-            enable_locationTracing(locationTracing_timeInterval,locationTracing_distance);
+            enable_locationTracing(locationTracing_timeInterval, locationTracing_distance);
 
 
 //          msgFilter.addAction("REDANT.POP.GPS_ON");
 //		    msgFilter.addAction("REDANT.POP.GPS_OFF");
 //		    msgFilter.addAction("REDANT.POP.REQUEST_LOCATION");
         }
-        if ((service_flag & FLAG_SERVICE_NOTIFICATION) == 1) {
+        if ((service_flag & FLAG_SERVICE_NOTIFICATION) == FLAG_SERVICE_NOTIFICATION) {
+
+            if (TextUtils.isEmpty(url_checknotification)) {
+                Log.e(TAG, "onCreate: setup FLAG_SERVICE_NOTIFICATION without url_checknotification");
+            }
 
             msgFilter.addAction("REDANT.BROADCAST.ACTION_PUSHNOTIFICATION_CHECK");
 
@@ -416,7 +441,7 @@ public abstract class RAService extends Service {
                     .getAction();
             // 如果捕捉到的action是ACTION_BATTERY_CHANGED
 
-            if ("REDANT.BROADCAST.ACTION_UPLOAD_ADD_TASK".equals(action)) {
+            if (RABroadcast.ACTION_UPLOAD_ADD_TASK.equals(action)) {
 
                 ArrayList<Bundle> tasks = intent.getParcelableArrayListExtra("tasks");
 
@@ -482,30 +507,38 @@ public abstract class RAService extends Service {
                 }
 
 
-            }
-            else if ("REDANT.BROADCAST.ACTION_LOCATION_ENABLE_TRACING"
-                    .equals(action))
-            {
-                enable_locationTracing(locationTracing_timeInterval,locationTracing_distance);
-            }
-            else if ("REDANT.BROADCAST.ACTION_LOCATION_DISABLE_TRACING"
-                    .equals(action))
-            {
+            } else if (RABroadcast.ACTION_LOCATION_ENABLE_TRACING
+                    .equals(action)) {
+                enable_locationTracing(locationTracing_timeInterval, locationTracing_distance);
+            } else if (RABroadcast.ACTION_LOCATION_DISABLE_TRACING
+                    .equals(action)) {
 
                 disable_locationTracing();
+            } else if (RABroadcast.ACTION_LOCATION_REQUEST_LOCATION
+                    .equals(action)) {
+
+
+                String receiverID=intent.getStringExtra("receiverID");
+//                locationManager.requestSingleUpdate();
+                request_location(receiverID);
+//                locationCallback.onLocationChanged();
             }
-            else if ("REDANT.BROADCAST.ACTION_LOCATION_REQUEST_LOCATION"
+            else if (RABroadcast.ACTION_PUSHNOTIFICATION_CHECK
                     .equals(action))
             {
-                request_location(intent);
+                checkpush(context);
             }
-            else if ("REDANT.BROADCAST.ACTION_PUSHNOTIFICATION_CHECK"
+            else if (RABroadcast.ACTION_PUSHNOTIFICATION_ENABLE_CHECK
                     .equals(action))
             {
 
                 String tag = "onReceive@Alarmreceiver";
-                Log.i( tag, "receive alarm broadcast caller =="
-                        + intent.getStringExtra("caller"));
+//                Log.i( tag, "receive alarm broadcast caller =="
+//                        + intent.getStringExtra("caller"));
+
+                startalarm();
+
+//                checkpush(context);
 
 //                if (SystemClock.elapsedRealtime()
 //                        - ApexTrackingApplication.getLastCheckMessageTime() > 120000)
@@ -516,9 +549,61 @@ public abstract class RAService extends Service {
 //
 //                }
             }
+            else if (RABroadcast.ACTION_PUSHNOTIFICATION_DISABLE_CHECK
+                    .equals(action))
+            {
+                if (m_task != null)
+                    m_task.cancel(true);
+//                NotificationManager nManager = (NotificationManager) context
+//                        .getSystemService(Context.NOTIFICATION_SERVICE);
+//                nManager.cancel(R.layout.activity_apex);
+                cancelalarm();
+                // ApexTrackingApplication.put_password("");
+                // ApexTrackingApplication.put_sessionid("");
+                // ApexTrackingApplication.put_user("");
+//                ApexTrackingApplication.logout();
+            }
         }
     };
+    private void startalarm()
+    {
+
+//        SharedPreferences pref = getSharedPreferences("Apex", 0);
+//        boolean autologin = pref.getBoolean("autologin", false);
+//        if (autologin == false)
+//            return;
 
+        // 启动完成
+        Intent iAlarm = new Intent(this, BroadcastReceiver.class);
+//        iAlarm.putExtra("caller", caller);
+        iAlarm.setAction(RABroadcast.ACTION_PUSHNOTIFICATION_CHECK);
+        PendingIntent sender = PendingIntent.getBroadcast(this, 0,
+                iAlarm, PendingIntent.FLAG_UPDATE_CURRENT);
+
+        long firstime = SystemClock.elapsedRealtime();
+//		UpdateLastAlermTime();
+        AlarmManager am = (AlarmManager) this.getSystemService(
+                Context.ALARM_SERVICE);
+
+        // 30秒一个周期,不停的发送广播
+        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstime,
+                pushcheck_timeInterval, sender);
+    }
+
+    private void cancelalarm()
+    {
+
+        // 启动完成
+        Intent iAlarm = new Intent(this, BroadcastReceiver.class);
+        iAlarm.setAction(RABroadcast.ACTION_PUSHNOTIFICATION_CHECK);
+        PendingIntent sender = PendingIntent.getBroadcast(this, 0,
+                iAlarm, PendingIntent.FLAG_UPDATE_CURRENT);
+
+        AlarmManager am = (AlarmManager) getSystemService(
+                Context.ALARM_SERVICE);
+
+        am.cancel(sender);
+    }
     void registerReceiver() {
 
     }
@@ -542,26 +627,56 @@ public abstract class RAService extends Service {
             return;
         }
 
-        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
 
+        locationManager.requestLocationUpdates(
+                "fused", timeInterval, distance,
+                locationListener);
+//        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
+//
+//
+//
+//
+//        } else if (locationManager
+//                .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
+//
+//
+//            locationManager.requestLocationUpdates(
+//                    LocationManager.NETWORK_PROVIDER, timeInterval, distance,
+//                    locationListener);
+//
+//        }
+    }
+
+    protected Location request_cachedlocation()
+    {
+        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
 
-            locationManager.requestLocationUpdates(
-                    LocationManager.GPS_PROVIDER, timeInterval, distance,
-                    locationListener);
+            return null;
+        }
 
-        } else if (locationManager
-                .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
 
 
-            locationManager.requestLocationUpdates(
-                    LocationManager.NETWORK_PROVIDER, timeInterval, distance,
-                    locationListener);
+        //使用GPS获取上一次的地址,这样获取到的信息需要多次,才能够显示出来,所以后面有动态的判断
+        Location location = locationManager.getLastKnownLocation("fused");
+        return location;
 
-        }
     }
-
-    void request_location(Intent intent)
+    protected void request_location(final String receiverID)
     {
+        if(receiverID==null)
+            throw new IllegalArgumentException("receiverID can't be null");
+
+//        Criteria criteria = new Criteria();
+//        criteria.setAccuracy(Criteria.ACCURACY_COARSE);//低精度,如果设置为高精度,依然获取不了location。
+//        criteria.setAltitudeRequired(false);//不要求海拔
+//        criteria.setBearingRequired(false);//不要求方位
+//        criteria.setCostAllowed(true);//允许有花费
+//        criteria.setPowerRequirement(Criteria.POWER_LOW);//低功耗
+//
+//        //从可用的位置提供器中,匹配以上标准的最佳提供器
+//        String locationProvider = locationManager.getBestProvider(criteria, true);
+
+
         if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
             // TODO: Consider calling
             //    ActivityCompat#requestPermissions
@@ -570,68 +685,41 @@ public abstract class RAService extends Service {
             //                                          int[] grantResults)
             // to handle the case where the user grants the permission. See the documentation
             // for ActivityCompat#requestPermissions for more details.
-            return;
+            return ;
         }
 
-        Location location = null;
-        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
-        {
+        LocationListener singleListener = new LocationListener() {
+            @Override
+            public void onLocationChanged(Location location) {
 
-            location = locationManager
-                    .getLastKnownLocation(LocationManager.GPS_PROVIDER);
+                Intent Bintent = new Intent(RABroadcast.EVENT_RETURN_LOCATION);
+                Bintent.putExtra("location",location);
+                Bintent.putExtra("receiverID",receiverID);
+                sendBroadcast(Bintent);
 
-        }
-        else if (locationManager
-                .isProviderEnabled(LocationManager.NETWORK_PROVIDER))
-        {
 
-            location = locationManager
-                    .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
 
-        }
+            }
+
+            @Override
+            public void onStatusChanged(String s, int i, Bundle bundle) {
+
+            }
+
+            @Override
+            public void onProviderEnabled(String s) {
+
+            }
+
+            @Override
+            public void onProviderDisabled(String s) {
+
+            }
+        };
+
+
+        locationManager.requestSingleUpdate("fused", singleListener, null);
 
-//        SharedPreferences pref = RedAntApplication.getInstance()
-//                .getSharedPreferences("POP", 0);
-//        double lat = pref.getFloat("Lat", 9999);
-//        double lon = pref.getFloat("Lon", 9999);
-//
-//        // SharedPreferences.Editor editor = pref.edit();
-//        if (location != null)
-//        {
-//            float[] result = new float[1];
-//            if (lat != 9999 && lon != 9999)
-//            {
-//                Location.distanceBetween(lat, lon, location.getLatitude(),
-//                        location.getLongitude(), result);
-//                if (result[0] > 1000)
-//                {
-//                    sendBroadcast(new Intent("REDANT.POP.STATION_CHANGE"));
-//                    return;
-//                }
-//                else
-//                {
-//                    sendBroadcast(new Intent("REDANT.POP.STATION_NOT_CHANGE"));
-//                    return;
-//                }
-//            }
-//            sendBroadcast(new Intent("REDANT.POP.STATION_NOT_CHANGE"));
-//            return;
-//            // new Location();
-//            //
-//            // Location.distanceBetween(lat, lon, endLatitude, endLongitude,
-//            // results)
-//            //
-//            // editor.putFloat("Lat", (float) location.getLatitude());
-//            // editor.putFloat("Lon", (float) location.getLongitude());
-//
-//        }
-//        else
-//        {
-//            sendBroadcast(new Intent("REDANT.POP.STATION_NOT_CHANGE"));
-//            return;
-//        }
-        // editor.commit();
 
-        // Log.d("location:", "lat:" + latitude + "lon:" + longitude);
     }
 }

+ 14 - 6
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/Upload/RAOperationQueue.java

@@ -1,6 +1,6 @@
 package com.usai.redant.rautils.Upload;
 
-import android.app.Application;
+import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.util.Log;
@@ -24,11 +24,19 @@ public class RAOperationQueue {
         public void operateFinish(Bundle taskinfo);
     }
 
-    private Application mApp;
-    public void setApplication(Application application) {
-        mApp = application;
-    }
+//    private Application mApp;
+//    public void setApplication(Application application) {
+//        mApp = application;
+//    }
+
 
+    public RAOperationQueue(Context applicationContext)
+    {
+        if(applicationContext==null)
+            throw new IllegalArgumentException("applicationContext can't be null");
+        this.applicationContext = applicationContext;
+    }
+    Context applicationContext;
     OperationCallback execCallback;
     public void setCallback(OperationCallback callback)
     {
@@ -106,7 +114,7 @@ public class RAOperationQueue {
                                 intent.putExtra("result","finish");
                             }
 
-                            mApp.getApplicationContext().sendBroadcast(intent);
+                            applicationContext.sendBroadcast(intent);
 
                             //getApplicationContext()
                             Log.e("Finish_msg", "run: -----------task finish" );

+ 20 - 15
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/Upload/RAUploadManager.java

@@ -1,6 +1,5 @@
 package com.usai.redant.rautils.Upload;
 
-import android.app.Application;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.net.ConnectivityManager;
@@ -77,13 +76,19 @@ public class RAUploadManager {
         //TaskStatusCancel,
     }
 
+    public RAUploadManager(Context applicationContext)
+    {
+        if(applicationContext==null)
+            throw new IllegalArgumentException("applicationContext can't be null");
+        this.applicationContext = applicationContext;
+    }
     public UIUpdateListener uiUpdateListener;
 
-    private Application mApp;
-
-    public void setApplication(Application application) {
-        mApp = application;
-    }
+//    private Application mApp;
+    private Context applicationContext;
+//    public void setApplication(Application application) {
+//        mApp = application;
+//    }
 
     public interface UIUpdateListener {
         //        void onProgress(long index, double percentage);
@@ -112,7 +117,7 @@ public class RAUploadManager {
         queue_status = QueueStatus.QueueStatusDefault;
 
 
-        SharedPreferences UMSetting = mApp.getSharedPreferences("UploadManager", 0);
+        SharedPreferences UMSetting = applicationContext.getSharedPreferences("UploadManager", 0);
 
         if (UMSetting != null) {
 //            autoStart = UMSetting.getBoolean("auto_upload",false);
@@ -126,8 +131,8 @@ public class RAUploadManager {
             wifiOnly = UMSetting.getBoolean("wifi_only", false);
 
         }
-        operation_queue = new RAOperationQueue();
-        operation_queue.setApplication(mApp);
+        operation_queue = new RAOperationQueue(applicationContext);
+//        operation_queue.setApplication(mApp);
         operation_queue.setCallback(new RAOperationQueue.OperationCallback() {
             @Override
             public Boolean operate(final Bundle taskinfo) {
@@ -343,7 +348,7 @@ public class RAUploadManager {
                 if (file.exists() && taskinfo.getInt("status") == TaskStatus.TaskStatusFinish.ordinal() && taskinfo.getString("msg").indexOf("warning:") < 0) {
                     String filepath = file.getAbsolutePath();
                     file.delete();
-                    ImageUtil.updateGallery(mApp.getApplicationContext(),filepath);
+                    ImageUtil.updateGallery(applicationContext,filepath);
                 }
                 ///////////////////////////////////////////////
 
@@ -394,7 +399,7 @@ public class RAUploadManager {
 
         Log.d("_RAIMAGE", "saveTasks: RAUploadManager");
 
-        SharedPreferences pref = mApp.getSharedPreferences("RA Image", 0);
+        SharedPreferences pref = applicationContext.getSharedPreferences("RA Image", 0);
         try {
             String tasksBase64 = pref.getString("task_list", "");
 
@@ -503,7 +508,7 @@ public class RAUploadManager {
 
         boolean canstart = true;
 
-        ConnectivityManager connManager = (ConnectivityManager) mApp.getSystemService(Context.CONNECTIVITY_SERVICE);
+        ConnectivityManager connManager = (ConnectivityManager) applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
 
         NetworkInfo networkInfo = connManager
                 .getActiveNetworkInfo();
@@ -587,7 +592,7 @@ public class RAUploadManager {
             if (file.exists() && task.getInt("status") == TaskStatus.TaskStatusFinish.ordinal()) {
                 String filepath = file.getAbsolutePath();
                 file.delete();
-                ImageUtil.updateGallery(mApp.getApplicationContext(),filepath);
+                ImageUtil.updateGallery(applicationContext,filepath);
             }
 
             if (uiUpdateListener != null)
@@ -615,7 +620,7 @@ public class RAUploadManager {
                 if (file.exists() && task.getInt("status") == TaskStatus.TaskStatusFinish.ordinal()) {
                     String filepath = file.getAbsolutePath();
                     file.delete();
-                    ImageUtil.updateGallery(mApp.getApplicationContext(),filepath);
+                    ImageUtil.updateGallery(applicationContext,filepath);
                 }
             }
             if (uiUpdateListener != null)
@@ -661,7 +666,7 @@ public class RAUploadManager {
 
         Log.d("_RAIMAGE", "saveTasks: RAUploadManager");
 
-        SharedPreferences pref = mApp.getSharedPreferences("RA Image", 0);
+        SharedPreferences pref = applicationContext.getSharedPreferences("RA Image", 0);
         SharedPreferences.Editor editor = pref.edit();
 
         try {

+ 2 - 1
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/Upload/UploadService.java

@@ -18,6 +18,7 @@ import com.usai.redant.rautils.Utils.dbgUtil;
 
 import java.util.ArrayList;
 
+@Deprecated
 public class UploadService extends Service
 {
 
@@ -27,7 +28,7 @@ public class UploadService extends Service
 //	LocationManager			locationManager;
 //	LocationListener		locationListener;
 
-    public RAUploadManager uploadManager = new RAUploadManager();
+    public RAUploadManager uploadManager = new RAUploadManager(getApplicationContext());
 
     // private boolean location_changed = false;
 

+ 1 - 1
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/Utils/Network.java

@@ -556,7 +556,7 @@ public class Network {
 
         return returnFile;
     }
-    public static String check_push(Context c,Bundle params)
+    public static String check_push(Context c,Bundle params,String url)
     {
 
         if(true)

+ 6 - 0
ApexDrivers/app/app.iml

@@ -84,15 +84,21 @@
       <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
       <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
       <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
       <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
     </content>

+ 7 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/ApexDriverApplication.java

@@ -1,6 +1,7 @@
 package com.usai.redant.apexdrivers;
 
 import android.app.Application;
+import android.content.Intent;
 import android.content.SharedPreferences;
 
 import com.usai.redant.rautils.Utils.AESUtil;
@@ -22,6 +23,12 @@ public class ApexDriverApplication extends Application {
 
         user = savedUser();
         password = savedPassword();
+
+
+
+         Intent serviceintent = new Intent();
+         serviceintent.setClass(this, ApexDriversBackgroundService.class);
+         startService(serviceintent);
     }
 
     public boolean isLogin() {

+ 33 - 3
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/ApexDriversBackgroundService.java

@@ -1,26 +1,56 @@
 package com.usai.redant.apexdrivers;
 
+import android.app.Notification;
 import android.location.Location;
+import android.util.Log;
 
 import com.usai.redant.rautils.Service.RAService;
 import com.usai.redant.rautils.Utils.dbgUtil;
 
-public class ApexDriversBackgroundService extends RAService {
+import org.json.JSONObject;
+
+public class ApexDriversBackgroundService extends RAService implements RAService.ServiceLocation, RAService.ServicePushNotification,RAService.ServiceUpload{
     public ApexDriversBackgroundService() {
     }
 
     @Override
     protected void Setup() {
-        service_flag=FLAG_SERVICE_UPLOAD|FLAG_SERVICE_NOTIFICATION|FLAG_SERVICE_LOCATION;
+//        service_flag=FLAG_SERVICE_UPLOAD|FLAG_SERVICE_NOTIFICATION|FLAG_SERVICE_LOCATION;
+
+        initServiceLocation(this);
+        initServiceNotification(this,"replace this string with notification checking url");
+        initServiceUpload(this);
 
         dbgUtil.fileLog(this,"ApexDriversBackgroundService Setup()");
     }
 
+//    @Override
+//    public void RequestLocation_ByBroadcast(String receiverID) {
+//        request_location(receiverID);
+//    }
+
+    @Override
+    public Location RequestCachedLocation() {
+        return request_cachedlocation();
+    }
+
     @Override
-    protected void onLocationChanged(Location location) {
+    public void onLocationChanged(Location location) {
 
+        Log.d("ApexDriversB..Service", "onLocationChanged: ");
     }
 
+    @Override
+    public Notification prepareNotification(JSONObject msg) {
+        return null;
+    }
+
+    @Override
+    public void handleSilenceMessage(JSONObject msg) {
+
+    }
+
+
 //    @Override
 //    public IBinder onBind(Intent intent) {
 //        // TODO: Return the communication channel to the service.

+ 37 - 0
ApexDrivers/app/src/main/java/com/usai/redant/apexdrivers/MainActivity.java

@@ -2,11 +2,18 @@ package com.usai.redant.apexdrivers;
 
 
 import android.app.ProgressDialog;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.location.Location;
 import android.os.Bundle;
+import android.os.IBinder;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
 import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.widget.RelativeLayout;
@@ -25,6 +32,34 @@ public class MainActivity extends AppCompatActivity implements LoginFragment.Log
 
     void Test()
     {
+
+//        if(true)
+//            return;
+        ServiceConnection serviceConnection= new ServiceConnection(){
+
+            @Override
+            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
+                ApexDriversBackgroundService.MyBinder binder;
+                binder = (ApexDriversBackgroundService.MyBinder)iBinder;
+                ApexDriversBackgroundService service = (ApexDriversBackgroundService)binder.getService();
+
+                Location l=service.RequestCachedLocation();
+                if(l!=null)
+                    Log.d("", "RequestLocation: "+l.toString());
+
+            }
+
+            @Override
+            public void onServiceDisconnected(ComponentName componentName) {
+
+            }
+        };
+
+        Intent intent = new Intent(MainActivity.this, ApexDriversBackgroundService.class);
+
+        bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
+
+
         dbgUtil.fileLog(this,"lib import successful");
 
 
@@ -53,6 +88,8 @@ public class MainActivity extends AppCompatActivity implements LoginFragment.Log
         mRootContainer = findViewById(R.id.root_container);
 
         initView();
+
+        Test();
     }
 
     private void initView() {