BCA / B.Tech 11 min read

Communication Services in Hindi

RK

लेखक Ratan Kumawat · संस्थापक, NotesMedia

प्रकाशित:

त्वरित सारांश और मुख्य बिंदु

  • • विषय फोकस: Android Programming notes in Hindi | एंड्राइड प्रोग्रामिंग नोट्स हिंदी में (BCA / B.Tech Syllabus)
  • • मुख्य विषय: Communication Services in Hindi - General Topics
  • • अवलोकन: Quick Answer: Android में Communication Services (SMS और Email) का उपयोग बाहरी दुनिया से संपर्क साधने के लिए किया जाता है। SMS भेजने के दो तरीके हैं: पह...
  • • मुख्य अवधारणाएं: Android SMS messaging, SmsManager, send email intent, ACTION_SEND,Android SMS messaging, SmsManager, send email intent, ACTION_SEND
Quick Answer: Android में Communication Services (SMS और Email) का उपयोग बाहरी दुनिया से संपर्क साधने के लिए किया जाता है। SMS भेजने के दो तरीके हैं: पहला, SmsManager class का उपयोग करके सीधे background में programmatic SMS भेजना (इसके लिए SEND_SMS permission और Android 6.0+ पर runtime permission अनिवार्य है); और दूसरा, Implicit Intent से user के default SMS app को खोलना। वहीं Email भेजने के लिए Android कोई direct SMTP API नहीं देता, बल्कि security और spam prevention के लिए Implicit Intent (Intent.ACTION_SENDTO या ACTION_SEND) के जरिए Gmail या Outlook जैसे installed email clients को launch किया जाता है।

Android Communication Services क्या हैं? (Overview)

Mobile devices का सबसे मुख्य कार्य communication है। Android operating system developers को अपने apps के अंदर से call करने, SMS भेजने और email draft करने के शक्तिशाली tools देता है। Android के core architecture को समझने के लिए आप Android architecture in Hindi पढ़ सकते हैं।

Android में communication को दो मुख्य श्रेणियों में समझा जाता है:

  1. Telephony & SMS Services: SIM card और cellular network के जरिए 160-character text message भेजना।
  2. Email Services: Internet protocols (SMTP/IMAP) के जरिए email clients को Intent से trigger करके rich-text और attachments के साथ mail भेजना। Intents के काम करने के तरीके के लिए linking activities using intents in Android देखें।
Advertisement

Android में SMS भेजने के दो तरीके (SMS Approaches)

Android application में SMS भेजने के लिए दो अलग-अलग दृष्टिकोण अपनाए जाते हैं:

तरीका 1: SmsManager API का उपयोग करके (Direct Background SMS)

जब आप चाहते हैं कि user को बिना कोई दूसरा app खोले सीधे आपके app के अंदर "Send" button दबाते ही SMS चला जाए (जैसे OTP भेजना या emergency alert), तो SmsManager का उपयोग किया जाता है:

  • Manifest Permission: AndroidManifest.xml में नीचे दी गई permission जोड़ना अनिवार्य है:
    <uses-permission android:name="android.permission.SEND_SMS" />
    Manifest file के नियमों के लिए what is AndroidManifest.xml in Hindi पढ़ें।
  • Runtime Permission (Android 6.0+ Marshmallow): क्योंकि SMS भेजना एक "Dangerous Permission" है (इससे user के SIM card से पैसे कट सकते हैं), इसलिए app run होने पर ContextCompat.checkSelfPermission() से user की रजामंदी लेना जरूरी है।
  • SmsManager Method: SmsManager.getDefault().sendTextMessage(phoneNo, null, message, sentIntent, deliveryIntent); (Android 12 / API 31+ पर getDefault() deprecated है; वहाँ context.getSystemService(SmsManager.class) use करें)

तरीका 2: Implicit Intent से (Default SMS App खोलना)

यदि आप अपने app में कोई extra SMS permission नहीं मांगना चाहते, तो आप user के phone में पहले से मौजूद SMS app (जैसे Google Messages) को Intent से खोल सकते हैं। इसमें user खुद "Send" button दबाता है:

Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.setData(Uri.parse("smsto:" + phoneNumber));
smsIntent.putExtra("sms_body", "Hello from Android App!");
startActivity(smsIntent);

Android में Email भेजने की कार्यशैली (Email via Intents)

कई शुरुआती students सोचते हैं कि Android में email भेजने के लिए कोई सीधा EmailManager class होता है। वास्तव में Android में कोई direct built-in email API नहीं है।

सीधे background से email न भेजने के दो technical कारण हैं:

  1. Security और Credentials: सीधे mail भेजने के लिए user का email password या SMTP credentials app में store करने पड़ेंगे, जिससे data चोरी का भारी खतरा होता है।
  2. Spam Prevention: यदि background से mail भेजने की खुली छूट दी जाए, तो malware apps user के phone से लाखों spam emails भेजने लगेंगे।

