初学Android——广播接收者
来源:互联网 发布:mars渲染软件 编辑:程序博客网 时间:2024/05/21 22:24
效果图:
代码实现;
package mybroadcastreceiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class MyBroadcastReceiverOne extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String name = intent.getExtras().getString("name"); Log.i("Recevier1", "接收到:"+name); } }package mybroadcastreceiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class MyBroadcastReceiverTwo extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String name = intent.getExtras().getString("name"); Log.i("Recevier2", "接收到:"+name); } }
package mybroadcastreceiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; 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(); } }<?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
- 初学Android——广播接收者
- Android基础——广播接收者BroadcastReceiver
- Android—————— 广播接收者
- android基础笔记——广播接收者,实现短信监听
- 黑马程序员——Android之广播接收者Alarm实例
- Android学习——服务Service与广播接收者BroadcastReciver
- android随笔08——代码注册广播接收者
- android基础学习13——广播接收者
- android—广播接收者BroadcastReceiver的应用开发范例
- android 广播接收者--BroadcastReceiver
- android 广播接收者--BroadcastReceiver
- Android 广播接收者--BroadcastReceiver
- 【android,20】广播接收者
- Android BroadcastReceiver 广播接收者
- Android 广播接收者--BroadcastReceiver
- android 广播接收者--BroadcastReceiver
- android:BroadcastReceiver 广播接收者
- android广播接收者
- 微信分享
- Word2vec基础介绍(二):统计词频
- 刷清橙OJ--A1071.分数线划分
- 【视频开发】【CUDA开发】ffmpeg Nvidia硬件加速总结
- 虚拟化virtualization
- 初学Android——广播接收者
- popubwindos封装
- BigDemicalUtil工具类
- 详解Oracle DELETE和TRUNCATE 的区别
- maven 系列- Unknown lifecycle phase "mvn".
- jMetal使用教程(二)
- 二叉树相关问题
- 如何阅读DB2的语法图-How to read the syntax diagrams
- oracle数据库中的异步IO