繁体   English   中英

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

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

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

            }
        }
    });
    }

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

<?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 -您的Android应用/

看一下manifest.xml的GUI版本。 在我的手动输入权限方面,Eclipse似乎存在一些问题。 删除有问题的权限,然后通过该工具重新添加它。

这解决了我的问题,并出现了相同的错误。

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