fix(sample): 通知监听

This commit is contained in:
hyb1996
2018-05-26 10:59:34 +08:00
parent d5630876d9
commit 9911c9146d
3 changed files with 8 additions and 11 deletions

View File

@@ -1,21 +1,16 @@
auto(); auto();
events.observeNotification(); events.observeNotification();
events.onNotification(function(info, notification){ events.onNotification(function(notification){
printNotification(info, notification); printNotification(notification);
}); });
toast("监听中,请在日志中查看记录的通知及其内容"); toast("监听中,请在日志中查看记录的通知及其内容");
function printNotification(info, notification){ function printNotification(notification){
log("应用包名: " + info.getPackageName()); log("应用包名: " + notification.getPackageName());
log("通知文本: " + info.getTexts()); log("通知文本: " + notification.getText());
log("通知优先级: " + notification.priority); log("通知优先级: " + notification.priority);
log("通知目录: " + notification.category); log("通知目录: " + notification.category);
log("通知创建时间: " + new Date(notification.creationTime));
log("通知时间: " + new Date(notification.when)); log("通知时间: " + new Date(notification.when));
log("通知数: " + notification.number); log("通知数: " + notification.number);
log("通知摘要: " + notification.tickerText); log("通知摘要: " + notification.tickerText);
for(var i = 0; i < notification.actions.length; i++){
var action = notification.actions[i];
log("通知" + (i + 1) + ": " + action.title);
}
} }

View File

@@ -53,3 +53,5 @@ public class ApkBuilderPluginHelper {
return BuildConfig.VERSION_CODE - 200; return BuildConfig.VERSION_CODE - 200;
} }
} }

View File

@@ -198,7 +198,7 @@ public class Events extends EventEmitter implements OnKeyListener, TouchObserver
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR2) @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public void observeNotification() { public void observeNotification() {
mScriptRuntime.requiresApi(18); ScriptRuntime.requiresApi(18);
if (mListeningNotification) if (mListeningNotification)
return; return;
mListeningNotification = true; mListeningNotification = true;