2014-03-26 5 views
0

이 앱을 제작 중입니다. 내가하고 싶은 일은 버튼 클릭으로 알림 막대에 내 활동 아이콘을 표시하는 것입니다. 다른 사건이 끝날 때까지 거기에 머물러 있기를 바랍니다. 현재이 코드를 dound하지만 친절하게 나에게이 작업을 수행하는 쉬운 방법을 말해, 오류를 많이 제공 :알림 바에 앱 아이콘 표시

save.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       if(icon.isChecked()) { 
        CharSequence text = getText(R.string.local_service_started); 

        // Set the icon, scrolling text and timestamp 
        Notification notification = new Notification(R.drawable.ic_launcher, "Track Your Life", System.currentTimeMillis()); 

        // The PendingIntent to launch our activity if the user selects this notification 
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
          new Intent(), 0); 

        // Set the info for the views that show in the notification panel. 
        notification.setLatestEventInfo(this, getText(R.string.local_service_label), text, contentIntent); 

        // Send the notification. 
        mNM.notify(NOTIFICATION, notification); 
       } 

      } 
     }); 
+0

당신이 원하는 것을 인쇄 화면을 추가 달성 –

+0

단순히 내 알림 아이콘에 내 앱의 아이콘을 남기고 싶습니다. 온라인 상태에서 Whatsapp 또는 skype 아이콘을 좋아하세요. –

+0

"많은 오류"가 무엇을 의미하는지 ** 완전하고 정확하게 ** 설명하십시오. 또한'Notification.Builder' 나'NotificationCompat.Builder'를 직접 쓰는 대신'Notification.Builder'를 사용하는 것이 좋습니다. – CommonsWare

답변

0
아이콘으로 알림을 생성하기위한

간단한 코드

Intent intentSetDefault = new Intent(mContext, ConversationListActivity.class); 
     PendingIntent piSetDeafult = PendingIntent.getActivity(mContext, 0, intentSetDefault, 
       PendingIntent.FLAG_UPDATE_CURRENT); 
     // create pending intent for action discard 
     Intent intentdiscard = new Intent(mContext, NotificationReceiver.class).setType(CODE_DISCARD); 
     PendingIntent piDiscard = PendingIntent.getBroadcast(mContext, 0, intentdiscard, 
       PendingIntent.FLAG_UPDATE_CURRENT); 

    Notification.Builder mBuilder = 
        new Notification.Builder(mContext) 
          .setTicker(title) 
          .setSmallIcon(R.drawable.ic_stat_notify_incoming_msg) 
          .setContentTitle(title) 
          .setContentText(text) 
          .setLargeIcon(mAppBitmap) 
          .setContentInfo(Integer.toString(smsCount)) 
          .setPriority(Notification.PRIORITY_MAX) 
          .setDefaults(Notification.DEFAULT_ALL) 
          .setAutoCancel(false); 

      mBuilder.setContentIntent(piSetDeafult); 

      Notification notification = mBuilder.build(); 
      notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; 

      mNotifyMgr.notify(NOTIFICATION_SET_DEFAULT, notification); 
+0

mContext, piSetDefault, mNotifyMgr을 찾을 수 없음 –

+0

해당 구성원 컨텍스트가 단순 컨텍스트이고 notifyMgr이 관리자임을 알리는 추가 –

관련 문제