-
-
Save burinov/d617be5eadc60d4021e3de6841e04c7c to your computer and use it in GitHub Desktop.
Example on how to use adb to start an Activity,BroadcastReceiver or Service from adb and include intent extras too.for Activity: adb shell am start -n "com.peirr.test/com.peirr.test.MyActivity" --es name "John" --ei age 30for BroadcastReceiver adb shell am broadcast -n "com.peirr.test/com.peirr.test.MyReceiver" --es name "John" --ei age 30for Se…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Example on how to use adb to start an Activity, | |
#BroadcastReceiver or Service from adb and include intent extras too. | |
#for Activity: | |
adb shell am start -n "com.peirr.test/com.peirr.test.MyActivity" --es name "John" --ei age 30 | |
#for BroadcastReceiver | |
adb shell am broadcast -n "com.peirr.test/com.peirr.test.MyReceiver" --es name "John" --ei age 30 | |
#for Service | |
adb shell am startservice -n "com.peirr.test/com.peirr.test.MyService" --es name "John" --ei age 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.peirr.test"> | |
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme"> | |
<receiver | |
android:name=".MyReceiver" | |
android:enabled="true" | |
android:exported="true" /> | |
<service | |
android:name=".MyService" | |
android:enabled="true" | |
android:exported="true" /> | |
<activity android:name=".MyActivity" | |
android:exported="true" | |
/> | |
</application> | |
</manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.peirr.test; | |
import android.content.Intent; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.widget.TextView; | |
public class MyActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_my); | |
TextView lname = (TextView) findViewById(R.id.name); | |
TextView lage = (TextView) findViewById(R.id.age); | |
Intent intent = getIntent(); | |
if (intent != null) { | |
String name = intent.getStringExtra("name"); | |
int age = intent.getIntExtra("age",0); | |
lname.setText(name); | |
lage.setText(String.valueOf(age)); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.peirr.test; | |
import android.content.BroadcastReceiver; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.widget.Toast; | |
public class MyReceiver extends BroadcastReceiver { | |
public MyReceiver() {} | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
if (intent != null) { | |
String name = intent.getStringExtra("name"); | |
int age = intent.getIntExtra("age",0); | |
Toast.makeText(context,"MyReceiver Received: [name:"+name+"] [age:"+age+"]",Toast.LENGTH_SHORT).show(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.peirr.test; | |
import android.app.Service; | |
import android.content.Intent; | |
import android.os.IBinder; | |
import android.widget.Toast; | |
public class MyService extends Service { | |
public MyService() {} | |
@Override | |
public IBinder onBind(Intent intent) { | |
// TODO: Return the communication channel to the service. | |
throw new UnsupportedOperationException("Not yet implemented"); | |
} | |
@Override | |
public int onStartCommand(Intent intent, int flags, int startId) { | |
if (intent != null) { | |
String name = intent.getStringExtra("name"); | |
int age = intent.getIntExtra("age",0); | |
Toast.makeText(this, "MyService Received: [name:" + name + "] [age:" + age + "]", Toast.LENGTH_SHORT).show(); | |
} | |
return super.onStartCommand(intent, flags, startId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
welcome