|
|
@@ -12,6 +12,7 @@ import android.content.Intent;
|
|
|
import android.os.Build;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
+import androidx.core.app.NotificationCompat;
|
|
|
|
|
|
import com.amap.api.location.AMapLocation;
|
|
|
import com.amap.api.location.AMapLocationClient;
|
|
|
@@ -64,7 +65,7 @@ public class AMapHelper {
|
|
|
});
|
|
|
if (PermissionUtil.hasPermission(context, LOCATION_PERMISSION)) {
|
|
|
aMapLocationClient.startLocation();
|
|
|
-// aMapLocationClient.enableBackgroundLocation(AMAP_NOTIFICATION_ID, createLocationNotification(context));
|
|
|
+ aMapLocationClient.enableBackgroundLocation(AMAP_NOTIFICATION_ID, createLocationNotification(context));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
isLocationInit.set(false);
|
|
|
@@ -76,41 +77,46 @@ public class AMapHelper {
|
|
|
public static void startLocation(Context context) {
|
|
|
if (isLocationInit.get()) {
|
|
|
aMapLocationClient.startLocation();
|
|
|
-// aMapLocationClient.enableBackgroundLocation(AMAP_NOTIFICATION_ID, createLocationNotification(context));
|
|
|
+ aMapLocationClient.enableBackgroundLocation(AMAP_NOTIFICATION_ID, createLocationNotification(context));
|
|
|
} else {
|
|
|
initLocation(context);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-// private static Notification createLocationNotification(Application application) {
|
|
|
-// NotificationManager notificationManager = (NotificationManager) application.getSystemService(Application.NOTIFICATION_SERVICE);
|
|
|
-// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
-// NotificationChannel notificationChannel = new NotificationChannel(AMAP_NOTIFICATION_CHANNEL_ID,
|
|
|
-// AMAP_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
|
|
|
-// notificationManager.createNotificationChannel(notificationChannel);
|
|
|
-// }
|
|
|
-//
|
|
|
-// Intent splashIntent = new Intent(application, .class);
|
|
|
-// splashIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
-//
|
|
|
-// PendingIntent contentIntent = PendingIntent.getActivity(
|
|
|
-// application,
|
|
|
-// 12344,
|
|
|
-// splashIntent,
|
|
|
-// PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
|
|
|
-// );
|
|
|
-//
|
|
|
-// return new NotificationCompat.Builder(application, AMAP_NOTIFICATION_CHANNEL_ID)
|
|
|
-// .setContentTitle(application.getString(R.string.location_notification_title))
|
|
|
-// .setContentText(application.getString(R.string.location_notification_content))
|
|
|
-// .setSmallIcon(R.drawable.icon_location_notification_small)
|
|
|
-// .setContentIntent(contentIntent)
|
|
|
-// .setOngoing(true)
|
|
|
-// .setSilent(true)
|
|
|
-// .setAutoCancel(false)
|
|
|
-// .build();
|
|
|
-// }
|
|
|
+ private static Notification createLocationNotification(Context context) {
|
|
|
+ LogUtil.d(TAG, "amap ... createLocationNotification...");
|
|
|
+ NotificationManager notificationManager = (NotificationManager) context.getSystemService(Application.NOTIFICATION_SERVICE);
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+ NotificationChannel notificationChannel = new NotificationChannel(AMAP_NOTIFICATION_CHANNEL_ID,
|
|
|
+ AMAP_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
|
|
|
+ notificationManager.createNotificationChannel(notificationChannel);
|
|
|
+ }
|
|
|
+
|
|
|
+ Intent splashIntent = new Intent();
|
|
|
+ splashIntent.setAction(Intent.ACTION_MAIN);
|
|
|
+ splashIntent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
|
+ splashIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+
|
|
|
+ PendingIntent contentIntent = PendingIntent.getActivity(
|
|
|
+ context,
|
|
|
+ 12345,
|
|
|
+ splashIntent,
|
|
|
+ PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
|
|
|
+ );
|
|
|
+
|
|
|
+ String appName = SystemUtil.getAppName(context);
|
|
|
+
|
|
|
+ return new NotificationCompat.Builder(context, AMAP_NOTIFICATION_CHANNEL_ID)
|
|
|
+ .setContentTitle(context.getString(R.string.location_notification_title, appName))
|
|
|
+ .setContentText(context.getString(R.string.location_notification_content, appName))
|
|
|
+ .setSmallIcon(R.drawable.icon_location_notification_small)
|
|
|
+ .setContentIntent(contentIntent)
|
|
|
+ .setOngoing(true)
|
|
|
+ .setSilent(true)
|
|
|
+ .setAutoCancel(false)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
|
|
|
public static AMapLocation getLastLocation() {
|
|
|
return lastLocation;
|