简体   繁体   English

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

[英]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. 我正在编写一个应用程序,它将通过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. 但是,当我尝试发送消息时,即使我的清单中具有此权限,也会收到错误消息“用户10074没有android.permission.SEND_SMS”。

Here is the code I am using to send the SMS: 这是我用来发送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/ 如果有帮助,我将根据在以下网址在线找到的示例创建此代码: http : //www.techrepublic.com/blog/software-engineer/how-to-send-a-text-message-from-within -您的Android应用/

Take a look at the GUI version of the manifest.xml. 看一下manifest.xml的GUI版本。 Eclipse has seemed to have some issues in my experience with hand typed permissions. 在我的手动输入权限方面,Eclipse似乎存在一些问题。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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