0

我编写了旨在发送短信的代码,它可以在模拟器上成功运行,但在真实设备上却失败了!社区可以帮助我识别我的代码或任何相关信息和链接的任何问题以帮助我吗?

public class SmsActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        
        final Button sendSms = (Button) findViewById (R.id.smsBut);
        sendSms.setOnClickListener(new View.OnClickListener() {         
            public void onClick(View v) {
            // TODO Auto-generated method stub              
            sendSMS("5556", "'hello frinds");
            sendSMS("*********", "'hello frinds");// **= real number
            }
        });

    }// end onCr

    public void sendSMS (String phoneNo, String msg) {      
        PendingIntent pi = PendingIntent.getActivity(this, 0,
            new Intent(this, SmsActivity.class), 0);                
        SmsManager sms = SmsManager.getDefault();       
        sms.sendTextMessage(phoneNo, null, msg, null, null);
    }    
}

这是清单:

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="sms.ecp.ccc"
        android:versionCode="1"
        android:versionName="1.0">
            <uses-sdk android:minSdkVersion="10" />
            <uses-permission android:name="android.permission.SEND_SMS" />
            <application android:icon="@drawable/ic_launcher"android:
                label="@string/app_name" >
            <activity android:name=".SmsActivity" android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    </manifest>   
4

1 回答 1

1

更改最后一行

sms.sendTextMessage(phoneNo, null, msg, pi, null);
于 2012-04-13T05:21:04.917 回答