Related Topics

What is Mobile Computing in Hindi?

Brief history of mobile technology in Hindi

Mobile Phone Generations in Hindi

The Mobile Ecosystem in Hindi

Types of Mobile Applications in Hindi

Mobile Information Architecture in Hindi

Android Versions in Hindi

Features of Android in Hindi

Android Architecture in Hindi

Installing Android SDK Tools in Hindi

Configuring Android in Eclipse IDE in Hindi

Android Development Tools (ADT) in Hindi

Creating Android Virtual Devices (AVD) in Hindi

Creating First Android Application in Hindi

Anatomy of Android Application in Hindi

Deploying Android App on USB Connected Android Device in Hindi

Android Activity Life Cycle in Hindi

Android Activities in Hindi

Exploring Intent Objects in Hindi

Linking Activities Using Intents in Hindi

Android Fragment Lifecycle in Hindi

Android UI Layouts in Hindi

Adapting to Display Orientation in Android in Hindi

Action Bar in Android in Hindi

Android Alarm Manager in Hindi

Displaying Analog & Digital Clocks in Android in Hindi

Event Handling in Android in Hindi

Android Menus in Hindi

Data Storage Options in Android in Hindi

External Storage in Android in Hindi

Content Providers in Android in Hindi

Views in Android in Hindi

Button in Android in Hindi

Toast in Android in Hindi

ToggleButton in Android in Hindi

CheckBox in Android in Hindi

RadioButton in Android in Hindi

Spinner in Android in Hindi

WebView in Android in Hindi

EditText in Android in Hindi

DatePicker in Android in Hindi

TimePicker in Android in Hindi

ListView in Android in Hindi

ProgressBar in Android in Hindi

Handling UI Events in Android in Hindi

ListFragment in Android in Hindi

DialogFragment in Android in Hindi

Context in Android in Hindi

Popup in Android in Hindi

ImageView in Android in Hindi

ImageSwitcher in Android in Hindi

AlertDialog in Android in Hindi

AlarmManager in Android in Hindi

SMS in Android in Hindi

E-mail in Android in Hindi

MediaPlayer in Android in Hindi

Using Camera in Android in Hindi

Video Recording in Android in Hindi

Telephony Manager in Android in Hindi

Android SQLite Database in Hindi

SQLite database operations in Hindi

Publishing Android Applications in Hindi

Deploying APK Files in Android in Hindi

Related Subjects

Android Application Components in Hindi

RGPV University / DIPLOMA_CSE / MOBILE COMPUTING

Android Application Components in Hindi

Android एक बहुत ही पॉपुलर मोबाइल ऑपरेटिंग सिस्टम है, जिसमें कई महत्वपूर्ण एप्लिकेशन कंपोनेंट्स होते हैं। ये कंपोनेंट्स किसी भी ऐप के फंक्शनलिटी को निर्धारित करते हैं और यूज़र इंटरैक्शन को आसान बनाते हैं। इस ब्लॉग में हम Android Activity, Service, Intents, Broadcast Receiver, Content Provider, Widgets और Notifications के बारे में विस्तार से जानेंगे। तो चलिए बिना देरी किए शुरुआत करते हैं!

Android Application Components in Hindi

अगर आप Android App Development सीख रहे हैं, तो आपको इसके Application Components के बारे में जरूर जानना चाहिए। ये कंपोनेंट्स किसी भी ऐप के बिल्डिंग ब्लॉक्स होते हैं, जो यह तय करते हैं कि ऐप कैसे काम करेगा। Android में कुल 5 मुख्य Application Components होते हैं: Activity, Service, Broadcast Receiver, Content Provider और Intents ।

हर एक कंपोनेंट का अपना एक अलग उद्देश्य होता है। जैसे Activity UI को कंट्रोल करती है, Service बैकग्राउंड में काम करने वाले प्रोसेस को मैनेज करता है, और Broadcast Receiver सिस्टम या अन्य ऐप्स से आने वाले संदेशों को प्रोसेस करता है।

इस ब्लॉग में, हम इन सभी Android Application Components को डिटेल में, आसान भाषा में और एकदम फ्रेंडली तरीके से समझेंगे, ताकि आपको ये हमेशा के लिए याद रह जाएं! 🚀

1. Android Activity in Hindi

Activity Android ऐप का सबसे महत्वपूर्ण कंपोनेंट है, क्योंकि यही वह स्क्रीन होती है जिससे यूजर इंटरैक्ट करता है। हर बार जब आप अपने फोन में कोई ऐप खोलते हैं, तो असल में एक Activity ही रन हो रही होती है।

उदाहरण के लिए, जब आप WhatsApp खोलते हैं, तो जो पहली स्क्रीन दिखती है, वह एक Activity होती है। फिर जब आप किसी दोस्त की चैट खोलते हैं, तो वह दूसरी Activity होती है।

