Last active
September 25, 2020 04:20
-
-
Save VioletXF/15afa5ac3859e1db255099ae7a0d8ece to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| importPackage(android.content); | |
| importPackage(android.app); | |
| const CHANNEL_ID = "test channel"; | |
| const actionName="myawesomemsgbot.buttonClick";//그냥 시스템 전반적으로 유니크하게 하시면 됩니다. | |
| const bot = BotManager.getCurrentBot(); | |
| let receiver = new BroadcastReceiver({ | |
| onReceive: function(ctx, intent){ | |
| let action = intent.getAction(); | |
| if(action.equals(actionName)){ | |
| Log.info("btn click"); | |
| } | |
| } | |
| }); | |
| let filter=new IntentFilter(actionName); | |
| App.getContext().registerReceiver(receiver, filter); | |
| function createNotificationChannel(){ | |
| let name = "알림채널 이름"; | |
| let importance = NotificationManager.IMPORTANCE_DEFAULT; | |
| let channel = NotificationChannel(CHANNEL_ID, name, importance); | |
| let manager = App.getContext().getSystemService(Context.NOTIFICATION_SERVICE); | |
| manager.createNotificationChannel(channel); | |
| } | |
| createNotificationChannel(); | |
| function notify(){ | |
| let intentAction = new Intent(actionName); | |
| let pendingIntent = PendingIntent.getBroadcast(App.getContext(), 1, intentAction, PendingIntent.FLAG_UPDATE_CURRENT); | |
| let builder = Notification.Builder(App.getContext(), CHANNEL_ID) | |
| .setSmallIcon(com.xfl.msgbot.R.drawable.ic_launcher_background) | |
| .setContentTitle("알림제목") | |
| .setContentText("알림내용") | |
| .setPriority(Notification.PRIORITY_DEFAULT) | |
| .addAction(0, "버튼이름", pendingIntent) | |
| App.getContext().getSystemService(Context.NOTIFICATION_SERVICE).notify(9999, builder.build()); | |
| } | |
| function onMessage(msg){ | |
| switch(msg.content){ | |
| case "test": | |
| notify(); | |
| break; | |
| } | |
| } | |
| function onStartCompile(){ | |
| App.getContext().unregisterReceiver(receiver); | |
| } | |
| bot.addListener(Event.START_COMPILE,onStartCompile); | |
| bot.addListener(Event.MESSAGE, onMessage); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment