由于常常写错一些规则,因为本人对于xml等一些细节不甚清楚,在此记录作为参考。
一、一个activity
public class MainActivity extends Activity {
Button sendButton = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sendButton = (Button) findViewById(R.id.sendBroadcast);
sendButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent("abc.xyz");
intent.putExtra("YouName", "songngjiangchao");
sendBroadcast(intent);
}
});
}
}
二、一个xml文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="song.jiangchao"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="MyBroadcaseReceiver">
<intent-filter >
<action android:name="abc.xyz"/>
</intent-filter>
</receiver>
</application>
</manifest>