代码之家  ›  专栏  ›  技术社区  ›  user2875404

RemoteInput无法检索附加项

  •  0
  • user2875404  · 技术社区  · 8 年前

        Bundle d = new Bundle();
        d.putString("chatID", id);
    
        RemoteInput remoteInput = new RemoteInput.Builder("remote_input")
                .setLabel("Send to "+name)
                .addExtras(d)
                .build();
        RemoteInput[] remoteInputs = new RemoteInput[]{remoteInput};
    
        Intent intent = new Intent(RemoteInputIntent.ACTION_REMOTE_INPUT);
        intent.putExtra(RemoteInputIntent.EXTRA_REMOTE_INPUTS, remoteInputs);
        intent.putExtra("chatID", id);
        intent.putExtra("asd", "das");
        startActivityForResult(intent, 0);
    

    检索:

        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        System.out.println(data);
        System.out.println(data.getExtras());
    
        System.out.println(data);
    
        System.out.println(data.getExtras().toString());
        if (resultCode == RESULT_OK && requestCode == 0) {
            System.out.println(data);
            Bundle results = RemoteInput.getResultsFromIntent(data);
            String text = results.getCharSequence("remote_input").toString();
    
            System.out.println("  >");
            Bundle c = data.getExtras();
            //Object cd = data.getExtras().get("remote_input_types");
            Object cd = results.get("remote_input");
            System.out.println(cd);
            System.out.println(cd.getClass().getName());
            System.out.println(c);
            System.out.println(c.keySet());
            System.out.println("  <");
    
            Set<String> keys = c.keySet();
    
            Iterator<String> it = keys.iterator();
            while(it.hasNext()){
                System.out.println(it.next());
            }
    

    1 回复  |  直到 8 年前
        1
  •  1
  •   Red M    8 年前

    我相信问题在于你是如何发送或发送的 发射
    尝试使用putExtra s ()而不是putExtra()。PutExtras()用于保存bundle类的对象。

    发布:

    Bundle bundle = new Bundle();
    bundle.putString(Key, value);
    Intent intent = new Intent(context, className);
    intent.putExtras(bundle);
    intent.setFlags(intFlag);
    startActivityForResult();
    

       @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (resultCode == RESULT_OK && requestCode == 0) {
               Bundle dataBundle = data.getExtras();
               //Use data bundle
            }
       }