Activity को हम Java या Kotlin में कोड करके बनाते हैं, और इसे AndroidManifest.xml में डिफाइन करना जरूरी होता है। हर Activity का एक Lifecycle होता है, जो तय करता है कि कब वह शुरू होगी, कब रुकेगी और कब पूरी तरह से खत्म होगी।

2. Android Service in Hindi

Service एक ऐसा कंपोनेंट है जो बैकग्राउंड में बिना किसी यूजर इंटरैक्शन के काम करता है। उदाहरण के लिए, जब आप Spotify पर कोई गाना प्ले करते हैं और फिर होम स्क्रीन पर चले जाते हैं, तो भी गाना बजता रहता है। यह Android Service की वजह से होता है।

Service दो प्रकार की होती हैं:

  • Foreground Service: जो लगातार काम करती है और नोटिफिकेशन दिखाती है, जैसे Music Player।
  • Background Service: जो यूजर के बिना देखे बैकग्राउंड में प्रोसेस करती है, जैसे Auto-Sync।
Service का इस्तेमाल तब किया जाता है जब किसी ऐप को लगातार कोई काम करना हो, जैसे File Upload, Location Tracking या Data Syncing ।

3. Android Intents in Hindi

Intent एक मैसेजिंग सिस्टम होता है जो Android Components को एक-दूसरे से जोड़ता है। जब भी आपको एक Activity से दूसरी Activity पर जाना हो, तो Intent का इस्तेमाल किया जाता है।

उदाहरण के लिए, अगर आप Gallery App में कोई फोटो खोलकर उसे WhatsApp पर शेयर करते हैं, तो Intent ही यह प्रोसेस मैनेज करता है।

Intent दो प्रकार के होते हैं:

  • Explicit Intent: जब आपको पता हो कि आपको किस Activity या Service को स्टार्ट करना है।
  • Implicit Intent: जब आप Android को बताते हैं कि आपको क्या काम करवाना है, लेकिन यह नहीं बताते कि कौन सा ऐप इसे करेगा। जैसे "Share" ऑप्शन।
Intent का इस्तेमाल Navigation, Data Transfer और System Events को हैंडल करने के लिए किया जाता है।

4. Android Broadcast Receiver in Hindi

Broadcast Receiver एक ऐसा कंपोनेंट है जो Android System या अन्य ऐप्स से आने वाले मैसेज या इवेंट्स को प्रोसेस करता है।

उदाहरण के लिए, जब आपके फोन की बैटरी Low हो जाती है, तो एक Notification आती है। यह Android System द्वारा भेजा गया एक Broadcast होता है , जिसे आपका फोन Broadcast Receiver के जरिए प्रोसेस करता है।

Broadcast Receiver का उपयोग Battery Status, Network Connectivity, Incoming Calls, SMS Received जैसे इवेंट्स को डिटेक्ट करने के लिए किया जाता है।

5. Android Content Provider in Hindi

Content Provider का उपयोग Apps के बीच Data Sharing के लिए किया जाता है। अगर एक ऐप को किसी दूसरे ऐप के डेटा की जरूरत होती है, तो यह Content Provider के जरिए संभव होता है।

उदाहरण के लिए, जब आप अपने Contacts को WhatsApp में एक्सेस करते हैं, तो WhatsApp आपके फोन के Contacts App के Content Provider से Data लेता है।

Content Provider SQLite Database, Files और Web से भी Data Access कर सकता है।

6. Android Widgets in Hindi

Widgets वे छोटे UI Components होते हैं जो Home Screen पर कुछ जरूरी जानकारी दिखाते हैं।

उदाहरण के लिए, Clock Widget, Weather Widget, Music Widget और Google Search Bar ।

Widgets का उपयोग Quick Access, Live Updates और Shortcuts के लिए किया जाता है।

7. Android Notifications in Hindi

Notification System वह फीचर है जो किसी ऐप की महत्वपूर्ण जानकारी को यूजर तक पहुँचाता है।

उदाहरण के लिए, जब आपको WhatsApp पर Message आता है, तो आपको एक Notification Bar में Popup दिखता है।

Notifications को तीन भागों में बांटा जा सकता है:

  • Basic Notification: सिर्फ एक छोटा Text और Icon होता है।
  • Expandable Notification: जिसमें Image और Action Buttons होते हैं।
  • Heads-up Notification: जो स्क्रीन के ऊपर Pop-up के रूप में आता है।

Android Activity in Hindi

अगर आप Android App Development सीख रहे हैं, तो आपको Activity के बारे में जरूर जानना चाहिए। Activity वह स्क्रीन होती है जिससे यूजर डायरेक्ट इंटरैक्ट करता है। जब आप किसी ऐप को खोलते हैं, तो पहली चीज़ जो दिखाई देती है, वह एक Activity होती है।

