Reputation: 23
Newbee to ADB
I wanted to do the following in my project.
1> Start with a nice GUI with some buttons like below (WPF c#) (achieved)
1> Install button to install apk (achieved)
2> Button to run apk (achieved)
3> Pass certain parameters to the android activity by using 'adb extras' (!PROBLEMS)
4> Capture the output into c# program (WPF GUI) (achieved)
Can anyone please give me an example to pass parameters to a activity in android using adb extras. Pass parameters to activity and how would you fetch these values in android activity. (Consider if i want to send two strings as extras to activity through ADB and extract them concatenate them in the android program. I dont find any clear answer for this online or an example. I have tried many things without results.
Responses in this regard would be appreciated!
Upvotes: 1
Views: 5266
Reputation: 546
You can pass those Strings as extras to your activity like this:
adb shell am start -n com.yourpackage/com.yourpackage.YourActivity --es extraKey extraValue
And in your activity:
public class YourActivity extends Activity {
private String extraValue;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
if (bundle != null) {
extraValue = bundle.getString("extraKey");
}
}
Upvotes: 3