不幸的是,申请被停止了

时间:2015-04-05 06:22:02

标签: android

我正在尝试向手机号码发送短信,但它显示不幸被停止

The Full Lgcat Errors: 
    04-05 06:31:19.682: E/AndroidRuntime(2231): FATAL EXCEPTION: main
04-05 06:31:19.682:
 E/AndroidRuntime(2231): java.lang.SecurityException: Sending SMS message: uid 10042 does not have android.permission.SEND_SMS.
04-05 06:31:19.682:
 E/AndroidRuntime(2231):    at android.os.Parcel.readException(Parcel.java:1425)
04-05 06:31:19.682: 
E/AndroidRuntime(2231):     at android.os.Parcel.readException(Parcel.java:1379)
04-05 06:31:19.682: 
E/AndroidRuntime(2231):     at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:434)
04-05 06:31:19.682:
E/AndroidRuntime(2231):     at android.telephony.SmsManager.sendTextMessage(SmsManager.java:87)
04-05 06:31:19.682: 
E/AndroidRuntime(2231):     at android.telephony.gsm.SmsManager.sendTextMessage(SmsManager.java:79)
04-05 06:31:19.682:
 E/AndroidRuntime(2231):    at com.example.validation.sms$1.onClick(sms.java:43)
04-05 06:31:19.682: 
E/AndroidRuntime(2231):     at android.view.View.performClick(View.java:4202)
04-05 06:31:19.682: 
E/AndroidRuntime(2231):     at android.view.View$PerformClick.run(View.java:17340)
04-05 06:31:19.682: 

E/AndroidRuntime(2231): at android.os.Handler.handleCallback(Handler.java:725) 04-05 06:31:19.682: E/AndroidRuntime(2231): at android.os.Handler.dispatchMessage(Handler.java:92) 04-05 06:31:19.682: E/AndroidRuntime(2231): at android.os.Looper.loop(Looper.java:137) 04-05 06:31:19.682: E/AndroidRuntime(2231): at android.app.ActivityThread.main(ActivityThread.java:5039) 04-05 06:31:19.682: E/AndroidRuntime(2231): at java.lang.reflect.Method.invokeNative(Native Method) 04-05 06:31:19.682: E/AndroidRuntime(2231): at java.lang.reflect.Method.invoke(Method.java:511) 04-05 06:31:19.682: E/AndroidRuntime(2231): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 04-05 06:31:19.682: E/AndroidRuntime(2231): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 04-05 06:31:19.682: E/AndroidRuntime(2231): at dalvik.system.NativeStart.main(Native Method)

package com.example.validation;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class sms extends Activity {

EditText e1,e2;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sms);

e1=(EditText)findViewById(R.id.mobile_no);
e2=(EditText)findViewById(R.id.message);
b1=(Button)findViewById(R.id.send);
b1.setOnClickListener(new OnClickListener() {

@SuppressWarnings("deprecation")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String no=e1.getText().toString();
String msg=e2.getText().toString();

Intent i=new Intent(getApplicationContext(),sms.class);
PendingIntent pi=PendingIntent.getActivity 
(getApplicationContext(), 0, i, 0);
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage(no, null, msg, pi, null);

Toast.makeText(getApplicationContext(), "Message sent",      
Toast.LENGTH_LONG).show();
}
});
}}

1 个答案:

答案 0 :(得分:0)

在清单文件上添加这些权限

<uses-permission android:name="android.permission.READ_CONTACTS" />

 <uses-permission android:name="android.permission.SEND_SMS" />