BCA / B.Tech 11 min read

Communication Services in Hindi

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

  • • विषय फोकस: Android Programming notes in Hindi | एंड्राइड प्रोग्रामिंग नोट्स हिंदी में (BCA / B.Tech Syllabus)
  • • मुख्य विषय: Communication Services in Hindi - General Topics
  • • अवलोकन: Communication Services 1: SMS Messaging Android applications programmatic रूप से SMS messages भेज सकती हैं। यह `SmsManager` class का उपयोग करके किया जात...
  • • मुख्य अवधारणाएं: Android SMS messaging, SmsManager, send email intent, ACTION_SEND,Android SMS messaging, SmsManager, send email intent, ACTION_SEND

Communication Services

1: SMS Messaging

Android applications programmatic रूप से SMS messages भेज सकती हैं। यह `SmsManager` class का उपयोग करके किया जाता है।

Step 1: Permission Add करें

SMS भेजने के लिए, आपकी app को `AndroidManifest.xml` file में `SEND_SMS` permission की आवश्यकता होती है।


<manifest ...>
    <uses-permission android:name="android.permission.SEND_SMS" />
    <application ...>
        ...
    </application>
</manifest>

Note: Android 6.0 (API 23) और उससे ऊपर के लिए, आपको user से runtime पर भी permission मांगनी होगी।

Step 2: Java में SMS भेजना

आप `SmsManager` class का instance प्राप्त कर सकते हैं और `sendTextMessage()` method का उपयोग कर सकते हैं।

Java में उदाहरण:


public class SmsActivity extends AppCompatActivity {
    EditText phoneEditText, messageEditText;

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

        phoneEditText = findViewById(R.id.phone_et);
        messageEditText = findViewById(R.id.message_et);

        // Runtime permission check (For API 23+)
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS}, 1);
        }
    }

    public void sendSms(View view) {
        String phoneNumber = phoneEditText.getText().toString();
        String message = messageEditText.getText().toString();

        if (!phoneNumber.isEmpty() && !message.isEmpty()) {
            try {
                SmsManager smsManager = SmsManager.getDefault();
                smsManager.sendTextMessage(phoneNumber, null, message, null, null);
                Toast.makeText(getApplicationContext(), "SMS sent.", Toast.LENGTH_LONG).show();
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), "SMS failed to send.", Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        } else {
            Toast.makeText(this, "Please enter phone number and message", Toast.LENGTH_SHORT).show();
        }
    }
}

2: Email भेजना

Android में directly email भेजने के लिए कोई built-in API नहीं है। इसके बजाय, Android एक Implicit Intent का उपयोग करता है ताकि device पर installed किसी email client (जैसे Gmail, Outlook) को email भेजने के लिए launch किया जा सके।

यह approach सुरक्षित और user-friendly है क्योंकि user अपने trusted email app का उपयोग करता है।

Email भेजने के Steps:

  1. एक नया `Intent` object बनाएं जिसका action `Intent.ACTION_SEND` हो।
  2. `putExtra()` method का उपयोग करके email details (जैसे recipient, subject, body) add करें।
  3. `setType("message/rfc822")` का उपयोग करके intent का type set करें ताकि केवल email clients ही इसे handle कर सकें।
  4. `startActivity()` का उपयोग करके intent को launch करें।

Java में Email Intent का उदाहरण:


public class EmailActivity extends AppCompatActivity {
    EditText recipientEditText, subjectEditText, bodyEditText;

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

        recipientEditText = findViewById(R.id.recipient_et);
        subjectEditText = findViewById(R.id.subject_et);
        bodyEditText = findViewById(R.id.body_et);
    }

    public void sendEmail(View view) {
        String recipient = recipientEditText.getText().toString();
        String subject = subjectEditText.getText().toString();
        String body = bodyEditText.getText().toString();

        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        
        // Data set करें
        emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{recipient}); // Recipient(s)
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); // Subject
        emailIntent.putExtra(Intent.EXTRA_TEXT, body); // Body

        // Type set करें
        emailIntent.setType("message/rfc822");

        // Activity को start करें, user को email client चुनने का option दें
        startActivity(Intent.createChooser(emailIntent, "Choose an email client:"));
    }
}

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

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