7

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

यहाँ आशय

 Intent intent = new Intent(context, AudioStreamService.class); 


    Random generator = new Random(); 


    PendingIntent i = PendingIntent.getActivity(context, 579, intent,PendingIntent.FLAG_UPDATE_CURRENT); 


    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
      .setSmallIcon(R.drawable.ic_launcher) 
      .setContentTitle(title) 
      .setContentText(text) 
      .setPriority(NotificationCompat.PRIORITY_DEFAULT) 
      .setLargeIcon(picture) 
      .setTicker(ticker) 
      .setNumber(number) 
      .setOngoing(true) 
      .addAction(
       R.drawable.ic_action_stat_reply, 
       res.getString(R.string.action_reply), 
       i); 

    notify(context, builder.build()); 

साथ मेरी सूचना है यहाँ मेरी सेवा

public int onStartCommand(Intent intent, int flags, int startId) { 
    Log.e("APP ID", "APP ID - service called "); 

    if(isPlaying){ 
     stop(); 
    } 
    else { 
     play(); 
    } 
    return Service.START_STICKY; 
} 

जब अधिसूचना में कार्रवाई से बुलाया लॉग शुरू हो रहा कभी नहीं किया गया है के लिए प्रारंभ पर है। लेकिन सेवा ऐप में एक बटन द्वारा उपयोग की जाती है और ठीक काम करती है। लॉग को नीचे दिए गए आदेशों के रूप में बुलाया जाता है।

उत्तर

13

उपयोग:

PendingIntent pendingIntent = PendingIntent.getService(context, 579, intent,PendingIntent.FLAG_UPDATE_CURRENT); 

के बजाय:

PendingIntent pendingIntent = PendingIntent.getActivity(context, 579, intent,PendingIntent.FLAG_UPDATE_CURRENT); 

^^ इस अधिसूचना से एक गतिविधि शुरू करने के लिए प्रयोग किया जाता है।

+0

बहुत बढ़िया, धन्यवाद! – Dandrews

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