Files
sb-front/android/app/src/main/java/kr/sblog/slimbudget/CardNotifPlugin.java
T

40 lines
1.3 KiB
Java
Raw Normal View History

package kr.sblog.slimbudget;
import android.content.Intent;
import android.provider.Settings;
import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;
/**
* 카드 결제 알림 자동인식 플러그인.
* - isEnabled: 알림 접근 권한(NotificationListener) 허용 여부
* - openSettings: 알림 접근 설정 화면 열기
* 실제 알림 수신/전송은 CardNotifListenerService 가 담당한다.
*/
@CapacitorPlugin(name = "CardNotif")
public class CardNotifPlugin extends Plugin {
@PluginMethod
public void isEnabled(PluginCall call) {
String pkg = getContext().getPackageName();
String flat = Settings.Secure.getString(
getContext().getContentResolver(), "enabled_notification_listeners");
boolean enabled = flat != null && flat.contains(pkg);
JSObject ret = new JSObject();
ret.put("enabled", enabled);
call.resolve(ret);
}
@PluginMethod
public void openSettings(PluginCall call) {
Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(intent);
call.resolve();
}
}