<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lsj.broadcasttest">
<span style="color:#FF0000;"> <permission
android:name="test.permission.TEST"
android:protectionLevel="normal"
></permission></span>
<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=".MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="20">
<action android:name="hahaha" />
</intent-filter>
</receiver>
<receiver
android:name=".MyReceiver2"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="19">
<action android:name="hahaha" />
</intent-filter>
</receiver>
</application>
<span style="color:#FF0000;"> <uses-permission android:name="test.permission.TEST"/></span>
</manifest>
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button send= (Button) findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent();
intent.setAction("hahaha");
intent.putExtra("msg","一个简单的消息");
sendOrderedBroadcast(intent,"test.permission.TEST");
}
});
}
}
ublic class MyReceiver extends BroadcastReceiver {
public MyReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"接收到的Intent的Action为:"+intent.getAction()+"\n消息内容是:"+intent.getStringExtra("msg"),Toast.LENGTH_LONG).show();
Bundle bundle=new Bundle();
bundle.putString("first","第一个BroadCast存入的消息!");
setResultExtras(bundle);
}
}
ublic class MyReceiver2 extends BroadcastReceiver {
public MyReceiver2() {
}
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
Bundle bundle=getResultExtras(true);
String first=bundle.getString("first");
Toast.makeText(context,"第一个BroadCast存入的消息为:"+first,Toast.LENGTH_LONG).show();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有