feat:添加登录功能

This commit is contained in:
2025-11-10 13:58:06 +08:00
parent 49f9b28091
commit 2e2caeaab5
36 changed files with 1076 additions and 458 deletions

View File

@@ -1,5 +1,14 @@
package com.bill.ai;
import android.os.Bundle;
import com.bill.ai.notification.NotificationPermissionPlugin;
import com.getcapacitor.BridgeActivity;
public class MainActivity extends BridgeActivity {}
public class MainActivity extends BridgeActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
registerPlugin(NotificationPermissionPlugin.class);
super.onCreate(savedInstanceState);
}
}

View File

@@ -0,0 +1,84 @@
package com.bill.ai.notification;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationManagerCompat;
import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.annotation.CapacitorPlugin;
import com.getcapacitor.annotation.Permission;
import com.getcapacitor.annotation.PermissionCallback;
import com.getcapacitor.annotation.PluginMethod;
@CapacitorPlugin(name = "NotificationPermissions", permissions = {
@Permission(alias = "notifications", strings = {"android.permission.POST_NOTIFICATIONS"})
})
public class NotificationPermissionPlugin extends Plugin {
@PluginMethod
public void checkStatus(@NonNull PluginCall call) {
JSObject result = new JSObject();
result.put("granted", isNotificationListenerEnabled(getContext()));
result.put("postNotificationsGranted", isPostNotificationsGranted());
call.resolve(result);
}
@PluginMethod
public void requestAccess(@NonNull PluginCall call) {
boolean granted = isNotificationListenerEnabled(getContext());
if (!granted) {
openNotificationListenerSettings();
}
JSObject result = new JSObject();
result.put("opened", true);
call.resolve(result);
}
@PluginMethod
public void openSettings(@NonNull PluginCall call) {
openNotificationListenerSettings();
JSObject result = new JSObject();
result.put("opened", true);
call.resolve(result);
}
@PluginMethod
public void requestPostNotifications(@NonNull PluginCall call) {
if (isPostNotificationsGranted()) {
JSObject result = new JSObject();
result.put("granted", true);
call.resolve(result);
return;
}
requestPermissionForAlias("notifications", call, "handlePostNotificationPermission");
}
@PermissionCallback
private void handlePostNotificationPermission(PluginCall call) {
boolean granted = isPostNotificationsGranted();
JSObject result = new JSObject();
result.put("granted", granted);
call.resolve(result);
}
private boolean isNotificationListenerEnabled(Context context) {
return NotificationManagerCompat.getEnabledListenerPackages(context).contains(context.getPackageName());
}
private boolean isPostNotificationsGranted() {
return NotificationManagerCompat.from(getContext()).areNotificationsEnabled();
}
private void openNotificationListenerSettings() {
Context context = getContext();
Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}