How to access extra bundle sent along with Remote

2019-08-05 16:53发布

问题:

I am trying to make an app that makes a direct reply notification from one activity and sets the text entered by user in the notification to a TextView in another activity. However i have two textviews in my second activity . One for the text entered in remote Input in my notification and second for the extra text i want to send along in a bundle with remote Input from first activity. The problem is that the text entered in the Remote input gets set to the desired Text View but the extra text that i sent in a bundle along with the Remote Input from my first activity is not getting received in my second activity. I used addExtras(Bundle extras) to send extra data from first activity and getExtras() to receive the data in second activity . It is not giving any errors but the TextView supposed to show the extra text becomes blank and doesn't show any text. Here's the code from first activity

            Bundle b=new Bundle();
            b.putString("title",title);


            RemoteInput rInput=new RemoteInput.Builder(REMOTE_KEY).setLabel(remoteLabel).addExtras(b).build();
            Intent i=new Intent(StoreList.this,StoreActivity.class);

            PendingIntent pi=PendingIntent.getActivity(StoreList.this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
            NotificationCompat.Action nAction=new NotificationCompat.Action.Builder(android.R.drawable.ic_dialog_info,"DESCRIBE",pi).addRemoteInput(rInput).build();


            nCompat=new NotificationCompat.Builder(StoreList.this)
            .setColor(getResources().getColor(R.color.colorPrimaryDark))
            .setContentTitle(title)
            .setSmallIcon(R.drawable.burger)
            .setPriority(4)
            .addAction(nAction);

            nManager.notify(uniqueID,nCompat.build());

Here's the second activity code

    String desc="";
    String title="";

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT_WATCH) {
        RemoteInput r=new RemoteInput.Builder(REMOTE_KEY).build();
        Bundle bundle= r.getExtras();
    }
    if(bundle!=null)
    {

        title=bundle.getString("title");

    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT_WATCH) 
    {
       Bundle remoteInput = RemoteInput.getResultsFromIntent(i);
    }
    if(remoteInput!=null)
    {
         desc=remoteInput.getCharSequence(REMOTE_KEY).toString();
    }

I am very new to this topic and i may have wrongly used addExtras() or getExtras() methods please point out the mistake.Please do tell if there are any other methods to do this job. Thank you!