उदाहरण के लिए, जब आप WhatsApp खोलते हैं, तो जो चैट लिस्ट स्क्रीन दिखाई देती है, वह एक Activity है। जब आप किसी दोस्त की चैट खोलते हैं, तो वह दूसरी Activity होती है। Activity का मुख्य काम UI को नियंत्रित करना और यूजर के इनपुट को प्रोसेस करना होता है।

इस ब्लॉग में हम Android Activity को पूरी गहराई से समझेंगे, ताकि आपको यह एकदम क्लियर हो जाए कि Activity क्या होती है, यह कैसे काम करती है और इसका Lifecycle कैसा होता है। 🚀

1. Android Activity क्या होती है?

Activity एक User Interface (UI) Screen होती है जो यूजर के साथ इंटरैक्ट करती है। हर Android App में कम से कम एक Activity जरूर होती है।

उदाहरण के लिए, Facebook खोलते ही जो Home Feed दिखता है, वह एक Activity है। जब आप किसी का प्रोफाइल खोलते हैं, तो वह दूसरी Activity होती है।

Activity में Buttons, Text Fields, Images और अन्य UI Components हो सकते हैं, जिनसे यूजर इंटरेक्ट कर सकता है।

2. Android Activity कैसे काम करती है?

जब कोई ऐप शुरू होता है, तो Android सिस्टम सबसे पहले उसकी Main Activity को लोड करता है।

एक Activity को Java या Kotlin में कोड करके बनाया जाता है , और इसे AndroidManifest.xml फाइल में डिक्लेयर करना जरूरी होता है।

जब यूजर किसी बटन को क्लिक करता है, या किसी इवेंट को ट्रिगर करता है, तो Activity उसका रिस्पॉन्स देती है और यूजर को अगले स्टेप तक पहुंचाती है।

3. Android Activity का Lifecycle

हर Activity का अपना एक Lifecycle होता है, जिससे यह तय होता है कि Activity कब शुरू होगी, कब रुकेगी और कब पूरी तरह से खत्म हो जाएगी।

Activity के Lifecycle को Android System खुद Manage करता है , और यह कुछ Predefined Methods के जरिए कंट्रोल किया जाता है।

Lifecycle Method काम
onCreate() जब Activity पहली बार Create होती है, तब यह Method Call होती है।
onStart() जब Activity यूजर के लिए विजिबल होने लगती है, तब यह Method Execute होती है।
onResume() जब Activity पूरी तरह से यूजर के साथ इंटरैक्ट करने के लिए तैयार होती है, तब यह Call होती है।
onPause() जब Activity बैकग्राउंड में जाती है, लेकिन अभी भी खत्म नहीं हुई है, तब यह Method चलती है।
onStop() जब Activity पूरी तरह से बंद हो जाती है और विजिबल नहीं होती, तब यह Method Call होती है।
onDestroy() जब Activity पूरी तरह से खत्म हो जाती है और सिस्टम उसे मेमोरी से हटा देता है, तब यह Method Execute होती है।

4. Android Activity का Example

अब हम एक Simple Android Activity का Java Code देखेंगे, जिससे आपको क्लियर हो जाएगा कि Activity कैसे बनती है।

package com.example.myfirstapp; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }

इस Code में onCreate() Method का उपयोग किया गया है, जो Activity की Starting Point होती है।

setContentView(R.layout.activity_main); का मतलब है कि यह Activity activity_main.xml Layout File का उपयोग कर रही है।

Android Service in Hindi

Android Service एक बहुत ही महत्वपूर्ण Component है, जो Background में काम करता है और यूजर के साथ डायरेक्ट इंटरैक्ट नहीं करता।

जब आप Spotify या YouTube Music में कोई गाना प्ले करते हैं और ऐप को बंद कर देते हैं, फिर भी गाना बजता रहता है। यह काम Android Service के कारण संभव होता है।

अगर आपका ऐप में कोई ऐसा काम है, जो Background में चलता रहना चाहिए, जैसे कि File Download, Notifications Handle करना, या Location Track करना , तो उसके लिए Service का इस्तेमाल किया जाता है।

1. Android Service क्या होती है?

Service एक Android Component है, जो बिना किसी UI (User Interface) के Background में काम करता है।

जब यूजर कोई ऐप खोलता है, तब Activity काम करती है, लेकिन जब कोई प्रोसेस बिना स्क्रीन पर दिखे चलता है, तब Service काम में आती है।

उदाहरण के लिए, जब आप Google Drive में कोई फाइल अपलोड करते हैं और ऐप को बंद कर देते हैं, तब भी अपलोड चलता रहता है। यह Service की वजह से होता है।

2. Android Service के प्रकार

