【问题标题】:Nativescript can't get android notification action workingNativescript 无法让 android 通知操作正常工作
【发布时间】:2015-07-03 21:21:48
【问题描述】:
【问题讨论】:
标签:
javascript
android
nativescript
【解决方案1】:
有效!
var app = require('application');
var packageName = app.android.context.getPackageName();
var launchIntent = app.android.context.getPackageManager().getLaunchIntentForPackage(packageName);
var className = launchIntent.getComponent().getClassName();
var tns = className + '.class';
var intent = new android.content.Intent(app.android.context, eval(tns));
var pIntent = android.app.PendingIntent.getActivity(app.android.context, 0, intent, 0);
var resImg = app.android.context.getResources().getIdentifier('icon' , 'drawable', app.android.context.getPackageName());
var mBuilder = new android.support.v4.app.NotificationCompat.Builder(app.android.context);
mBuilder.setSmallIcon(resImg);
mBuilder.setContentTitle('My notification');
mBuilder.setContentText('Hello World!');
mBuilder.addAction(resImg, 'see', pIntent);
var mNotificationId = 001;
var sytemservice = app.android.context.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
sytemservice.notify(mNotificationId, mBuilder.build());
使用模拟器 android 4.2.2 测试