Android:广播优先级、sendOrderedBroadcast、短信电话广播、abortBroadcast、ResultData
使用发送有序广播方法,广播优先级才能生效。
1
2
3
4
5
6
7
8
9
10
11
12
|
findViewById(R.id.button1).setOnClickListener(
new
OnClickListener()
{
@Override
public
void
onClick(View v)
{
Intent intent =
new
Intent();
intent.setAction(
"com.example.aex56"
);
intent.putExtra(
"key"
,
"value"
);
sendOrderedBroadcast(intent,
null
);
//发送有序广播
}
});
|
XML文件设置广播优先级:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<receiver
android:name=
"com.example.aex56_ordered_broadcast.MyReceiver1"
android:enabled=
"true"
android:exported=
"true"
>
<intent-filter android:priority=
"2500"
>
<action android:name=
"com.example.aex56"
/>
</intent-filter>
</receiver>
<receiver
android:name=
"com.example.aex56_ordered_broadcast.MyReceiver2"
android:enabled=
"true"
android:exported=
"true"
>
<intent-filter android:priority=
"3000"
>
<action android:name=
"com.example.aex56"
/>
</intent-filter>
</receiver>
|
接收电话呼出广播,自动添加号码前缀呼出;设置短信接收者最高优先级,拦截短信。
XML权限及优先级设置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<manifest xmlns:android=
"http://schemas.android.com/apk/res/android"
package
=
"com.example.aex58_ordered_tel"
android:versionCode=
"1"
android:versionName=
"1.0"
>
<uses-sdk
android:minSdkVersion=
"8"
android:targetSdkVersion=
"16"
/>
<uses-permission android:name=
"android.permission.PROCESS_OUTGOING_CALLS"
/>
<uses-permission android:name=
"android.permission.RECEIVE_SMS"
/>
<application
android:allowBackup=
"true"
android:icon=
"@drawable/ic_launcher"
android:label=
"@string/app_name"
android:theme=
"@style/AppTheme"
>
<receiver
android:name=
"com.example.aex58_ordered_tel.MyTelReceiver"
android:enabled=
"true"
android:exported=
"true"
>
<intent-filter>
<action android:name=
"android.intent.action.NEW_OUTGOING_CALL"
/>
</intent-filter>
</receiver>
<receiver
android:name=
"com.example.aex58_ordered_tel.MySmsReceiver"
android:enabled=
"true"
android:exported=
"true"
>
<intent-filter android:priority=
"9999999999999999999999999999999"
>
<action android:name=
"android.provider.Telephony.SMS_RECEIVED"
/>
</intent-filter>
</receiver>
</application>
</manifest>
|
电话呼出广播接收:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
public
class
MyTelReceiver
extends
BroadcastReceiver
{
//监测电话号码
/*1.添加电话呼出权限
* uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"
*
*2.接收系统电话呼出的广播
* <intent-filter >
* <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
* </intent-filter>
*
* 其他系统广播:
* android.intent.action.BOOT_COMPLETED 开机启动广播
*/
@Override
public
void
onReceive(Context context, Intent intent)
{
String telnum = getResultData();
//得到电话号码
telnum =
"0592"
+ telnum;
setResultData(telnum);
//设置拨出的电话号码
}
}
|
短信接收者:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
public
class
MySmsReceiver
extends
BroadcastReceiver
{
/*
* 拦截短信
* 1.添加短信接收权限
* uses-permission android:name="android.permission.RECEIVE_SMS"
*
* 2.设置广播优先级,接收系统收短信的广播
* <intent-filter android:priority="99999999999999999999999999"> 设置广播优先级
* <action android:name="android.provider.Telephony.SMS_RECEIVED"/>接收系统收到短信时的广播
* </intent-filter>
*
* 3.重写onReceive
* abortBroadcast();
*/
@Override
public
void
onReceive(Context context, Intent intent)
{
Log.e(
"msg"
,
"mmm"
);
abortBroadcast();
//关闭广播
}
}
|

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
Android调用系统相机、自己定义相机、处理大图片
Android调用系统相机和自己定义相机实例 本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,而且因为涉及到要把拍到 的照片显示出来,该样例也会涉及到Android载入大图片时候的处理(避免OOM),还有简要提一下有些人SurfaceView出现黑屏的原因。 Android应用拍照的两种方式,以下为两种形式的Demo展示出来的效果。 知识点: 一、调用系统自带的相机应用 二、自己定义我们自己的拍照界面 三、关于计算机解析图片原理(怎样正确载入图片到Android应用中) 所需权限: <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" /> <uses-permission android:name="android.pe...
-
下一篇
Android--ColorMatrix改变图片颜色
ColorMatrix 在Android中,图片是以一个个RGBA的像素点的形式加载到内存中的,所以如果需要改变图片的颜色,就需要针对这一个个像素点的RGBA的值进行修改,其实主要是RGB,A是透明度。在Android下,修改图片RGBA的值需要ColorMatrix类的支持,它定义了一个5*4的float[]类型的矩阵,矩阵中每一行表示RGBA中的一个参数。 一般常用指定ColorMatrix的RGBA值的方式有两种: 通过构造函数ColorMatrix(float[] src)直接得到i一个ColorMatrix对象,其中src参数为5*4的float[]类型的矩阵。 通过构造函数ColorMatrix()得到ColorMatrix对象,再通过set(float[] src)指定一个5*4的float[]类型的矩阵。 下面是定义了一个不修改的原图的RGBA的ColorMatrix。 1 ColorMatrix colorMatrix = new ColorMatrix(); 2 colorMatrix.set(new float[] { 3 1, 0, 0, 0, 0, 4 0, ...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Dcoker安装(在线仓库),最新的服务器搭配容器使用
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS8编译安装MySQL8.0.19
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2全家桶,快速入门学习开发网站教程