Android में Services को तीन मुख्य भागों में बांटा गया है:

  • Foreground Service - यह User को Notify करती रहती है, जैसे कि Music Player की Service।
  • Background Service - यह बिना किसी Notification के Background में काम करती है, जैसे कि File Downloading ।
  • Bound Service - यह किसी दूसरे Component से Bind होती है और जब तक वह Component एक्टिव रहता है, तब तक यह Service भी काम करती है।

3. Android Service कैसे काम करती है?

Service को स्टार्ट करने के लिए startService() Method का इस्तेमाल किया जाता है, और इसे रोकने के लिए stopService() Method का उपयोग किया जाता है।

Bound Service को bindService() Method से स्टार्ट किया जाता है, और इसे बंद करने के लिए unbindService() Method का प्रयोग किया जाता है।

जब भी कोई Service स्टार्ट होती है, तो onCreate() , onStartCommand() , और onDestroy() जैसे Methods Execute होते हैं।

4. Android Service Lifecycle

Service का अपना एक Lifecycle होता है, जिससे यह तय होता है कि Service कब शुरू होगी, कब बंद होगी और कब Destroy होगी।

Android में Service के Lifecycle Methods कुछ इस प्रकार होते हैं:

Method काम
onCreate() जब Service पहली बार Create होती है, तब यह Method Call होती है।
onStartCommand() जब Service स्टार्ट होती है, तब यह Method Execute होती है।
onBind() जब कोई Component Service से Bind होता है, तब यह Method Call होती है।
onUnbind() जब कोई Component Service से Unbind होता है, तब यह Method Execute होती है।
onDestroy() जब Service पूरी तरह से बंद हो जाती है, तब यह Method Call होती है।

5. Android Service का Example

अब हम एक Simple Android Service का Java Code देखेंगे, जिससे आपको क्लियर हो जाएगा कि Service कैसे बनती है।

