2013-08-15 11 views
41

बंद नहीं करता है मैं NotificationCompat लाइब्रेरी का उपयोग कर सिस्टम बार में अधिसूचना जोड़ रहा हूं। इस अधिसूचना में दो एक्शन बटन हैं। इसके अलावा, अधिसूचना पर AutoCancel() संपत्ति सत्य पर सेट है।एंड्रॉइड अधिसूचना क्रियाओं पर क्लिक करना अधिसूचना दराज

एक्शन बटन के क्लिक पर, सिस्टम को IntentService लॉन्च करने के लिए कॉन्फ़िगर किया गया है जो NotificationManager.cancel(NOTIFICATION_ID) पर कॉल करता है और फिर एक नया कार्य में एक गतिविधि लॉन्च करता है।
समस्या यह है कि हालांकि यह कॉल ट्रे से अधिसूचना को हटा देता है, यह दराज को पतन नहीं करता है। कहा जाता है गतिविधि दराज के पीछे खींचा जाता है।

क्या कोई व्यक्ति अधिसूचना रद्द करने के अलावा ड्रा को बंद करने के लिए विशेष कोड की आवश्यकता के बारे में कुछ प्रकाश डाल सकता है?

धन्यवाद।

+1

क्या आपको कभी इसके लिए समाधान मिला? –

+6

नहीं। प्रतिबिंब और विस्तार का उपयोग करने के लिए बस कुछ हैक्स, स्टेटस बार को संकुचित करें। जाहिर है, अगर आपके लंबित इरादे में एक इरादा है जो किसी गतिविधि को हल करता है, तो दराज ऑटो ढह गया है। हालांकि, यदि आपका लंबित इरादा ब्रॉडकास्ट रिसीवर या सेवा को लपेटता है, तो अधिसूचना ट्रे अपने (विस्तारित) राज्य को बरकरार रखती है। – Aster

उत्तर

0

जब भी आप अधिसूचना पर क्लिक करते हैं और गतिविधि या प्रसारण लॉन्च करते हैं तो एंड्रॉइड सिस्टम आपके लिए अधिसूचना ड्रॉवर को ध्वस्त कर देता है। मुझे नहीं लगता कि आपके कोड द्वारा अधिसूचना ड्रॉवर को बंद करने के लिए कोई प्रोग्रामेटिक तरीका है। मेरा सुझाव है कि आप उन सूचनाओं की जांच करें जिन्हें आप अधिसूचना निर्माता को पास करते हैं और सुनिश्चित करते हैं कि उन्हें सही संदर्भ इरादे दिए गए हैं। मुझे लगता है कि आपके द्वारा प्रदान किए गए इरादे के कारण एंड्रॉइड अधिसूचना प्रबंधक के अंदर कुछ अवरुद्ध हो रहा है। अधिसूचना से कार्रवाई शुरू होने के बाद तक मैंने अधिसूचना ड्रॉवर को खुले रहने को नहीं देखा है। यह जानने के लिए उत्सुक है कि क्या आपकी लक्षित गतिविधि में एक सेमिट्रांसेंट क्षेत्र है जहां पिछली गतिविधि दिखाई दे रही है, अगर ऐसा होता है तो मेरा सुझाव है कि आप पृष्ठभूमि को पूरी तरह से अपारदर्शी बनाते हैं (कोई पारदर्शी/अर्द्ध पारदर्शी क्षेत्र नहीं है)। हो सकता है कि एंड्रॉइड होम लॉन्चर को स्टॉप अनुक्रम को पूरा करने के लिए रोका जा रहा है और इस प्रकार लॉन्चर को आपके लिए अधिसूचना ड्रॉवर बंद करने की अनुमति नहीं दे रहा है। आशा है कि मैं आपकी मदद कर पाऊंगा। शुभकामनाएं।

1

जब मैं अच्छी तरह से समझते हैं कि Soumyajyoti के जवाब सही होना चाहिए ... यह

मैं एक जारी सूचना के लिए एक remoteview लेआउट में

Intent CR = new Intent(CRCODE); 
PendingIntent.getBroadcast(getApplicationContext(), MY_ID, CR, 0); 

उपयोग कर रहा हूँ की नहीं है ... ...

मैं आपको आश्वस्त कर सकता हूं कि यह दराज को बंद नहीं करता है, लेकिन इरादे को आग लगाता है और खुले दराज के पीछे गतिविधि खींचता है, साथ ही साथ मेरे रिसीवर को सौंपा गया अन्य कार्य भी करता है ...

,210

मैं दोनों getActivity, और getService और उन दोनों को दराज ठीक से बंद (जिनमें से न तो मेरी परिस्थिति में काम करने, मैं कई उद्देश्यों onRecieve सक्रिय करना हो) ...

