Java 发送短信:用户10074没有android.permission.SEND\u短信
我正在写一个应用程序,将通过短信发送信息到输入的号码。然而,当我尝试发送消息时,我得到一个错误:“用户10074没有android.permission.send_SMS”,即使我在清单中有此权限 以下是我用来发送短信的代码:Java 发送短信:用户10074没有android.permission.SEND\u短信,java,android,sms,android-manifest,Java,Android,Sms,Android Manifest,我正在写一个应用程序,将通过短信发送信息到输入的号码。然而,当我尝试发送消息时,我得到一个错误:“用户10074没有android.permission.send_SMS”,即使我在清单中有此权限 以下是我用来发送短信的代码: private void setupmessageButton(){ Button messageButton = (Button) findViewById(R.id.button2); messageButton.setOnClickListener(
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>
看看manifest.xml的GUI版本。根据我的经验,Eclipse在手动输入权限方面似乎存在一些问题。删除有问题的权限并通过工具重新添加
这解决了我的问题,但出现了相同的错误。使用这种方式似乎与在每部手机上使用内置消息应用程序大致相同。当我尝试这种方式时,信息无法发送。我想这又是因为我没有电话留言计划,对吗?是否仍然可以使用Wifi连接向另一部手机发送短信?
//try this way
Intent intent = new Intent("android.intent.action.SENDTO", Uri.parse("smsto:" + "phoneNo"));
intent.putExtra("sms_body", "messageBody");
startActivity(intent);