package com.example.myservice; import android.app.Service; import android.content.Intent; import android.os.IBinder; import androidx.annotation.Nullable; public class MyService extends Service { @Override public void onCreate() { super.onCreate(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { return START_STICKY; } @Override public void onDestroy() { super.onDestroy(); } @Nullable @Override public IBinder onBind(Intent intent) { return null; } }

इस Code में हमने onStartCommand() Method का उपयोग किया है, जिससे Service Background में चलती रहती है।

जब Service पूरी तरह बंद हो जाती है, तब onDestroy() Method Call होता है, जिससे Service को System से Remove कर दिया जाता है।

Android Intents in Hindi

Android Intent एक बहुत ही ज़रूरी Component है, जो एक Activity से दूसरी Activity या एक App से दूसरे App के बीच Communication करने का काम करता है।

जब आप अपने फोन में Gallery से कोई Image चुनकर उसे WhatsApp पर Share करते हैं, तो यह काम Intent की मदद से होता है।

Intent का इस्तेमाल Data Transfer, App Navigation, और System Functions (जैसे Call या Message Send करना) के लिए किया जाता है।

1. Android Intent क्या होती है?

Intent का मतलब होता है "इरादा" , और Android में इसका उपयोग एक Component से दूसरे Component को Action Perform करवाने के लिए किया जाता है।

जब आप Login Screen से Home Screen पर जाते हैं या कोई Web Page Open करते हैं , तो यह सब Intent के द्वारा ही संभव होता है।

Intent का मुख्य काम Different Components के बीच Communication करना है, जिससे Application ज़्यादा Dynamic और Interactive बनती है।

2. Android Intent के प्रकार

Intent मुख्य रूप से दो प्रकार की होती हैं:

  • Explicit Intent - जब हम Target Component (जैसे Activity या Service) का नाम पहले से जानते हैं और उसे Direct Call करते हैं, तब हम Explicit Intent का उपयोग करते हैं।
  • Implicit Intent - जब हमें नहीं पता कि कौन-सा Component Action Handle करेगा, लेकिन हम Android को बताते हैं कि हमें क्या करना है (जैसे Web Page Open करना), तब Implicit Intent का उपयोग किया जाता है।

3. Explicit Intent क्या होती है?

Explicit Intent तब उपयोग होती है, जब हमें यह पहले से पता हो कि कौन-सी Activity या Service को Start करना है।

उदाहरण के लिए, अगर हमें Login Activity से Home Activity पर जाना है , तो हम Explicit Intent का उपयोग करेंगे।

Intent intent = new Intent(MainActivity.this, HomeActivity.class); startActivity(intent);

इस Code में MainActivity से HomeActivity पर जाने के लिए Intent का उपयोग किया गया है।

यह Intent हमें Directly Targeted Component तक पहुंचाता है, इसलिए इसे Explicit Intent कहा जाता है।

4. Implicit Intent क्या होती है?

Implicit Intent तब उपयोग होती है, जब हमें नहीं पता कि कौन-सा Component हमारी Request Handle करेगा।

उदाहरण के लिए, अगर हम किसी Web Page को Open करना चाहते हैं, तो Android खुद तय करेगा कि कौन-सा Browser इसे Handle करेगा।

Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://www.google.com")); startActivity(intent);

इस Code में Intent.ACTION_VIEW का उपयोग किया गया है, जो Android को बताता है कि हमें Web Page Open करना है , लेकिन कौन-सा Browser इसे Handle करेगा, यह Android खुद तय करेगा।

5. Intent के महत्वपूर्ण Methods

Intent में कई Methods होते हैं, जिनका उपयोग हम विभिन्न कार्यों के लिए कर सकते हैं:

Method काम
putExtra(String key, Value value) Intent के माध्यम से Data पास करने के लिए उपयोग किया जाता है।
getStringExtra(String key) Intent से Data प्राप्त करने के लिए उपयोग किया जाता है।
setData(Uri uri) Intent के साथ कोई Data (जैसे URL) Set करने के लिए उपयोग किया जाता है।
setType(String type) Intent के माध्यम से File Type Specify करने के लिए उपयोग किया जाता है।

6. Intent से Data Transfer कैसे करें?

Intent का उपयोग करके हम एक Activity से दूसरी Activity में Data Send और Receive कर सकते हैं।

मान लीजिए, हमें MainActivity से SecondActivity में कुछ Data भेजना है, तो हम putExtra() Method का उपयोग करेंगे।

Intent intent = new Intent(MainActivity.this, SecondActivity.class); intent.putExtra("message", "Hello, Second Activity!"); startActivity(intent);

अब SecondActivity में हम इस Data को getIntent() Method से प्राप्त कर सकते हैं।

Intent intent = getIntent(); String message = intent.getStringExtra("message");

इस तरह हम Intent के माध्यम से Data Transfer कर सकते हैं, जिससे हमारे Apps ज़्यादा Dynamic और Interactive बनते हैं।

Android Broadcast Receiver in Hindi

Android Broadcast Receiver एक बहुत ही महत्वपूर्ण Component है, जो System या अन्य Applications से आने वाले Events को Listen करता है।

जब भी कोई महत्वपूर्ण Event (जैसे Battery Low, Internet Connected/Disconnected, SMS Received, Boot Completed) होता है, तो Broadcast Receiver उसे पकड़ता है और Automatically Code Execute करता है।

इसका उपयोग अक्सर Background Tasks और System Notifications को Manage करने के लिए किया जाता है।

1. Android Broadcast Receiver क्या है?

Broadcast Receiver एक ऐसा Component है, जो Android System या अन्य Applications से आने वाले Broadcasted Messages (Events) को पकड़ने का काम करता है।

जब भी कोई विशेष Event (जैसे फोन चार्जिंग पर लगाना, WiFi कनेक्ट करना, या SMS प्राप्त होना) होता है, तो Android इसे Broadcast करता है, और अगर हमारा Application इस Broadcast को Listen कर रहा है, तो वह Automatically Trigger हो जाता है।

2. Broadcast Receiver कैसे काम करता है?

जब Android System कोई महत्वपूर्ण Event Generate करता है, तो वह इसे Broadcast कर देता है। अगर हमारा Application इस Event को सुनने के लिए Register किया गया है , तो Broadcast Receiver इसे पकड़ लेता है और उससे संबंधित Code Execute करता है।

उदाहरण के लिए, मान लीजिए फोन की Battery 15% से कम हो जाती है , तो Android एक Broadcast Send करता है। हमारा Application इसे पकड़ सकता है और यूज़र को Battery Low Warning दिखा सकता है।

3. Android Broadcast Receiver के प्रकार

Broadcast Receiver मुख्य रूप से दो प्रकार के होते हैं:

  • Static Broadcast Receiver - इसे Manifest File में Declare किया जाता है, और यह तभी Trigger होता है, जब कोई Broadcast Send किया जाता है।
  • Dynamic Broadcast Receiver - इसे Runtime पर Programmatically Register किया जाता है, और इसे ज़रूरत के हिसाब से Start या Stop किया जा सकता है।

4. Static Broadcast Receiver कैसे बनाएं?

Static Broadcast Receiver बनाने के लिए हमें सबसे पहले एक Java/Kotlin Class बनानी होगी, जो BroadcastReceiver Class को Extend करेगी।

public class MyReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Battery Low Detected!", Toast.LENGTH_SHORT).show(); } }

अब इस Broadcast Receiver को AndroidManifest.xml में Register करना होगा।

इस Code में, BATTERY_LOW Event को Listen करने के लिए Broadcast Receiver को Register किया गया है। जब Battery Low होगी, तो यह Toast Message Show करेगा।

5. Dynamic Broadcast Receiver कैसे बनाएं?

Dynamic Broadcast Receiver को हम Runtime पर Register करते हैं, यानी जब App Run हो रहा होता है, तभी इसे Set किया जाता है।

BroadcastReceiver myReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Airplane Mode Changed!", Toast.LENGTH_SHORT).show(); } }; IntentFilter filter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); registerReceiver(myReceiver, filter);

इस Code में AIRPLANE_MODE_CHANGED Event को Listen किया गया है। जब भी Airplane Mode On या Off होगा, तो Toast Message Show होगा।

6. Broadcast Receiver के महत्वपूर्ण Methods

BroadcastReceiver Class में कुछ महत्वपूर्ण Methods होते हैं:

Method काम
onReceive(Context context, Intent intent) जब कोई Broadcast Receive होता है, तो यह Method Execute होता है।
abortBroadcast() Broadcast को रोकने के लिए उपयोग किया जाता है। (केवल Ordered Broadcasts में)
registerReceiver() Dynamic Broadcast Receiver को Register करने के लिए उपयोग किया जाता है।
unregisterReceiver() Broadcast Receiver को Unregister करने के लिए उपयोग किया जाता है।

Android Content Provider in Hindi

Android Content Provider एक बहुत ही महत्वपूर्ण Component है, जो एक Application के Data को दूसरी Applications के साथ Share करने की अनुमति देता है।

Android में Security और Data Encapsulation बहुत ज़रूरी होता है, इसलिए एक App सीधे किसी दूसरे App के Data को Access नहीं कर सकता। Content Provider इस समस्या को हल करता है, जिससे एक App दूसरे App के Database, Files, Contacts या अन्य Data को सुरक्षित तरीके से Access कर सकता है।

अगर आपने कभी Contacts App से किसी Messaging App में नंबर Share किया हो , तो आपने Content Provider का उपयोग किया है! 🚀

1. Android Content Provider क्या है?

Content Provider एक ऐसा Android Component है, जो एक Application के Data को दूसरे Application के साथ सुरक्षित तरीके से Share करता है।

यह SQL Database, Files, Shared Preferences या किसी अन्य Storage System में Store Data को CRUD (Create, Read, Update, Delete) Operations के साथ Manage करने की अनुमति देता है।

उदाहरण के लिए, जब आप WhatsApp पर Contact List देखते हैं , तो वह आपके फोन के Contacts Provider से Data Fetch करता है।

2. Content Provider कैसे काम करता है?

जब कोई Application किसी अन्य App के Data को Access करना चाहता है, तो उसे Content Provider का उपयोग करना पड़ता है।

Content Provider एक URI (Uniform Resource Identifier) के माध्यम से Data को Identify करता है। हर Content Provider का एक Unique URI होता है, जिससे उसे Identify और Access किया जा सकता है।

3. Content Provider के मुख्य कार्य

Content Provider मुख्य रूप से CRUD Operations को Handle करता है, जैसे कि:

  • Insert - नए Data को Store करने के लिए।
  • Query - पहले से मौजूद Data को Fetch करने के लिए।
  • Update - मौजूदा Data को Modify करने के लिए।
  • Delete - Data को Remove करने के लिए।

जब कोई App Content Provider से Data मांगता है, तो वह इन Operations में से किसी एक का उपयोग करता है।

4. Android में पहले से मौजूद कुछ Content Providers

Android पहले से ही कुछ In-built Content Providers Provide करता है, जिनका उपयोग हम अपने Apps में कर सकते हैं।

Content Provider काम
ContactsContract Contacts को Access करने के लिए।
MediaStore Images, Videos और Audio Files को Access करने के लिए।
CallLog Call History को Access करने के लिए।
CalendarContract Calendar Events को Manage करने के लिए।

5. Custom Content Provider कैसे बनाएं?

Custom Content Provider बनाने के लिए, हमें ContentProvider Class को Extend करना होता है और उसके कुछ महत्वपूर्ण Methods को Implement करना होता है।

public class MyContentProvider extends ContentProvider { @Override public boolean onCreate() { return true; } @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { return null; } @Override public Uri insert(Uri uri, ContentValues values) { return null; } @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { return 0; } @Override public int delete(Uri uri, String selection, String[] selectionArgs) { return 0; } }

इस Code में query, insert, update और delete Methods को Override किया गया है, जो Content Provider के Data को Manage करने के लिए ज़रूरी होते हैं।

6. Content Provider से Data Retrieve कैसे करें?

Content Resolver का उपयोग करके हम Content Provider से Data को Fetch कर सकते हैं।

Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { String contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); Log.d("Contact Name", contactName); }

यह Code फोन के Contacts Provider से Data Fetch करके Log में Print करता है।

Android Widgets in Hindi

Android Widgets एक खास प्रकार के User Interface (UI) Components होते हैं, जिन्हें सीधे Home Screen पर Mini Applications की तरह दिखाया जा सकता है।

आपने अपने फोन की स्क्रीन पर Clock, Weather, Calendar, या Music Player जैसे छोटे-छोटे Boxes देखे होंगे जो हमेशा Live Data दिखाते हैं। ये सभी Widgets होते हैं।

Widgets का मुख्य काम User Experience को बेहतर बनाना और बिना किसी App को खोले Important Information दिखाना होता है। 🚀

1. Android Widgets क्या हैं?

Widgets एक तरह के Small Applications होते हैं, जो Home Screen पर Dynamic Data दिखाते हैं।

इन्हें App के अंदर भी इस्तेमाल किया जा सकता है , लेकिन इनका मुख्य उपयोग Home Screen पर Quick Access देना होता है।

उदाहरण के लिए, Google Search Widget से आप सीधे Home Screen से कुछ भी सर्च कर सकते हैं बिना Google App को खोले।

2. Android Widgets के प्रकार

Android में मुख्य रूप से चार प्रकार के Widgets होते हैं:

  • Information Widgets - ये Real-time Data दिखाते हैं, जैसे Clock, Weather या News Widgets।
  • Collection Widgets - ये Multiple Items को List या Grid View में दिखाते हैं, जैसे Email या Gallery Widgets।
  • Control Widgets - ये किसी App के Actions को Control करते हैं, जैसे Music Player के Play/Pause बटन।
  • Hybrid Widgets - इनमें एक से ज्यादा Categories के Features होते हैं, जैसे Smart Home Control Widgets।

3. Android में Widget कैसे बनाएं?

Android में Widget बनाने के लिए , हमें AppWidgetProvider Class को Extend करना होता है और AppWidgetProviderInfo XML File Create करनी होती है।

public class MyWidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int appWidgetId : appWidgetIds) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); appWidgetManager.updateAppWidget(appWidgetId, views); } } }

