2013-05-13 4 views
9

मैं जब पुश अधिसूचना पर उपयोगकर्ता क्लिक करें, मैं stackoverflow खोज एक यूआरएल के साथ ब्राउज़र को खोलने के लिए कोशिश कर रहा हूँ और मैं इसब्राउज़र खोलना

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
     startActivity(browserIntent); 

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

इस

कोड

public void mostrarNotificacion(Context context, String body,String title, String icon, String url,String superior) 
{ 

    String ns = Context.NOTIFICATION_SERVICE; 
    NotificationManager notManager = (NotificationManager) context.getSystemService(ns); 




    int icono = R.drawable.mydrawable; 
    CharSequence textoEstado = superior; 
    long hora = System.currentTimeMillis(); 

    Notification notif = new Notification(icono, textoEstado, hora); 


    Context contexto = context.getApplicationContext(); 
    CharSequence titulo = title; 
    CharSequence descripcion = body; 
    PendingIntent contIntent; 
    if(url.equalsIgnoreCase("NULL")) 
    { 
     Intent notIntent = new Intent(contexto,MainActivity.class); 
     contIntent = PendingIntent.getActivity(
       contexto, 0, notIntent, 0); 
    } 
    else 
    {    
     // Intent i = new Intent(Intent.ACTION_VIEW); 
     //i.setData(Uri.parse(url)); 
     // contIntent = PendingIntent.getActivity(contexto, 0, i, 0); 
     Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
     startActivity(browserIntent); 



    } 


    // notif.setLatestEventInfo(contexto, titulo, descripcion, contIntent); 



    //AutoCancel: 
    notif.flags |= Notification.FLAG_AUTO_CANCEL; 


    //send notif 
    notManager.notify(1, notif); 
} 
+0

आप कहां 'mostrarNotificacion'' कहां कहते हैं Thod? – Eran

+0

अब यह काम कर रहा है ड्रोर फिचमैन के लिए धन्यवाद, वैसे भी मैं मैसेज – D4rWiNS

+0

पर विधि को कॉल करता हूं यहां एक वर्कअराउंड है http://stackoverflow.com/questions/39285006/android-lock-screen-notification-is-not-able-to-open- ब्राउज़र-ऑन-डबल-टैपिंग –

उत्तर

22

आपको बस इतना करना एक लंबित इरादे सेट किया गया है की जरूरत क्या है।

private void createNotification(String text, String link){ 

    NotificationCompat.Builder notificationBuilder = 
     new NotificationCompat.Builder(this) 
    .setAutoCancel(true) 
    .setSmallIcon(R.drawable.app_icon) 
    .setContentTitle(text); 

    NotificationManager mNotificationManager = 
     (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

    // pending implicit intent to view url 
    Intent resultIntent = new Intent(Intent.ACTION_VIEW); 
    resultIntent.setData(Uri.parse(link)); 

    PendingIntent pending = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
    notificationBuilder.setContentIntent(pending); 

    // using the same tag and Id causes the new notification to replace an existing one 
    mNotificationManager.notify(String.valueOf(System.currentTimeMillis()), PUSH, notificationBuilder.build()); 
} 

संपादित करें: 1: मैं इस सवाल का जवाब नमूना उद्देश्य के लिए PendingIntent.FLAG_UPDATE_CURRENT उपयोग करने के लिए बदल (ऊपर तुम सिर्फ एक गतिविधि शुरू कर दिया ...)

यहाँ एक नमूना कोड है। टिप्पणी के लिए धन्यवाद अवीव बेन शब्त।

संपादित करें 2: एलेक्स Zezekalo की टिप्पणी के बाद,,, ध्यान दें कि लॉक स्क्रीन से अधिसूचना खोलने संभालने क्रोम प्रयोग किया जाता है असफल हो जायेगी रूप में खुला अंक में विस्तार से बताया: https://code.google.com/p/chromium/issues/detail?id=455126 -
क्रोम इरादे पर ध्यान नहीं देगा , और आपको अपने लॉगकैट में ढूंढने में सक्षम होना चाहिए - ई/cr_document.CLActivity: इरादे को अनदेखा करना: इरादा {act = android.intent.action.VIEW डेटा = http://google.com/ ... flg = 0x1000c000 cmp = com.android.chrome/com.google.android.apps.chrome.Main (अतिरिक्त है)}

+2

लिंक में 'http: //' – Hamidreza

+0

इरादा होना चाहिए। FLAG_ACTIVITY_NEW_TASK का उपयोग यहां नहीं किया जाना चाहिए। जैसा कि यह दस्तावेज़ों में कहता है: इनमें से एक या अधिक होना चाहिए: लंबित INTent.FLAG_ONE_SHOT, लंबित INTent.FLAG_NO_CREATE, लंबित INTent.FLAG_UPDATE_CURRENT, Intent.FILL_IN_ACTION, Intent.FILL_IN_DATA, Intent.FILL_IN_CATEGORIES ...) –

+0

हम्म, यह एक अच्छा समाधान है लेकिन जब मैं लॉक स्क्रीन पर पुश अधिसूचना पर टैप करता हूं तो यह काम नहीं करता है: उस स्थिति में ब्राउज़र नहीं चलता है और लिंक नहीं खोलता है। कोई उपाय? –

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