【问题标题】:Sending intent with bundle using console使用控制台通过捆绑发送意图
【发布时间】:2014-05-06 13:55:29
【问题描述】:

我正在开发一个 Android 应用程序,用于侦听包含包含一些数据的捆绑包的特定意图。我想使用 adb 向我的应用程序发送一个意图。我试过了:

adb shell am startservice -a com.INTENT_NAME -e myBundleName myBundleData com.pkg/com.pkg.cls

但我的应用程序将其识别为字符串列表而不是捆绑包。有谁知道如何使用 am 应用程序发送带有捆绑包的意图?不幸的是,文档只提到了发送字符串或数字列表,没有提到 bundle。

【问题讨论】:

    标签: android android-intent console bundle adb


    【解决方案1】:

    根据source codeam无法接受bundle类型的输入数据

    更新: 在 Android 7.0 中,intent 参数解析代码 has been movedAm.javaIntent.java 并支持更多数据类型(如基本类型的 Array[]ArrayList<>)。不幸的是,在am 命令中仍然不支持Bundle 类型的附加功能。

    【讨论】:

    • 感谢您的回复。您知道如何使用控制台通过捆绑发送意图吗?
    【解决方案2】:

    我也遇到了同样的问题,试图假装你在收到 Facebook 应用邀请后刚刚安装了一个应用。无法让 shell 工作,最终构建了一个非常简单的测试平台,它只有一个按钮和处理程序代码,例如:

        Button button  = (Button)findViewById(R.id.trigger_button);
        button.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                intent.setData(Uri.parse("myapp://fb-app-invite"));
    
                Bundle bundle = new Bundle();
                bundle.putString("target_url", "myapp://fb-app-invite?fromuser=673");
                intent.putExtra("al_applink_data", bundle);
    
                MainActivity.this.startActivity(intent);
            }
        });
    

    【讨论】:

      【解决方案3】:

      您可以使用以下命令启动它: adb shell am startservice -a android.intent.action.MAIN -e "key" "value" -n com.example.test/.TestService 键和值应该是您要发送的捆绑包值。 TestService 应该是您的 ServiceName 在 androidmanifest.xml 中为您的服务添加 片段:

      <service android:name=".TestService" android:enabled="true">
                  <intent-filter>
                      <action android:name="android.intent.action.MAIN"/>
                      <category android:name="android.intent.category.LAUNCHER"/>
                  </intent-filter>
      
      </service>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-27
        • 1970-01-01
        • 2014-10-08
        • 1970-01-01
        • 1970-01-01
        • 2013-09-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多