我使用SMSmanager制作应用程序,但它崩溃了,这是我的代码
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
button1=(Button)findViewById(R.id.b1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String SENT = "SMS_SENT";
String phoneNumber = "0123456789";
String message = "Hello World!";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendMultipartTextMessage(phoneNumber, null,message, null, null);
Toast.makeText(getApplicationContext(),"wow",Toast.LENGTH_LONG).show();
}
});
}
我已将权限添加到清单文件
这是logcat
01-02 08:05:52.126 4215-4215/? I/art: Not late-enabling -Xcheck:jni (already on)
01-02 08:05:52.248 4215-4215/com.example.humam.blacne W/System: ClassLoader referenced unknown path: /data/app/com.example.humam.blacne-2/lib/x86
01-02 08:05:52.578 4215-4242/com.example.humam.blacne D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-02 08:05:52.582 4215-4215/com.example.humam.blacne D/: HostConnection::get() New Host Connection established 0xaa24db20, tid 4215
01-02 08:05:52.638 4215-4242/com.example.humam.blacne D/: HostConnection::get() New Host Connection established 0xaa24dd40, tid 4242
01-02 08:05:52.655 4215-4242/com.example.humam.blacne I/OpenGLRenderer: Initialized EGL, version 1.4
01-02 08:05:52.727 4215-4242/com.example.humam.blacne W/EGL_emulation: eglSurfaceAttrib not implemented
01-02 08:05:52.727 4215-x 4242/com.example.humam.blacne W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xabaf9300, error=EGL_SUCCESS
感谢帮助
答案 0 :(得分:0)
你们之所以使用模拟的话 第二个把发送短信放在试试中
try
{
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(PhoneNumber, null, SmsContent, null, null);
Toast.makeText(getApplicationContext(),"wow",Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(), e.printStackTrace,Toast.LENGTH_LONG).show();
}
如果是尝试抓住应用程序不会崩溃
答案 1 :(得分:-2)
也许你没有这个许可?尝试在AndroidManifest.xml中添加此行
<uses-permission android:name="android.permission.SEND_SMS"/>