diff --git a/app/src/main/java/net/kaaass/zerotierfix/ui/NetworkListFragment.java b/app/src/main/java/net/kaaass/zerotierfix/ui/NetworkListFragment.java
index d343925..4ab37ca 100644
--- a/app/src/main/java/net/kaaass/zerotierfix/ui/NetworkListFragment.java
+++ b/app/src/main/java/net/kaaass/zerotierfix/ui/NetworkListFragment.java
@@ -1,5 +1,6 @@
package net.kaaass.zerotierfix.ui;
+import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ComponentName;
@@ -27,6 +28,7 @@
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.SwitchCompat;
+import androidx.core.app.NotificationManagerCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
@@ -34,7 +36,6 @@
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.zerotier.sdk.NodeStatus;
import com.zerotier.sdk.Version;
-import com.zerotier.sdk.VirtualNetworkConfig;
import net.kaaass.zerotierfix.BuildConfig;
import net.kaaass.zerotierfix.R;
@@ -44,12 +45,12 @@
import net.kaaass.zerotierfix.events.IsServiceRunningRequestEvent;
import net.kaaass.zerotierfix.events.NetworkListCheckedChangeEvent;
import net.kaaass.zerotierfix.events.NetworkListReplyEvent;
+import net.kaaass.zerotierfix.events.NetworkListRequestEvent;
import net.kaaass.zerotierfix.events.NodeDestroyedEvent;
import net.kaaass.zerotierfix.events.NodeIDEvent;
import net.kaaass.zerotierfix.events.NodeStatusEvent;
import net.kaaass.zerotierfix.events.NodeStatusRequestEvent;
import net.kaaass.zerotierfix.events.OrbitMoonEvent;
-import net.kaaass.zerotierfix.events.NetworkListRequestEvent;
import net.kaaass.zerotierfix.events.StopEvent;
import net.kaaass.zerotierfix.events.VPNErrorEvent;
import net.kaaass.zerotierfix.events.VirtualNetworkConfigChangedEvent;
@@ -196,9 +197,17 @@ public void onAttach(@NonNull Context context) {
public void onStart() {
super.onStart();
this.eventBus.post(new NetworkListRequestEvent());
+
// 初始化节点及服务状态
this.eventBus.post(new NodeStatusRequestEvent());
this.eventBus.post(new IsServiceRunningRequestEvent());
+
+ // 检查通知权限
+ var notificationManager = NotificationManagerCompat.from(requireContext());
+ if (!notificationManager.areNotificationsEnabled()) {
+ // 无通知权限
+ showNoNotificationAlertDialog();
+ }
}
@Override
@@ -587,6 +596,45 @@ public void onNetworkListCheckedChangeEvent(NetworkListCheckedChangeEvent event)
}
}
+ /**
+ * 显示无通知权限的提示框。若用户选择过 “不再提示”,则此方法将不进行任何操作
+ */
+ private void showNoNotificationAlertDialog() {
+ // 检查是否选择过 “不再提示”,若是则不显示
+ var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext());
+
+ if (sharedPreferences.getBoolean(Constants.PREF_DISABLE_NO_NOTIFICATION_ALERT, false)) {
+ return;
+ }
+
+ // 显示提示框
+ View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_no_notification_alert, null);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(getContext())
+ .setView(view)
+ .setTitle(R.string.dialog_no_notification_alert_title)
+ .setPositiveButton(R.string.open_notification_settings, (dialog, which) -> {
+ // 打开 APP 的通知设置
+ var intent = new Intent();
+
+ intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra("app_package", requireContext().getPackageName());
+ intent.putExtra("app_uid", requireContext().getApplicationInfo().uid);
+ intent.putExtra("android.provider.extra.APP_PACKAGE", requireContext().getPackageName());
+ startActivity(intent);
+ })
+ .setNegativeButton(R.string.dont_show_again, (dialog, which) -> {
+ // 设置不再提示此对话框
+ sharedPreferences.edit()
+ .putBoolean(Constants.PREF_DISABLE_NO_NOTIFICATION_ALERT, true)
+ .apply();
+ })
+ .setCancelable(true);
+
+ builder.create().show();
+ }
+
/**
* 网络信息列表适配器
*/
diff --git a/app/src/main/java/net/kaaass/zerotierfix/util/Constants.java b/app/src/main/java/net/kaaass/zerotierfix/util/Constants.java
index f1d353b..d8ef123 100644
--- a/app/src/main/java/net/kaaass/zerotierfix/util/Constants.java
+++ b/app/src/main/java/net/kaaass/zerotierfix/util/Constants.java
@@ -17,6 +17,8 @@ public class Constants {
public static final String PREF_GENERAL_START_ZEROTIER_ON_BOOT = "general_start_zerotier_on_boot";
+ public static final String PREF_DISABLE_NO_NOTIFICATION_ALERT = "disable_no_notification_alert";
+
public static final String FILE_CUSTOM_PLANET = "planet.custom";
public static final String FILE_TEMP = "temp";
diff --git a/app/src/main/res/layout/dialog_no_notification_alert.xml b/app/src/main/res/layout/dialog_no_notification_alert.xml
new file mode 100644
index 0000000..847dde4
--- /dev/null
+++ b/app/src/main/res/layout/dialog_no_notification_alert.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 96a68d3..0f98b7d 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -147,4 +147,8 @@
VPN 服务发生错误!%1$s
未知
(APP: %s)
+ Zerotier Fix 未获得通知权限!您可能会遗漏用于提示连接状态的通知气泡与状态栏消息。Zerotier Fix 推荐您打开应用通知权限以获取连接状态信息。如果您不希望看到状态栏的常驻通知,您仍可以在打开通知权限后关闭对应通知类别的消息。
+ 未开启通知权限
+ 打开通知设置
+ 不再提示
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 226df12..4ef08e1 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -149,4 +149,8 @@
A VPN service error has occurred! %1$s
Unknown
(APP: %s)
+ Zerotier Fix does not have notification permissions! You might miss notification pop-ups and status bar messages that indicate connection status. Zerotier Fix recommends you enable notification permissions for the app to receive connection status information. If you don\'t want to see persistent notifications in the status bar, you can still turn off messages for that notification category after enabling the permissions.
+ Notification Permission Not Granted
+ Goto notification settings
+ Don\'t show again