इसलिए Android Implicit Intent का उपयोग करता है। App Intent.ACTION_SENDTO के साथ mailto: URI set करता है (सिर्फ email apps दिखते हैं), या Intent.ACTION_SEND के साथ message/rfc822 MIME-type set करता है। System phone में मौजूद सभी email apps (Gmail, Outlook, Yahoo) की list का Chooser दिखाता है, जहाँ user अपनी पसंद के app से secure email भेज सकता है।

SmsManager (Direct) बनाम SMS via Intent (Comparison Table)

Android exam में दोनों SMS techniques की तुलना अक्सर पूछी जाती है:

Comparison Parameter SmsManager (Direct Programmatic) SMS via Implicit Intent
User Interface (UI) कोई बाहरी app नहीं खुलता; message सीधे background में चला जाता है। Phone का default SMS app खुलता है, जहाँ user खुद message देखता है।
Permissions की जरूरत SEND_SMS permission अनिवार्य (Manifest + Runtime). शून्य permission (किसी भी SMS permission की आवश्यकता नहीं).
User Control कम (App background में सीधे send कर देता है). पूर्ण (User message edit कर सकता है या send करने से मना कर सकता है).
उपयुक्त Real-World Use Case Two-Factor OTP verification, banking alerts, SOS emergency apps. Contact sharing, सामान्य customer support feedback.

SMS Services बनाम Email Services (Comparison Table)

Android में दोनों communication services का technical analysis:

Feature SMS Service Email Service
प्राथमिक API / Class android.telephony.SmsManager android.content.Intent (Implicit Intent)
Internet की आवश्यकता नहीं (केवल cellular network / SIM card चाहिए)। हाँ (सक्रिय Wi-Fi या mobile data internet अनिवार्य)।
Attachments (Files/Photos) केवल plain text (MMS के लिए अलग API चाहिए)। पूर्ण support (Intent.EXTRA_STREAM से PDF, Images भेज सकते हैं)।
Character Limit एक SMS में 160 characters (Hindi/Unicode में 70); बड़े text के लिए Multipart SMS. कोई fix limit नहीं (email server के अनुसार).
लागत (Carrier Charges) Telecom carrier के SMS plan के अनुसार शुल्क लग सकता है। Free (केवल internet data खर्च होता है)।

Complete Worked Program: Android SMS और Email Activity (Java)

यह एक सम्पूर्ण और tested Android Activity code है जो एक ही screen से SMS भेजने और Email composer खोलने का काम करता है:

package com.example.communicationservices;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private EditText editPhone, editSmsBody;
    private EditText editEmailTo, editEmailSubject, editEmailBody;
    private Button btnSendSms, btnSendEmail;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // UI Views Binding
        editPhone = findViewById(R.id.editPhone);
        editSmsBody = findViewById(R.id.editSmsBody);
        editEmailTo = findViewById(R.id.editEmailTo);
        editEmailSubject = findViewById(R.id.editEmailSubject);
        editEmailBody = findViewById(R.id.editEmailBody);
        btnSendSms = findViewById(R.id.btnSendSms);
        btnSendEmail = findViewById(R.id.btnSendEmail);

        // 1. Direct SMS Sending Logic
        btnSendSms.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String phone = editPhone.getText().toString().trim();
                String message = editSmsBody.getText().toString().trim();

                if (!phone.isEmpty() && !message.isEmpty()) {
                    try {
                        SmsManager smsManager = SmsManager.getDefault();
                        smsManager.sendTextMessage(phone, null, message, null, null);
                        Toast.makeText(MainActivity.this, "SMS Sent Successfully!", Toast.LENGTH_SHORT).show();
                    } catch (Exception ex) {
                        Toast.makeText(MainActivity.this, "Failed to send SMS: " + ex.getMessage(), Toast.LENGTH_LONG).show();
                    }
                } else {
                    Toast.makeText(MainActivity.this, "Please enter Phone and Message", Toast.LENGTH_SHORT).show();
                }
            }
        });

        // 2. Email Sending via Intent Logic
        btnSendEmail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String recipient = editEmailTo.getText().toString().trim();
                String subject = editEmailSubject.getText().toString().trim();
                String emailContent = editEmailBody.getText().toString().trim();

                Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
                emailIntent.setData(Uri.parse("mailto:")); // Only email apps should handle this
                
                // EXTRA_EMAIL must be a String array
                emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{ recipient });
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                emailIntent.putExtra(Intent.EXTRA_TEXT, emailContent);

                try {
                    // Create chooser to let user pick their favorite email client
                    startActivity(Intent.createChooser(emailIntent, "Select Email App:"));
                } catch (Exception e) {
                    Toast.makeText(MainActivity.this, "No email client installed on device", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
Advertisement

विद्यार्थी अक्सर क्या गलतियां करते हैं? (Common Student Mistakes)

  • EXTRA_EMAIL में साधारण String पास करना: Intent.EXTRA_EMAIL में students putExtra(Intent.EXTRA_EMAIL, "test@gmail.com") लिख देते हैं। Android API इसे String Array (new String[]{"test@gmail.com"}) के रूप में स्वीकार करता है। साधारण string देने पर email app में "To:" field खाली रह जाता है।
  • Android 6.0+ Runtime Permission भूल जाना: केवल AndroidManifest.xml में SEND_SMS लिखने से काम नहीं चलता। यदि code में runtime permission की जांच नहीं की गई, तो app SecurityException फेंक कर तुरंत crash हो जाएगा।
  • 160 character से बड़े SMS के लिए sendTextMessage उपयोग करना: यदि message 160 character से बड़ा है, तो sendTextMessage fail हो सकता है। लंबे messages के लिए smsManager.divideMessage(text) और smsManager.sendMultipartTextMessage() का use करना चाहिए।
  • Chooser का उपयोग न करना: startActivity(emailIntent) सीधे लिखने के बजाय हमेशा startActivity(Intent.createChooser(emailIntent, "...")) का प्रयोग करना चाहिए ताकि यदि user के पास multiple email apps हों तो वह मनचाहा app चुन सके।

Exam के लिए Important Questions

Short Questions (2 से 5 अंक)

  1. Android में SMS भेजने के लिए AndroidManifest.xml में कौन सी permission आवश्यक है?
  2. SmsManager class का प्राथमिक कार्य क्या है? इसके मुख्य method का नाम लिखिए।
  3. Android में सीधे email भेजने के बजाय Intent का use क्यों किया जाता है?
  4. Email Intent में Uri.parse("mailto:") का क्या महत्व है?
  5. लंबे (160+ characters) SMS को भेजने के लिए SmsManager का कौन सा method use होता है?

Long Questions (10 से 20 अंक)

  1. Android में SMS Messaging सेवाओं का विवरण दीजिए। SmsManager से सीधे SMS भेजने और Intent से SMS भेजने के बीच अंतर स्पष्ट कीजिए।
  2. Implicit Intent का use करके Android में Email भेजने के पूरे workflow को समझाइए। Java में एक complete Activity class लिखिए जो user input लेकर email client launch करती हो।
  3. Android में Runtime Permissions (Dangerous Permissions) क्या हैं? Android 6.0+ पर SMS भेजने के लिए आवश्यक permission checking steps को code के साथ समझाइए।

FAQs

Q1: क्या Android ऐप बिना यूजर की जानकारी के बैकग्राउंड में चुपके से ईमेल भेज सकता है?

Android के standard Intent system से यह संभव नहीं है। यदि background से बिना user interaction के email भेजना हो, तो developer को third-party JavaMail API और background thread में खुद का SMTP server configuration जोड़ना पड़ता है।

Q2: क्या ईमेल Intent में फोटो या फाइल अटैचमेंट जोड़ा जा सकता है?

हाँ, Intent.ACTION_SEND वाले intent में emailIntent.putExtra(Intent.EXTRA_STREAM, fileUri); का use करके और emailIntent.setType("application/pdf") या "image/*" set करके किसी भी file को email में attach किया जा सकता है।

Q3: PendingIntent का SMS भेजने में क्या कार्य होता है?

sendTextMessage() में दो PendingIntents pass किए जा सकते हैं: पहला sentIntent (यह जानने के लिए कि SMS telecom network पर broadcast हुआ या नहीं) और दूसरा deliveryIntent (यह पुष्टि करने के लिए कि receiver के phone पर SMS deliver हो चुका है)।

अक्सर पूछे जाने वाले प्रश्न (FAQs)

Quick Answer: Android में Communication Services (SMS और Email) का उपयोग बाहरी दुनिया से संपर्क साधने के लिए किया जाता है।
Android Programming notes in Hindi | एंड्राइड प्रोग्रामिंग नोट्स हिंदी में के पाठ्यक्रम में Communication Services in Hindi एक महत्वपूर्ण अध्याय है। यह मुख्य सिद्धांतों, परीक्षा प्रश्नों और सूत्रों को समझने के लिए अत्यधिक आवश्यक है।
हाँ, NotesMedia पर आपको Communication Services in Hindi के महत्वपूर्ण प्रश्नोत्तर, हल किए गए उदाहरण और नोट्स बिल्कुल मुफ्त मिलेंगे। अधिक अभ्यास के लिए आप हमारा ऐप भी डाउनलोड कर सकते हैं।
Advertisement