接收短信

时间:2013-01-31 06:16:23

标签: android

我正在尝试从我的应用程序接收短信。我已经创建了一个扩展broadCastReceiver类的ReceiveSms类。我也覆盖了onReceive()。我添加了权限并在清单中注册了接收器。但是当我使用DDMS发送短信时,我的onRecieve没有打电话。为什么?谢谢你的提前。这是我的清单和BroadCastReceiver。

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();
    }

}

的manifest.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>

1 个答案:

答案 0 :(得分:3)

您需要在清单中添加android.permission.RECEIVE_SMS使用权限才能接收短信:

<uses-permission android:name="android.permission.RECEIVE_SMS" />