Nativescript可以't使android通知操作正常工作

Nativescript can't get android notification action working

本文关键字:常工作 操作 工作 通知 android 可以 Nativescript      更新时间:2023-09-26

我试图创建一个带有操作的通知,但我无法将这行代码转换为Javascript:

Intent resultIntent = new Intent(this, ResultActivity.class);

发件人https://developer.android.com/training/notify-user/build-notification.html

有人能帮忙吗?或者有一个功能示例?感谢

它有效

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 进行测试