发送短信:用户10074没有android.permission.SEND_SMS

时间:2013-11-21 03:55:37

标签: java android sms android-manifest

我正在编写一个应用程序,它将通过短信向输入的号码发送消息。但是,当我尝试发送消息时,我收到“用户10074没有android.permission.SEND_SMS”的错误,即使我在我的清单中有此权限。

以下是我用来发送短信的代码:

private void setupmessageButton(){
    Button messageButton = (Button) findViewById(R.id.button2);
    messageButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.i(TAG, "You've sent a message");
            Toast.makeText(MainActivity.this, "You've sent a message", Toast.LENGTH_LONG).show();
            String phonenumber = ((EditText) findViewById(R.id.editView1)).getText().toString();
            try {
                SmsManager.getDefault().sendTextMessage(phonenumber, null, "Hello SMS!",null, null);
            } catch(Exception e) {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
                AlertDialog dialog = alertDialogBuilder.create();
                dialog.setMessage(e.getMessage());
                dialog.show();

            }
        }
    });
    }

这是具有所需权限的清单:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="10" />

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="school.project.application.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>

        <activity   
            android:name=".AppPreferenceActivity" 
            android:label="@string/app_name">  
            <intent-filter> 
                 <action android:name="android.Intent.ACTION_VIEW" />  

                 <category android:name="android.intent.category.DEFAULT" />  
            </intent-filter>   
        </activity>
    </application>

</manifest>

消息不会发送的原因是我尝试运行它的手机没有数据计划吗?或者我的编码中是否存在阻止消息通过的潜在问题?

如果有任何帮助,我的代码基于我在网上找到的一个例子:http://www.techrepublic.com/blog/software-engineer/how-to-send-a-text-message-from-within-your-android-app/

2 个答案:

答案 0 :(得分:1)

查看manifest.xml的GUI版本。 Eclipse在手工输入权限方面似乎遇到了一些问题。删除有问题的权限并通过该工具重新添加。

这解决了我的问题同样的错误。

答案 1 :(得分:0)

//try this way
Intent intent = new Intent("android.intent.action.SENDTO", Uri.parse("smsto:" + "phoneNo"));
intent.putExtra("sms_body", "messageBody");
startActivity(intent);