2012-07-11 12 views
6

मैं अपने आवेदन के लिए एंड्रॉइड में स्थानीय अधिसूचना का उपयोग करना चाहता हूं। यदि स्थानीय अधिसूचना से 24 घंटे के लिए ऐप नहीं खोला जाता है। क्या कोई मुझे बता सकता है कि इसे कैसे किया जाना चाहिए।एंड्रॉइड में स्थानीय नोटिफिकेशन भेजना

+0

क्यों यू एक अलार्म – Zamani

+0

मुझे लगता है कि आप सेवा बनाने और उसके बाद समय की जाँच करनी चाहिए का उपयोग नहीं है, लेकिन अधिसूचना दिखाने के लिए यू इसके बारे में पढ़ने चाहिए। =) – Gorets

+0

गोरेट्स, आप बिल्कुल सही हैं, मुझे किसी प्रकार की सेवा का उपयोग करना होगा क्योंकि ऐप बंद होने पर अधिसूचना ट्रिगर की जाएगी। क्या आप मुझे –

उत्तर

4

देखें: Local Notifications in Android? आपको हर घंटे अलार्म प्रबंधक के साथ एक इरादा निर्धारित करने में सक्षम होना चाहिए।

+1

के लिए कुछ ट्यूटोरियल प्रदान कर सकते हैं त्वरित प्रतिक्रिया के लिए धन्यवाद लेकिन ऐप बंद होने पर अलार्म मैनेजर का उपयोग किया जा सकता है। ऐप बंद होने पर अधिसूचना कैसे ट्रिगर की जाएगी? –

+0

ऐप बंद होने पर भी अलार्म प्रबंधक का उपयोग किया जा सकता है। हालांकि ऐप इंस्टॉल होने पर आप अलार्म मैनेजर सेट करने में सक्षम नहीं होंगे, केवल तभी जब ऐप लोड हो जाए (कम से कम एक बार) (देखें: http://stackoverflow.com/a/8492846/986105)। अलार्म मैनेजर का उपयोग करके अधिसूचना बनाने के लिए इसे देखें: http://smartandroidians.blogspot.com/2010/04/alarmmanager-and-notification-in.html – KrispyDonuts

-1

आप शीर्षक के साथ एक अधिसूचना में बहु पाठ के साथ, बड़ा डेटा यानी के साथ स्थानीय अधिसूचना सक्रिय करना चाहते हैं, टिकर, आइकन, ध्वनि .. निम्न कोड का उपयोग करें .. मुझे लगता है कि .. यह तुम्हारी मदद करेगा

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



     notificationIntent.putExtra("clicked", "Notification Clicked"); 
     notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
       | Intent.FLAG_ACTIVITY_SINGLE_TOP); // To open only one activity 


      // Invoking the default notification service 

      NotificationManager mNotificationManager; 
      NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
        context); 
      Uri uri = RingtoneManager 
        .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
      mBuilder.setContentTitle("Reminder"); 
      mBuilder.setContentText("You have new Reminders."); 
      mBuilder.setTicker("New Reminder Alert!"); 
      mBuilder.setSmallIcon(R.drawable.clock); 
      mBuilder.setSound(uri); 
      mBuilder.setAutoCancel(true); 

      // Add Big View Specific Configuration 
      NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); 
      String[] events = null; 

       events[0] = new String("Your first line text "); 
       events[1] = new String(" Your second line text"); 



      // Sets a title for the Inbox style big view 
      inboxStyle.setBigContentTitle("You have Reminders:"); 

      // Moves events into the big view 
      for (int i = 0; i < events.length; i++) { 
       inboxStyle.addLine(events[i]); 
      } 

      mBuilder.setStyle(inboxStyle); 

      // Creates an explicit intent for an Activity in your app 
      Intent resultIntent = new Intent(context, 
        ReminderListActivity.class); 

      TaskStackBuilder stackBuilder = TaskStackBuilder 
        .create(context); 
      stackBuilder.addParentStack(ReminderListActivity.class); 


      // Adds the Intent that starts the Activity to the top of the stack 


      stackBuilder.addNextIntent(resultIntent); 
      PendingIntent resultPendingIntent = stackBuilder 
        .getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); 

      mBuilder.setContentIntent(resultPendingIntent); 
      mNotificationManager = (NotificationManager) context 
        .getSystemService(Context.NOTIFICATION_SERVICE); 


      // notificationID allows you to update the notification later on. 


      mNotificationManager.notify(999, mBuilder.build()); 
1
Intent intent = new Intent(context, yourActivity.class); 
    PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

    NotificationCompat.Builder b = new NotificationCompat.Builder(context); 

    b.setAutoCancel(true) 
    .setDefaults(Notification.DEFAULT_ALL) 
    .setWhen(System.currentTimeMillis())   
    .setSmallIcon(R.drawable.ic_launcher) 
    .setTicker("notification")    
    .setContentTitle("notification") 
    .setContentText("notification") 
    .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND) 
    .setContentIntent(pIntent) 
    .setContentInfo("Info"); 


    NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(1, b.build()); 
संबंधित मुद्दे