का परीक्षण किया है मुझे पता है कि यह नहीं है एक उत्तर, लेकिन जब और मुझे यह पता चलता है तो मैं इसे संपादित करने के लिए रिपोर्ट करूंगा ...

पागल विचार ... शायद किसी सामग्री दृश्य वाले गतिविधि को प्रसारण रिसीवर के रूप में बुलाया जा सकता है जो उचित इरादे को आग लगाएगा आवश्यकतानुसार अन्य कक्षाएं या ऐप्स ...

उपरोक्त सूचीबद्ध पागल विचार ... लंबित इंटेंटेंट के साथ एक गतिविधि शुरू करें। निष्क्रियता प्राप्त करें और इसे प्रसारण या अन्य उद्देश्यों को रिले करने के लिए उपयोग करें, फिर स्वयं को समाप्त करें ... प्रभाव अंतिम उपयोगकर्ता के लिए प्रत्यक्ष नहीं है लेकिन

9

मैंने पाया कि जब आप विस्तारित अधिसूचनाओं में कार्रवाई बटन का उपयोग करते हैं, तो आपको अतिरिक्त लिखना होगा कोड और आप अधिक बाध्य हैं।

विस्तारित अधिसूचनाओं का उपयोग करने से पहले, मेरी फ़ाइल डाउनलोड अधिसूचना में डिफ़ॉल्ट कार्रवाई फ़ाइल पर एक दृश्य गतिविधि शुरू करना था। दृश्य उद्देश्य एक Chooser इरादे से लपेटा गया था। मैं अधिसूचना से सीधे चयनकर्ता उद्देश्य के लिए लंबित इरादे का उपयोग नहीं कर सका क्योंकि फ़ाइल प्रकार देखने के लिए कोई गतिविधि नहीं होने पर चयनकर्ता क्रैश हो जाएगा। तो मेरे पास ब्रॉडकास्ट रिसीवर था जो Chooser इरादा शुरू करेगा।

विस्तारित अधिसूचनाओं के साथ, मैंने फ़ाइल डाउनलोड अधिसूचना को बदलने का फैसला किया है, इसलिए डिफ़ॉल्ट कार्रवाई फ़ाइल विवरण गतिविधि को दिखाने और देखने के लिए कार्रवाई बटन के साथ दिखाने के लिए है। जैसा कि उपयोगकर्ता 2536953 द्वारा नोट किया गया है, अधिसूचना से प्रसारण रिसीवर शुरू करने से अधिसूचना ड्रॉवर बंद नहीं होता है। उनकी जानकारी के आधार पर कि एक गतिविधि दराज को बंद कर देगी, मैंने अपने प्रसारण रिसीवर को किसी भी यूआई के बिना अधिसूचना सक्रियता में बदल दिया।

जैसा कि इस पोस्ट How to dismiss Android notification after action has been clicked में इंगित किया गया है, एक और मुद्दा यह है कि जब उपयोगकर्ता एक एक्शन बटन पर क्लिक करता है तो आपको मैन्युअल रूप से अपनी सूचना रद्द करनी होगी। अधिसूचना केवल डिफ़ॉल्ट कार्रवाई के लिए स्वचालित रूप से रद्द कर दी गई है। मैंने इसे संभालने के लिए अधिसूचना सक्रियता में कोड भी जोड़ा।

दृश्य के साथ विस्तार किया अधिसूचना का निर्माण और भेज बटन:

NotificationCompat.Builder builder = new NotificationCompat.Builder(m_context).setAutoCancel(true); 

    final PendingIntent contentIntent = DownloadedFileIntentUtils.buildPendingItemDetailIntent(m_context, item); 
     builder.setContentIntent(contentIntent); 

    PendingIntent viewIntent = DownloadedFileIntentUtils.buildNotificationActionIntent(m_context, Intent.ACTION_VIEW, 
       m_context.getString(R.string.action_open), uri, MimeTypeUtil.getMimeType(item), id); 
    builder.addAction(R.drawable.actionbar_open_with, m_context.getString(R.string.action_open), viewIntent); 

    PendingIntent sendIntent = DownloadedFileIntentUtils.buildNotificationActionIntent(m_context, Intent.ACTION_SEND, 
       m_context.getString(R.string.action_send), uri, MimeTypeUtil.getMimeType(item), id); 
    builder.addAction(R.drawable.actionbar_share, m_context.getString(R.string.action_send), sendIntent); 

    builder.setTicker(title) 
    .setContentTitle(title) 
    .setContentText(text) 
    .setSmallIcon(R.drawable.notification_download); 
    .setStyle(new NotificationCompat.BigTextStyle().bigText(text)); 

    getNotificationManager().notify(id, builder.build()); 

आशय का निर्माण अधिसूचना कार्रवाई बटन से एक गतिविधि शुरू करने के लिए: किसी भी बिना

