Skip to main content

Android Notifications

Android Notifications 


  • Introduction to android notifications in Hindi
  • Contents of android notifications in Hindi
  • Creating android notifications in Hindi
  • Taking actions with notifications in Hindi

Introduction to Android Notifications 

Notifications आपके device में top पर battery और signal icons के पास show होते है। आपने देखा होगा जैसे ही आपके device पर कोई mail या text message आता है तो top पर एक message icon शो होता है। ये messages notifications कहलाते है।     

जब भी कोई notification आता है तो सबसे पहले उसका icon show होता है। जैसे की कोई mail आया तो Gmail का icon शो होगा। इसके बाद यदि यूज़र उस notification के बारे में detail जानना चाहता है तो वो notification drawer को open करता है। 

ज्यादातर devices में notification drawer जब यूज़र top से bottom की तरफ swipe करता है तो open हो जाता है। Notification drawer को यूज़र कभी भी देख सकता है। इसमें कुछ दूसरी settings भी होती है जैसे की WiFi, Bluetooth, screen brightness आदि। 

आप चाहे तो notification के माध्यम से कोई action भी ले सकते है। जैसे की जब यूज़र notification पर click करे तो आपकी application open हो जाये। जँहा यूज़र दूसरे actions ले सकता है।


Contents of Android Notification 

  • Icon - ये एक छोटा सा icon होता है जो notification से related एप्लीकेशन को represent करता है   
  • Title  - ये notification का title होता है जो notification का purpose शो करता है। 
  • Detail text - ये detailed text message होता है।   

Creating a Notification      

एक notification क्रिएट करने के लिए सबसे पहले आप NotificationCompat.Builder क्लास का object क्रिएट करते है। ये एक public static क्लास है। आसानी से notifications क्रिएट करने के लिए ये एक builder क्लास है। इसमें आप current activity का reference पास करते है।

इसके बाद आप इस builder क्लास के object के माध्यम से notification के contents सेट करेंगे। Icon set करने के लिए setSmallIcon() method कॉल करेंगे और इसमें icon का एड्रेस पास करेंगे। Notification का title सेट करने के लिए आप setContentTitle() method कॉल करते है और इसमें title string पास करते है। Detailed  message set करने के लिए setContentText() method कॉल करते है और इसमें text string पास करते है।
        
इसके बाद आप NotificationCompat.Builder क्लास के object पर build() method कॉल करते है। ये method एक notification return करता है। जो notification ये method return करता है तो  वो उन्हीं contents के साथ loaded होता है जो आपने set किये थे।

सबसे आखिर में notification को issue करने के लिए आप build method ने जो notification object return किया है उसे notify() मेथड में पास करते है। इस मेथड को NotificationManager क्लास के object पर कॉल करते है।

NotificationCompat.Builder ncb = new NotificationCompat.Builder(this); // crating builder class object

ncb.setSmallIcon(R.drawable.yricon); // setting icon

ncb.setContentTitle("your notification title"); //setting title
ncb.setContextText("your notification message");// setting text

Notification noti = ncb.build(); //creating notification 


NotificationManager nm = new NotificationManager(); 


nm.notify(noti); //showing notification





Taking Actions with Notification 

Android notifications के साथ action लेना optional है। आप चाहे तो एक simple text message शो कर सकते है या फिर जब यूज़र notification पर क्लिक करे तो कोई notification ले सकते है। जैसे की action के माध्यम से आप notification drawer से यूज़र को अपनी एप्लीकेशन में भेज सकते है।

Notification के माध्यम से आप कई प्रकार के action ले सकते है। आप चाहे तो notification में button भी provide कर सकते है। जिसे press करने पर आपकी application बिना open हुए कुछ एक्शन perform करती है।

जब यूज़र notification पर click करे तो application को open करना सबसे common एक्शन है। इस action के लिए आप builder क्लास के object पर setContentIntent() मेथड कॉल करते है और उसमे PendingIntent क्लास का ऑब्जेक्ट पास करते है। PendingIntent क्लास का object क्रिएट करते समय आप उसमे normal intent का object पास करते है। ये intent ही application को open करने के action को define करता है।

Intent yrIntent = new Intent(this,yrActivity.class);

pendingIntent pi = new pendingIntent(yrIntent);


ncb.setContentIntent(pi); 

Comments

Popular posts from this blog

Android Services

Android Services Introduction to  android services in Hindi  Declaring  services in Hindi Creating a  android service in Hindi Introduction to Android Services इससे पहले की आप जाने की service क्या होती है आइये जानते है की service क्या नहीं होती है - एक service separate प्रोसेस नहीं होती है। ये आपकी एप्लीकेशन का ही पार्ट होती है।  एक service thread नहीं होती है।  आइये अब देखते है service क्या होती है - Service एक facility होती है जिससे आप android system को बता सकते है की आप कोई काम background में करते रहना चाहते है।  Service एक facility होती है जिससे एक एप्लीकेशन अपनी कुछ functionality दूसरी applications को expose कर सकती है।    हर service क्लास का <service> declaration AndroidManifest.xml file में होना चाहिए। Services को आप context.startService() और context.bindService() मेथड्स से स्टार्ट कर सकते है।            जब service component क्रिएट होता है तो android syst...

Android Activity

Android Activity Activity life cycle in Hindi Starting an  android activity in Hindi Creating a new activity in Hindi Destroying an  android activity in Hindi Introduction to Activity आप की application में एक से ज्यादा activity हो सकती है। जब आप इन activities के through navigate करते है, यानि एक activity से दूसरी activity में जाते है तो activity अपनी life cycle की different stages में जाती है। उदाहरण के लिए जब आपकी activity start होती है तो ये foreground में होती है और user का पूरा focus इस पर होता है। इस process के दौरान  android  system कुछ life cycle methods को call करता है। यदि user कोई दूसरी activity start करता है तो android system उस activity के life cycle methods को call करता है और आपकी पहले वाली activity background में चली जाती है। life cycle methods में आप decide कर सकते है की जब user जाता है या वापस आता है तो आपकी activity कैसे behave करेगी।  उदाहरण के लिए यदि आप एक वीडियो player बना रहे है तो जब user किसी दूसरी activity पर जाये तो...

Android Spinners

Android Spinners  Introduction to  android spinners in Hindi Defining  android spinners in Hindi Creating spinner items array in Hindi Responding to spinner selections in Hindi    Introduction to Android Spinners Android spinners आपकी एप्लीकेशन में एक drop down menu होती है। इस drop down menu में बहुत से items होते है जिन्हे user choices कहते है। जब user spinner पर क्लिक करता है तो ये items शो होते है। यूज़र अपने लिए appropriate choice choose करता है। By default spinner में सबसे top वाला element शो होता है। Spinners को XML layout file में क्रिएट किया जाता है। और items की लिस्ट string resource file में क्रिएट की जाती है। जिसमे आप एक string array क्रिएट करते है।  Spinner और items को जोड़ने के लिए एक array adapter क्रिएट किया जाता है। इसके बाद selection events को respond करने के लिए OnItemSelectedListener interface को  इम्प्लीमेंट किया जाता है।  Defining Android Spinners Android spinners को आप XML l...