इस Code में onUpdate() Method को Override किया गया है, जो Widget को हर बार Update करने के लिए जरूरी होता है।

4. Widget की XML File

हर Widget के लिए एक XML File बनानी होती है, जिसमें Widget का Size और Update Interval सेट किया जाता है।

इस XML में Widget की Width, Height, Update Time और Default Layout Define किया गया है।

5. Widget का Layout कैसे बनाएं?

Widget Layout बनाने के लिए हमें XML File में UI Design करना होता है।

इस Code में एक Simple Text Widget बनाया गया है, जो "Hello Widget!" टेक्स्ट दिखाएगा।

6. Widget को Manifest File में Register करना

AndroidManifest.xml में हमें Widget को Register करना जरूरी होता है।

इस Code में Widget को System के साथ Register किया गया है, ताकि Android उसे पहचान सके।

7. Widget Update करने के लिए Broadcast Receiver

अगर हम चाहते हैं कि हमारा Widget Automatically Update हो, तो हमें एक Broadcast Receiver बनाना होगा।

public class WidgetUpdateReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ComponentName thisWidget = new ComponentName(context, MyWidgetProvider.class); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget); appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_text); } }

इस Code में Broadcast Receiver बनाया गया है, जो Widget को Update करने का काम करता है।

Android Notifications in Hindi

