我在具有android marshmallow的模拟器上测试了这段代码,模拟器上没有崩溃。我看不到logcat错误,因为我发送调试apk给我的朋友,他告诉我有一个崩溃。你们能猜出这个问题吗?它简单的两行代码。按钮点击发生崩溃,里面的代码就在这里......
if(Build.VERSION.SDK_INT >= 23){
if(checkSelfPermission(
Manifest.permission.READ_SMS)
== PackageManager.PERMISSION_GRANTED && checkSelfPermission(
Manifest.permission.SEND_SMS)
== PackageManager.PERMISSION_GRANTED){
prepareSend();
}else {
if (!shouldShowRequestPermissionRationale(
Manifest.permission.SEND_SMS)) {
requestPermissions(
new String[]{Manifest.permission.READ_SMS, Manifest.permission.SEND_SMS},
1);
}}
}else{
prepareSend();
}
其他代码很好,这里是准备发送,在低于23的设备上没有崩溃。
public void prepareSend() {
String phones = extractPhones();
if (TextUtils.isEmpty(phones) || TextUtils.isEmpty(messageText.getText().toString()) || TextUtils.isEmpty(bomb.getText().toString()) || TextUtils.isEmpty(delay.getText().toString()))
Toast.makeText(this,"One or more required field is empty.",Toast.LENGTH_LONG).show();
else {
//Toast.makeText(this,phones,Toast.LENGTH_LONG).show();
intent = new Intent(getBaseContext(),FreshService.class);
intent.putExtra("message",messageText.getText().toString().trim());
intent.putExtra("bombs",Integer.parseInt(bomb.getText().toString()));
int delayLong = Integer.parseInt(delay.getText().toString());
intent.putExtra("interval",delayLong);
intent.putExtra("phones", phones);
startService(intent);
//Toast.makeText(getBaseContext(),"Service started successfully interval:" + delayLong,Toast.LENGTH_SHORT).show();
btnSend.setEnabled(false);
btnStop.setEnabled(true);
doBindService();
}
}