Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Android

एंड्रॉइड नोटिफिकेशन पर EditText (टेक्स्ट इनपुट) कैसे डालें?

नोटिफिकेशन में EditText — केवल डिस्प्ले, इंटरेक्टिव नहीं

यह आर्टिकल पिछले (ID 1005061585) के समान है — कस्टम RemoteViews लेआउट में EditText डालने का उदाहरण।

चरण 1-4: वही सेटअप

प्रोजेक्ट, मेन लेआउट, कस्टम लेआउट (EditText के साथ), MainActivity, मैनिफेस्ट — सभी पिछले आर्टिकल जैसे।

मुख्य कोड (पुनरावृत्ति)

// कस्टम लेआउट res/layout/custom_notification_layout.xml में EditText
// MainActivity में:
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
mBuilder.setContent(contentView);

❌ यह काम नहीं करता: EditText में टाइप करना

RemoteViews एंड्रॉइड का सीरियलाइज़्ड व्यू रिप्रेजेंटेशन है — लाइव व्यू नहीं। इसमें:

  • कोई टच/फोकस इवेंट नहीं
  • कीबोर्ड नहीं खुलता
  • टेक्स्ट चेंज लिसनर नहीं

✅ सही समाधान: Direct Reply (RemoteInput)

Android 7.0 (API 24) से RemoteInput के साथ इंलाइन रिप्लाई:

// 1. RemoteInput बनाएं
RemoteInput remoteInput = new RemoteInput.Builder("reply_text")
    .setLabel("Reply")
    .setChoices(new String[]{"Yes", "No", "Later"}) // ऑप्शनल क्विक रिप्लाई
    .build();

// 2. PendingIntent — रिप्लाई हैंडल करने वाली एक्टिविटी/ब्रॉडकास्ट
Intent replyIntent = new Intent(this, ReplyReceiver.class);
PendingIntent replyPending = PendingIntent.getBroadcast(this, 0, replyIntent, PendingIntent.FLAG_IMMUTABLE);

// 3. एक्शन में RemoteInput जोड़ें
NotificationCompat.Action action = new NotificationCompat.Action.Builder(
    R.drawable.ic_reply, "Reply", replyPending)
    .addRemoteInput(remoteInput)
    .setAllowGeneratedReplies(true)
    .build();

mBuilder.addAction(action);

4. रिप्लाई प्राप्त करें (BroadcastReceiver या Activity में)

public class ReplyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
        if (remoteInput != null) {
            String replyText = remoteInput.getCharSequence("reply_text").toString();
            // replyText प्रोसेस करें
        }
    }
}

मैनिफेस्ट में रिसीवर रजिस्टर करें

<receiver android:name=".ReplyReceiver" />

निष्कर्ष

कस्टम लेआउट में EditText डालना केवल UI मॉकअप के लिए ठीक है। वास्तविक टेक्स्ट इनपुट के लिए Direct Reply (RemoteInput) उपयोग करें — यह सिस्टम हैंडल करता है, कीबोर्ड दिखाता है, और रिजल्ट आपके ऐप को देता है।

  1. एंड्रॉइड में ImageView के लिए बॉर्डर कैसे सेट करें? एंड्रॉइड में ImageView के लिए बॉर्डर कैसे सेट करें?

    एंड्रॉइड में ImageView पर बॉर्डर जोड़ने के तरीके यह गाइड ImageView पर बॉर्डर/स्ट्रोक जोड़ने के कई दृष्टिकोण दिखाता है: XML ड्रॉएबल, प्रोग्रामेटिकली, और मॉडर्न Material Components। विधि 1: Shape Drawable (XML) - सबसे सरल res/drawable/image_border.xml <shape xmlns:android=https://schemas.android.

  1. एंड्रॉइड में बटन टेक्स्ट के लिए कस्टम फॉन्ट कैसे सेट करें? एंड्रॉइड में बटन टेक्स्ट के लिए कस्टम फॉन्ट कैसे सेट करें?

    एंड्रॉइड में बटन (या किसी व्यू) पर कस्टम फॉन्ट लागू करना एंड्रॉइड 8.0 (API 26) से **XML में फॉन्ट रिसोर्स** सपोर्ट करता है — यह सबसे सरल, प्रदर्शन-योग्य तरीका है। उससे पहले या प्रोग्रामेटिक कंट्रोल के लिए Typeface API उपयोग करें। यह ट्यूटोरियल दोनों तरीके दिखाता है। चरण 1: नया प्रोजेक्ट बनाएं Andro

  1. Android ऐप में मार्की (Marquee) टेक्स्ट कैसे उपयोग करें? Android ऐप में मार्की (Marquee) टेक्स्ट कैसे उपयोग करें?

    Android में मार्की (स्क्रॉलिंग) टेक्स्ट बनाने का गाइड यह ट्यूटोरियल दिखाता है कि कैसे TextView में लंबे टेक्स्ट को क्षैतिज रूप से स्क्रॉल (मार्की प्रभाव) कराया जाए। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में File → New Project चुनकर नया प्रोजेक्ट बनाएं। चरण 2: लेआउट फ़ाइल में कोड जोड़ें res/lay