我收到上述错误,我无法使用此代码发送短信请帮助我。我的清单文件是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.user8.seminia" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-permission android:name="android.permission.SEND_SMS" />
<activity
android:name=".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>
</application>
我无法使用权限发送短信,我也在发布我的主要活动代码
EditText name,phone,email;
Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name=(EditText)findViewById(R.id.editText);
phone=(EditText)findViewById(R.id.editText3);
email=(EditText)findViewById(R.id.editText2);
bt=(Button)findViewById(R.id.button);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String user=name.getText().toString();
String num=phone.getText().toString();
String cont=email.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("9350581140", null,"hello", null, null);
Toast.makeText(getApplicationContext(), "SMS sent.",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again."+e.toString(),
Toast.LENGTH_LONG).show();
Log.d("sms",e.toString());
e.printStackTrace();
}
}
});
}
答案 0 :(得分:3)
uses-permission
元素位于manifest
下,不在清单XML中的application
下。