|
|
@@ -13,11 +13,15 @@ import android.content.Intent;
|
|
|
import android.content.ServiceConnection;
|
|
|
import android.content.SharedPreferences;
|
|
|
import android.location.Location;
|
|
|
+import android.media.AudioAttributes;
|
|
|
+import android.media.RingtoneManager;
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.IBinder;
|
|
|
import android.os.Looper;
|
|
|
+import android.provider.Settings;
|
|
|
import android.support.v4.app.NotificationCompat;
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
import android.text.TextUtils;
|
|
|
@@ -35,6 +39,7 @@ import org.json.JSONObject;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
|
+import static android.app.Notification.VISIBILITY_PUBLIC;
|
|
|
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
|
|
|
|
|
public class ApexDriverApplication extends Application {
|
|
|
@@ -598,7 +603,7 @@ public class ApexDriverApplication extends Application {
|
|
|
sendBroadcast(new Intent(HomeFragment.HomeReloadBroadcastAction));
|
|
|
|
|
|
boolean isActive = !isbackground; // 程序是否在前台
|
|
|
- if (isActive) {
|
|
|
+ if (isActive) {
|
|
|
// 弹窗提示
|
|
|
|
|
|
final int orderType = aps.optInt("order-type");
|
|
|
@@ -688,10 +693,22 @@ public class ApexDriverApplication extends Application {
|
|
|
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
|
|
|
|
Notification noti = null;
|
|
|
+ long[] vibrates = { 0, 1000, 1000, 1000 };
|
|
|
+
|
|
|
+// Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
|
|
+ Uri soundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
|
|
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_NONE);
|
|
|
+ // 震动
|
|
|
+ channel.enableVibration(true);
|
|
|
+ channel.setVibrationPattern(vibrates);
|
|
|
+
|
|
|
+ channel.enableLights(true);
|
|
|
+
|
|
|
+ channel.setSound(soundUri, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
|
|
+
|
|
|
nm.createNotificationChannel(channel);
|
|
|
|
|
|
noti = new NotificationCompat.Builder(this, CHANNEL_ID)
|
|
|
@@ -699,6 +716,9 @@ public class ApexDriverApplication extends Application {
|
|
|
.setContentText(msg)
|
|
|
.setSmallIcon(R.drawable.icon_50)
|
|
|
.setContentIntent(contentIntent)
|
|
|
+ .setVisibility(VISIBILITY_PUBLIC)
|
|
|
+ .setSound(soundUri)
|
|
|
+ .setLights(0xff00bbff,500,200)
|
|
|
.build();
|
|
|
} else {
|
|
|
|
|
|
@@ -707,10 +727,19 @@ public class ApexDriverApplication extends Application {
|
|
|
.setContentText(msg)
|
|
|
.setSmallIcon(R.drawable.icon_50)
|
|
|
.setContentIntent(contentIntent)
|
|
|
+ .setVisibility(VISIBILITY_PUBLIC)
|
|
|
+ .setSound(soundUri)
|
|
|
+ .setLights(0xff00bbff,500,20)
|
|
|
.build();
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * vibrate属性是一个长整型的数组,用于设置手机静止和振动的时长,以毫秒为单位。
|
|
|
+ * 参数中下标为0的值表示手机静止的时长,下标为1的值表示手机振动的时长, 下标为2的值又表示手机静止的时长,以此类推。
|
|
|
+ */
|
|
|
+ noti.vibrate = vibrates;
|
|
|
+
|
|
|
noti.flags |= Notification.FLAG_AUTO_CANCEL;
|
|
|
nm.notify(id, noti);
|
|
|
}
|