0

我正在爲鈦應用程序編寫Android模塊。我添加了一個通知,告訴我們什麼時候進入燈塔區域(可能不相關)。我正在從模塊類(KrollModule的子類)發出我的通知。Titanium Android模塊:通知單擊不顯示任何內容

問題是:當我點擊通知它什麼都不做!它只會取消通知。

這裏是我的代碼:

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

經過一番(很多)的搜索和工作後,我發現了一個可行的解決方案(並且可以對其他人有用)。

問題是TiApplication.getInstance().getCurrentActivity().getClass() ...它似乎在這個應用程序運行的時候仍然沒有Activity

使用TiApplication.getAppRootOrCurrentActivity().getClass()解決了獲取應用程序的根活動的問題。