public static PendingIntent buildNotificationActionIntent(Context context, String action, String actionTitle, Uri uri, 
     String mimeType, int notificationId) { 
    // Build the file action intent (e.g. VIEW or SEND) that we eventually want to start. 
    final Intent fileIntent = buildFileActionIntent(action, actionTitle, uri, mimeType); 

    // Build the intent to start the NotificationActivity. 
    final Intent notificationIntent = new Intent(context, NotificationActivity.class); 
    // This flag must be set on activities started from a notification. 
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    // Pass the file action and notification id to the NotificationActivity. 
    notificationIntent.putExtra(Intent.EXTRA_INTENT, fileIntent); 
    notificationIntent.putExtra(IIntentCode.INTENT_EXTRA_NOTIFICATION_ID, notificationId); 

    // Return a pending intent to pass to the notification manager. 
    return PendingIntent.getActivity(context, s_intentCode.getAndIncrement(), notificationIntent, PendingIntent.FLAG_ONE_SHOT); 
} 

public static Intent buildFileActionIntent(String action, String actionTitle, 
     Uri uri, String mimeType) { 
    Intent intent = new Intent(action); 
    intent.addCategory(Intent.CATEGORY_DEFAULT); 

    if (action.equals(Intent.ACTION_SEND)) { 
     intent.putExtra(Intent.EXTRA_STREAM, uri); 
     intent.setType(mimeType); 
    } else { 
     intent.setDataAndType(uri, mimeType); 
    } 

    intent.putExtra(Intent.EXTRA_TITLE, actionTitle); 

    // Grant read permission on the file to other apps without declared permission. 
    int flags = Intent.FLAG_GRANT_READ_URI_PERMISSION; 
    intent.setFlags(flags); 

    return intent; 
} 

अधिसूचना गतिविधि यूआई:

public class NotificationActivity extends Activity { 
private final static Logger s_logger = LogUtil.getLogger(NotificationActivity.class); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    Intent intent = getIntent(); 

    // Cancel the notification that initiated this activity. 
    // This is required when using the action buttons in expanded notifications. 
    // While the default action automatically closes the notification, the 
    // actions initiated by buttons do not. 
    int notificationId = intent.getIntExtra(IIntentCode.INTENT_EXTRA_NOTIFICATION_ID, -1); 
    if (notificationId != -1) { 
     NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     manager.cancel(notificationId); 
    } 

    // If there is an activity to handle the action, start the file action. 
    if (DownloadedFileIntentUtils.verifyActivityIsAvailable(this, fileActionIntent, false)) { 
      fileActionIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      DownloadedFileIntentUtils.startFileActionActivity(this, fileActionIntent); 
    } 

    // Finish activity. 
    finish(); 
} 

public static void startFileActionActivity(Context context, Intent fileActionIntent) { 
    // Start chooser intent. 
    Intent chooser = Intent.createChooser(fileActionIntent, fileActionIntent.getStringExtra(Intent.EXTRA_TITLE)); 

    // Copy the flags from fileActionIntent to chooser intent. 
    // FileActionExecutor must set FLAG_ACTIVITY_NEW_TASK on the intent passed to startActivity 
    // because the flag is required when starting an activity from a context that is not an activity. 
    chooser.addFlags(fileActionIntent.getFlags()); 

    context.startActivity(chooser); 
} 

AndroidManifest.xml पर अधिसूचना सक्रियता जोड़ने के लिए मत भूलना।

+0

बहुत बहुत धन्यवाद! –

+1

मुझे एंड्रॉइड सेट करने की आवश्यकता थी: टास्कएफ़िनिटी = "" अधिसूचना में सक्रियता अन्यथा यह मुख्य क्रियाशीलता भी शुरू कर रहा था अगर यह बैकस्टैक –

+0

में मौजूद था http://stackoverflow.com/questions/42527534/pending-action-expand-notification-on- कृपया क्लिक करें मेरे पास –

36

अपनी कार्रवाई एक प्रसारण या एक सेवा के रूप में है, लेकिन आप का इरादा अधिसूचना दराज संक्षिप्त करने के लिए के लिए, आप android.intent.action.CLOSE_SYSTEM_DIALOGS अपने onReceive से प्रसारित चाहिए। यह मैन्युअल रूप से दराज बंद कर देगा।

+26

भेजें ब्रॉडकास्ट (नया इरादा (इरादा.एक्शन_CLOSE_SYSTEM_DIALOGS)); – goodhyun

+2

भेजें ब्रॉडकास्ट विधि संदर्भ ऑब्जेक्ट के अंदर पाई जा सकती है। –

+0

मैंने संदर्भ को कॉल करने से पहले अपने ब्रॉडकास्ट रिसीवर में यह लाइनें जोड़ दीं। स्टार्ट एक्टिविटी (myIntent) इसका इरादा = नया इरादा (इरादा.एक्शन_CLOSE_SYSTEM_DIALOGS); context.sendBroadcast (इसे); –

संबंधित मुद्दे