我正在编写一个应用程序,它将通过短信向输入的号码发送消息。但是,当我尝试发送消息时,我收到错误“用户 10074 没有 android.permission.SEND_SMS”,即使我在 list 中拥有此权限。
这是我用来发送短信的代码:
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();
}
}
});
}
这是具有所需权限的 list :
<?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/
最佳答案
看一下manifest.xml 的GUI 版本。根据我的经验,Eclipse 在手动输入权限方面似乎存在一些问题。删除有问题的权限并通过工具重新添加。
这解决了我的问题,但出现了同样的错误。
关于java - 正在发送短信 : User 10074 does not have android. 权限.SEND_SMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20112129/