Android Notifications एक बहुत महत्वपूर्ण फीचर है, जिससे Users को Important Alerts और Updates मिलते हैं बिना किसी App को Open किए।

जब आपके फोन में New Message, Email, या कोई App Update आता है, तो आपको एक Notification Bar में Pop-up दिखता है।

Android हमें Fully Customizable Notifications बनाने की सुविधा देता है, जिससे हम अपने Users को बेहतर Experience दे सकते हैं। 🚀

1. Android Notifications क्या हैं?

Notifications एक तरह के Pop-up Alerts होते हैं, जो Users को Important Information देते हैं जब वे App के बाहर होते हैं।

ये Status Bar में दिखते हैं और Users इन्हें Click करके सीधे App में जा सकते हैं।

उदाहरण के लिए, WhatsApp Message Notification हमें बताती है कि कोई नया Message आया है और हम उसपर Click करके उसे Read कर सकते हैं।

2. Android Notifications के प्रकार

Android में विभिन्न प्रकार के Notifications होते हैं:

  • Basic Notification - एक Simple Alert जिसमें Title, Message और Icon होता है।
  • Expandable Notification - जिसमें Extra Content, Image, या Multiple Actions हो सकते हैं।
  • Heads-up Notification - जो सीधे स्क्रीन पर Pop-up के रूप में दिखता है।
  • Progress Notification - जो किसी File Downloading या Process Progress को दिखाता है।
  • Custom Notification - जिसे Developers अपने हिसाब से Design कर सकते हैं।

