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 पर कॉल करते है।
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 करता है।
pendingIntent pi = new pendingIntent(yrIntent); ncb.setContentIntent(pi); |

Comments
Post a Comment