Sending intent with bundle using console

前端 未结 3 1030
予麋鹿
予麋鹿 2020-11-29 12:36

I\'m developing an Android app listening for specific intent containing a bundle with some data. I would like to send an intent to my app using adb. I have tried with:

相关标签:
3条回答
  • 2020-11-29 13:09

    According to the source code am has no way of accepting input data of the bundle type

    Update: In Android 7.0 the intent parameters parsing code has been moved from Am.java to Intent.java and support for more data types (like Array[] and ArrayList<> of basic types) has been added. Unfortunately there is still no support for the Bundle type extras in am command.

    0 讨论(0)
  • 2020-11-29 13:13

    I was facing the same issue, trying to fake the situation where you've just installed an app after receiving a Facebook App Invite. Couldn't get the shell to work, ended up building a really simple test rig that had one button and handler code like:

        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);
            }
        });
    
    0 讨论(0)
  • 2020-11-29 13:15

    You can start it by using the following command: adb shell am startservice -a android.intent.action.MAIN -e "key" "value" -n com.example.test/.TestService Key and value should be your bundle values you want to send. TestService should be your ServiceName Add for your Service in androidmanifest.xml Snippet:

    <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>
    
    0 讨论(0)
提交回复
热议问题