我正在尝试从我的应用程序接收短信。我做了一个 ReceiveSms 类,它扩展了 broadCastReceiver 类。我也覆盖 onReceive() 。我添加了权限并在清单中注册了接收者。但是当我使用 DDMS 发送短信时,我的 onRecieve 没有被调用。为什么 ?谢谢是提前。这是我的清单和广播接收器。
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class ReceiveSms extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "One Message Received", Toast.LENGTH_LONG).show();
}
}
清单.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blogspot.uappmarket.sendingsms"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="6"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.blogspot.uappmarket.sendingsms.SendSms"
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=".ReceiveSms" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
</manifest>