我尝试使用操作创建通知,但我无法将此行代码转换为Javascript:
Intent resultIntent = new Intent(this, ResultActivity.class);
来自https://developer.android.com/training/notify-user/build-notification.html
有人可以帮忙吗?或者有一个功能实例? 感谢
答案 0 :(得分:4)
有效!
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进行测试