<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.broadcast.BroadcastReceiverActivity"
android:label="@string/app_name_bc" >
<intent-filter>
<action android:name="android.intent.action.MAIN" >
</action>
<category android:name="android.intent.category.LAUNCHER" >
</category>
</intent-filter>
</activity>
<receiver android:name="com.example.broadcast.HelloBroadReciever" >
<intent-filter>
<action android:name="comz.test.printlog" >
</action>
</intent-filter>
</receiver>
</application>
</manifest>
package com.example.broadcast;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.example.test.R;
public class BroadcastReceiverActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1 = (Button) findViewById(R.id.broadcastBtn);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("mason", "here");
// 定义一个intent
Intent intent = new Intent().setAction("comz.test.printlog")
.putExtra("info", "here is your info.");
// 广播出去
sendBroadcast(intent);
}
});
}
}
package com.example.broadcast;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class HelloBroadReciever extends BroadcastReceiver {
// 如果接收的事件发生
@Override
public void onReceive(Context context, Intent intent) {
Log.e("mason", "on receive");
if (intent.getAction().equals("comz.test.printlog")) {
Log.e("mason", intent.getStringExtra("info"));
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有