【问题标题】:Nativescript can't get android notification action workingNativescript 无法让 android 通知操作正常工作
【发布时间】:2015-07-03 21:21:48
【问题描述】:

我正在尝试使用操作创建通知,但我无法将这行代码转换为 Javascript:

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

来自https://developer.android.com/training/notify-user/build-notification.html

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

【问题讨论】:

    标签: 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 测试

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-28
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 2015-08-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多