广播 收音机
来源:互联网 发布:板式换热器计算软件 编辑:程序博客网 时间:2024/05/01 00:30
<span style="font-size:18px;"></span>
<span style="font-size:18px;">动态广播:</span>
<span style="font-size:18px;"></span>
<span style="font-size:18px;">package com.example.boradcast;import android.app.Activity;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.Button;public class MainActivity extends Activity {privateMyBroadcastReceiver mBroadcastReceiver;//频道号privatefinalString chanel="com.";//过滤器需要的字段(tag)@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);final Activity activity=this;Button button=(Button) findViewById(R.id.button);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//发送广播(比如,某个广播电台在Chanel的频道发送节目)Intent intent=new Intent();intent.setAction(chanel);activity.sendBroadcast(intent);}});//初始化广播接收器(搞到一台收音机,开始准备接收音乐广播频道的音乐节目)mBroadcastReceiver=new MyBroadcastReceiver();//过滤器(选定音乐频道)IntentFilter filter=new IntentFilter();filter.addAction(chanel);//注册(旋转收音机的选台按钮,选定频道。开始接收音乐)registerReceiver(mBroadcastReceiver, filter);}@OverridepublicvoidonDestroy(){super.onDestroy();//注销广播接收(关闭收音机)unregisterReceiver(mBroadcastReceiver);}//创建广播接收器(收音机待命中。。。)private class MyBroadcastReceiver extends BroadcastReceiver{@Overridepublic void onReceive(Context context, Intent intent) {Log.d("广播测试","收到广播!");}}}</span>
静态广播:
<span style="font-size:18px;">package com.hx.gb;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;public class MainActivity extends Activity {private final String action = "com.xx";//过滤器需要的字段(tag)@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);final Activity activity = this;Button button = (Button) findViewById(R.id.button);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {//发送广播Intent intent = new Intent();intent.setAction(action); activity.sendBroadcast(intent);}});}}</span>
<span style="font-size:18px;">package com.hx.gb;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.util.Log;//创建广播接收器 public class MyBroadcastReceiver extends BroadcastReceiver{@Overridepublic void onReceive(Context context, Intent intent ) {Log.d("广播测试","收到广播!");} }</span>
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hx.gb" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <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> <span style="color:#ff0000;"><receiver android:name="com.hx.gb.MyBroadcastReceiver" > <intent-filter> <action android:name="com.xx" > </action> </intent-filter> </receiver></span> </application></manifest></span>
0 0
- 广播 收音机
- 收音机
- 无线广播相关信号(收音机)的发射与接收
- 旧作---收音机,送给喜欢听广播的朋友们
- 四大组件之BroadcastReceiver(一)-自定义“收音机”与发送“广播”
- 收音机驱动
- 收音机原理
- 收音机抗干扰
- 收音机原理
- USB收音机
- python 收音机
- 使用PPC听收音机
- 收音机的感触
- 小小收音机 免费
- 自动搜索调频收音机
- 电视 收音机地址大全
- HtmlInputRadio 收音机按钮控件
- 龙卷风收音机绿色版cradio_chs
- VS2010 中更改项目名称
- 如何使用swfobject(中文版)
- TextView复合文本的输入
- 2015.11.4-- <<机器学习实战>>chapt1--NUMPY等安装
- UNION中ORDER By的使用
- 广播 收音机
- 枚举
- mysql 查询表死锁 和结束死锁的表步骤
- iOS实现UPD广播(AsyncSocket)
- JAVA八大基本类型
- 微信支付jsApiParameter::{"return_code":"FAIL","return_msg":"invalid out_trade_no"}
- 光学术语
- 写在前面
- WebService分别在web项目和java工程中的使用