简体   繁体   中英

Sending SMS message: User 10074 does not have android.permission.SEND_SMS

I am writing an app that will send a message to an inputted number through SMS. However when I try to send the message I get the error that "User 10074 does not have android.permission.SEND_SMS" even though I have this permission in my Manifest.

Here is the code I am using to send the 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();

            }
        }
    });
    }

And this is the manifest with the needed permissions:

<?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>

Could the reason the message won't send be that the phone I am trying to run it on does not have a data plan? Or is there an underlying problem in my coding that is preventing the message from going through?

If it is any help, I was basing this code off an example I found online at: http://www.techrepublic.com/blog/software-engineer/how-to-send-a-text-message-from-within-your-android-app/

Take a look at the GUI version of the manifest.xml. Eclipse has seemed to have some issues in my experience with hand typed permissions. Delete the troubled permission and re-add it through the tool.

This fixed my issue with the same error.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM