2016-08-02 50 views
0

我已經創建了一個應用程序來運行連接到HC-06 module.and還有brodcastlistener,它偵聽特定的SMS並從我的app生成通知。當我單擊通知時,它應該加載應用程序活動但我的應用程序總是在連接到bluetooth時運行。但是當點擊通知時,我想在同一個應用程序中啓動一個活動。我可以這樣做嗎?開始活動沒有藍牙

+0

鉤了的PendingIntent作爲contentIntent的通知 –

+0

當我們implemet的PendingIntent可以請你分享一個鏈接發生什麼 –

+0

嘗試下一次搜索自己https://developer.android.com/training/notify-user/集結notification.html#點擊 –

回答

0
NotificationManager notificationManager = (NotificationManager) context 
      .getSystemService(Context.NOTIFICATION_SERVICE); 
    Notification notification = new Notification(icon, message, when); 

    Intent notificationIntent = new Intent(context, HomeActivity.class); 

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
      | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

    PendingIntent intent = PendingIntent.getActivity(context, 0, 
      notificationIntent, 0); 

    notification.setLatestEventInfo(context, title, message, intent); 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 
    notificationManager.notify(0, notification);