3. Android में Notification कैसे बनाएं?

Notification बनाने के लिए , हमें NotificationCompat.Builder का उपयोग करना होता है और इसे NotificationManager के माध्यम से दिखाना होता है।

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "my_channel") .setSmallIcon(R.drawable.notification_icon) .setContentTitle("New Message") .setContentText("Hello! You have a new notification.") .setPriority(NotificationCompat.PRIORITY_DEFAULT); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build());

इस Code में setContentTitle(), setContentText(), और setPriority() का उपयोग किया गया है जिससे Notification का Title, Message और Priority सेट की जा सके।

4. Notification Channel क्या होता है?

Android 8.0 (Oreo) और उससे ऊपर के Versions में , हमें Notification Channels का उपयोग करना जरूरी होता है जिससे Users अपने हिसाब से Notifications को Manage कर सकें।

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CharSequence name = "My Channel"; String description = "Channel for Notifications"; int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel("my_channel", name, importance); channel.setDescription(description); NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); }

इस Code में NotificationChannel Create किया गया है, जिससे System इस Channel के अंदर आने वाले सभी Notifications को Manage कर सके।

5. Click पर Activity Open करना

अगर हम चाहते हैं कि Notification Click करने पर कोई Activity Open हो , तो हमें PendingIntent का उपयोग करना होगा।

Intent intent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "my_channel") .setSmallIcon(R.drawable.notification_icon) .setContentTitle("New Message") .setContentText("Tap to open the app") .setContentIntent(pendingIntent) .setAutoCancel(true); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build());

इस Code में PendingIntent का उपयोग किया गया है, जिससे जब User Notification पर Click करे, तो MainActivity Open हो जाए।

6. Progress Notification

अगर हमें किसी Process का Progress दिखाना है , तो हम setProgress() Method का उपयोग कर सकते हैं।

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "my_channel") .setSmallIcon(R.drawable.notification_icon) .setContentTitle("Downloading...") .setContentText("Download in progress") .setProgress(100, 50, false); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(2, builder.build());

इस Code में Progress Bar Add किया गया है, जो Downloading के Progress को दिखाता है।

7. Custom Notification Layout

हम Custom Notification Layout भी बना सकते हैं, जिसमें हमारा खुद का UI Design होगा।

RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.custom_notification); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "my_channel") .setSmallIcon(R.drawable.notification_icon) .setCustomContentView(notificationLayout) .setStyle(new NotificationCompat.DecoratedCustomViewStyle()); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(3, builder.build());

इस Code में एक Custom Layout Create किया गया है, जिससे हम Notification का Design Customize कर सकते हैं।

FAQs

Android Notification एक Pop-up Alert होता है, जो Users को उनके Device पर Important Updates देता है जैसे Messages, Emails, और App Alerts। ये Status Bar में दिखता है और Click करने पर User को सीधे App में ले जाता है।
Android में कई प्रकार के Notifications होते हैं, जैसे Basic Notification, Expandable Notification, Heads-up Notification, Progress Notification, और Custom Notification। ये विभिन्न स्थितियों में उपयोग किए जाते हैं, जैसे Simple Alerts, Image के साथ Notifications और Download Progress दिखाने के लिए।
Simple Notification बनाने के लिए , हमें NotificationCompat.Builder का उपयोग करना होता है और NotificationManagerCompat के माध्यम से उसे दिखाना होता है।

Code: NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "my_channel") .setSmallIcon(R.drawable.notification_icon) .setContentTitle("New Alert") .setContentText("This is a simple notification.") .setPriority(NotificationCompat.PRIORITY_DEFAULT); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build());
Android 8.0 (Oreo) और उससे ऊपर के Versions में , Notification Channel अनिवार्य होता है। यह एक Category की तरह काम करता है, जिससे Users अपनी पसंद के अनुसार Notifications को Control कर सकते हैं।
इसके लिए हमें PendingIntent का उपयोग करना होता है, जिससे Click करने पर User को Directly किसी Activity में भेजा जा सकता है।

Code: Intent intent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "my_channel") .setSmallIcon(R.drawable.notification_icon) .setContentTitle("Tap to Open") .setContentText("Click here to open the app.") .setContentIntent(pendingIntent) .setAutoCancel(true); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1, builder.build());
Progress Notification का उपयोग किसी Task (जैसे Downloading) की Progress दिखाने के लिए किया जाता है। इसके लिए setProgress() Method का उपयोग किया जाता है।

Code: NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "my_channel") .setSmallIcon(R.drawable.notification_icon) .setContentTitle("Downloading...") .setContentText("Download in progress") .setProgress(100, 50, false); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(2, builder.build());

Please Give Us Feedback