Android SmsManager不要将短信发送到特定号码

时间:2015-06-30 17:56:31

标签: android sms broadcastreceiver smsmanager

我正在尝试创建一个Android应用程序,它将在设备首次启动时发送短信,并且在成功发送短信后,应用程序将自动销毁。如果应用程序无法发送短信,那么它将在30分钟内尝试从设备启动时间再次开始。

但是出于测试目的,我试图将短信发送到特定号码。但是它不会从设备发送短信。这是manifest.xml代码

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.farhadrakib.waltonmobile.wst"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
     <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.SEND_SMS" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <receiver android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        <category android:name="android.intent.category.NONE" />
    </intent-filter>
</receiver>
    </application>

</manifest>

这是broadcastReceiver代码:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.util.Log;


public class MainActivity extends BroadcastReceiver{


    private static final String  DestinationAddress = "+8801746433855";
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String DeviceId = telephonyManager.getDeviceId();
        Log.d("DEVICEID",DeviceId);
        //String Line1Number = telephonyManager.getLine1Number();
        if (DeviceId != null){

            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(DestinationAddress, null, "My id: "+DeviceId, null, null);
        }
    }
}

任何人都可以帮忙吗?我真的需要一些好的消息

0 个答案:

没有答案