评论

收藏

[其他] android broadcastReceiver组件

网络安全 网络安全 发布于:2021-08-06 13:16 | 阅读数:415 | 评论:0

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.receivedemo"
  android:versionCode="1"
  android:versionName="1.0" >
  <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<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" >
    <activity
      android:name="com.example.receivedemo.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>
    <receiver android:name=".Demo">
      <intent-filter android:priority="1000">
        <action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
          
      </intent-filter>
     
    </receiver>
    
    
  </application>
</manifest>
Demo.java
package com.example.receivedemo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class Demo extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(context, "Massage Receiver", Toast.LENGTH_LONG).show();
}
}



关注下面的标签,发现更多相似文章