2013-10-17 9 views
5

अधिसूचना बटन क्लिक करने के बाद मैं स्टेटस बार कैसे बंद कर सकता हूं?बटन अधिसूचना पर क्लिक होने पर स्टेटस बार बंद करें

मैं this कोशिश की, लेकिन मैं एक अपवाद था:

java.lang.NoSuchMethodException: collapse [] 
    at java.lang.Class.getConstructorOrMethod(Class.java:460) 
    at java.lang.Class.getMethod(Class.java:915) 
    ... 

मेरे कोड:

NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
    .setSmallIcon(R.drawable.icon) 
    .setContentTitle("Sync Failed") 
    .setContentText("Lorem ipsum dolor sit amet") 
    .setStyle(new NotificationCompat.BigTextStyle().bigText("Lorem ipsum dolor sit amet")) 
    .addAction(R.drawable.change, "Change Pass", pChangePass) 
    .addAction(R.drawable.remove, "Ignore", pIgnore) 
    .setAutoCancel(false); 
mNotificationManager.notify(accountUnique, builder.build()); 

NotificationIntent वर्ग

@Override 
public void onReceive(Context context, Intent intent) { 
    int notificationID = intent.getExtras().getInt("NOT_ID"); 
    this.callbackContext = StatusBarNotification.getCallback(); 
    this.mNotificationManager = StatusBarNotification.getNotificationManager(); 

    this.mNotificationManager.cancel(notificationID); 
    this.callbackContext.success(returnJSON(intent)); 
} 

उत्तर

0

ठीक है, मैं इसे हल।

private int currentApiVersion = android.os.Build.VERSION.SDK_INT; 
... 

Object sbservice = context.getSystemService("statusbar"); 
try { 
    Class<?> statusbarManager = Class.forName("android.app.StatusBarManager"); 
    if (currentApiVersion <= 16) { 
     Method collapse = statusbarManager.getMethod("collapse"); 
     collapse.invoke(sbservice); 
    } else { 
     Method collapse2 = statusbarManager.getMethod("collapsePanels"); 
     collapse2.invoke(sbservice); 
    } 
} catch (Exception e) { 
    e.printStackTrace(); 
} 
+4

आप वास्तव में स्वीकार करना चाहिए सैम लू के टिप्पणी -, अपने समाधान किसी भी अगले संस्करण पर काम करना बंद कर सकता है क्योंकि यह गैर का उपयोग करता है सार्वजनिक एपीआई जैसा कि आप देखते हैं कि आपको 'अगर एपीआई <= 16'' जोड़ना था - यह संभव है कि जल्द ही आपको उपरोक्त टिप्पणी के साथ सहमत होने पर 'if api <= 19' – imbryk

+0

जोड़ना होगा। सैम का जवाब बहुत आसान है और संस्करण संख्याओं से निपटता नहीं है। – Saik

30

निम्नलिखित समाधान अधिक सरल और कोई गैर सरकारी एपीआई के लिए इस्तेमाल किया जाना चाहिए:

Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 
context.sendBroadcast(it); 
+1

क्या आप कह सकते हैं कि इसका उपयोग कहां करें, रेसीसीव या एक्शन इरादे में? – Ajeet

+0

आकर्षण की तरह काम करते हैं! धन्यवाद। बस रेसीसीव में 2 कोड लाइनें डालें। –

+0

हाँ, यह काम किया। धन्यवाद। – Saik

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