Titanium Android模块:通知点击不显示任何内容

时间:2014-04-10 13:27:23

标签: android notifications titanium android-pendingintent titanium-modules

我正在为钛应用程序编写Android模块。我在进入信标区域时添加通知(可能不相关)。我从模块类(KrollModule的子类)发出通知。

问题是:当我点击通知时它什么也没做!它只取消通知。

这是我的代码:

private void postNotification(String msg) {
    Intent notifyIntent = new Intent(context, TiApplication.getInstance().getCurrentActivity().getClass());
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(
            context,
            0,
            notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    Notification notification = new NotificationCompat.Builder(context)
    .setSmallIcon(R.drawable.ic_notification_overlay)
    .setContentTitle("Notify Demo")
    .setContentText(msg)
    .setAutoCancel(true)
    .setContentIntent(pendingIntent)
    .build();
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notificationManager.notify(NOTIFICATION_ID, notification);

    try {
        beaconManager.stopMonitoring(region);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    beaconManager.disconnect();

}

这是日志:

W/ActivityManager(755): Permission Denial: starting Intent { flg=0x20000000 cmp=com.....banking/org.appcelerator.titanium.TiActivity bnds=[0,153][1080,345] } from null (pid=-1, uid=10360) not exported from uid 10367
V/PanelView(868): animationTick called with dtms=0; nothing to do (h=1776.0 v=-6000.0)
W/ActivityManager(755): Unable to send startActivity intent
W/ActivityManager(755): java.lang.SecurityException: Permission Denial: starting Intent { flg=0x20000000 cmp=com.....banking/org.appcelerator.titanium.TiActivity bnds=[0,153][1080,345] } from null (pid=-1, uid=10360) not exported from uid 10367
W/ActivityManager(755):     at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1186)
W/ActivityManager(755):     at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:741)
W/ActivityManager(755):     at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:3300)
W/ActivityManager(755):     at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:252)
W/ActivityManager(755):     at com.android.server.am.PendingIntentRecord.send(PendingIntentRecord.java:192)
W/ActivityManager(755):     at android.content.IIntentSender$Stub.onTransact(IIntentSender.java:64)
W/ActivityManager(755):     at android.os.Binder.execTransact(Binder.java:404)
W/ActivityManager(755):     at dalvik.system.NativeStart.run(Native Method)

我能看到的问题在于我如何创建PendingIntent ...我希望当用户点击通知时它会打开应用程序。无论如何或在哪里......它可以在用户离开的活动,登录页面,启动页面等等。

有什么建议吗?感谢

1 个答案:

答案 0 :(得分:1)

经过一些(大量)搜索和工作后,我找到了一个有效的解决方案(对其他人有用)。

问题是TiApplication.getInstance().getCurrentActivity().getClass() ......似乎在应用程序运行的这个时候仍然没有Activity

使用TiApplication.getAppRootOrCurrentActivity().getClass()修复了获取应用根活动的问题。