初学安卓-安卓广播
来源:互联网 发布:有哪些搜索算法 编辑:程序博客网 时间:2024/05/01 01:10
直接上代码,没什么可讲的地方
MyBroadcastReceiverOne
package mybroadcastreceiver;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.util.Log;/** * Created by Administrator on 2017/6/2. */public class MyBroadcastReceiverOne extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String name = intent.getExtras().getString("name"); Log.i("Recevier1", "接收到:"+name); }}MyBroadcastReceiverTwo
package mybroadcastreceiver;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.util.Log;/** * Created by Administrator on 2017/6/2. */public class MyBroadcastReceiverTwo extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String name = intent.getExtras().getString("name"); Log.i("Recevier2", "接收到:"+name); }}MyBroadcastReceiverThree
package mybroadcastreceiver;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.util.Log;/** * Created by Administrator on 2017/6/2. */public class MyBroadcastReceiverThree extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String name = intent.getExtras().getString("name"); Log.i("Recevier3", "接收到:"+name); }}
MainActivity
package com.example.bz0209.myapplication;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Toast;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void SendMessage(View view)//广播发送者 { Intent intent = new Intent(); intent.setAction("SendMessage"); intent.putExtra("name","cyk"); sendOrderedBroadcast(intent,null); Toast.makeText(getApplicationContext(), "发送广播成功", Toast.LENGTH_SHORT).show(); }}AndroidManifest
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.bz0209.myapplication"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name="mybroadcastreceiver.MyBroadcastReceiverOne"> <intent-filter android:priority="1000"> <action android:name="SendMessage"/> </intent-filter> </receiver> <receiver android:name="mybroadcastreceiver.MyBroadcastReceiverThree"> <intent-filter android:priority="200"> <action android:name="SendMessage"/> </intent-filter> </receiver> <receiver android:name="mybroadcastreceiver.MyBroadcastReceiverTwo"> <intent-filter android:priority="600"> <action android:name="SendMessage"/> </intent-filter> </receiver>
阅读全文
0 0
- 初学安卓-安卓广播
- 安卓发送广播
- 【安卓】Broadcast广播
- 安卓广播接收者
- 安卓广播
- 安卓广播BroadcastReceiver
- 安卓广播事件
- 安卓-无序广播
- 安卓广播大全
- 安卓广播
- 安卓广播
- 安卓自定义广播
- 安卓 广播总结
- 安卓 广播
- 安卓广播大全
- 安卓学习--广播
- 安卓初学笔记
- 初学安卓控件
- Qt 窗口属性简介之Qt::WA_DeleteOnClose
- myeclipse报An error has occurred,See error log for more details. java.lang.NullPointerException错误解决办法
- (搬运)在VS2013以上版本中无法使用配置工具的解决方案
- eclipse+maven环境搭建问题总结
- linux操作命令
- 初学安卓-安卓广播
- Spring Filter过滤器,Spring拦截未登录用户权限限制
- Swift 3.0 数组的语法小变动
- 电容参数X5R,X7R,Y5V,COG
- Flooded!
- 【python学习笔记】14:开发一个简易的爬虫
- Android常用控件七之ProgressBar的代码用法
- Android 监听屏幕锁屏(听音频,看视频)
- Word_Search