我每天有40到50个电话号码。目前我们手动呼叫每个人以检测每个人的状态,如电话号码是否有效(如果是呼叫振铃)。我想以编程方式执行此操作。有可能,以编程方式呼叫每个号码,如果电话铃声正在进行,那么设置它的状态是否有效,否则无效?
答案 0 :(得分:1)
是的,这是可能的,但最好使用短信发送报告来检查android你可以创建一个程序,如果它显示发送报告比自动添加到活动否则不活动
BroadcastReceiver sendBroadcastReceiver = new sentReceiver();
BroadcastReceiver deliveryBroadcastReciever = new deliverReceiver();;
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
try {
unregisterReceiver(sendBroadcastReceiver);
unregisterReceiver(deliveryBroadcastReciever);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
try {
unregisterReceiver(sendBroadcastReceiver);
unregisterReceiver(deliveryBroadcastReciever);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
send_sms.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (textView.getText().toString().equals("")
| textView.getText().toString().equals(null)) {
Toast.makeText(SendSMS.this, enter_ph_no, Toast.LENGTH_LONG)
.show();
} else {
sendSMS(textView.getText().toString(), "sms_content");
finish();
}
}
});
private void sendSMS(String phoneNumber, String message) {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
registerReceiver(sendBroadcastReceiver, new IntentFilter(SENT));
registerReceiver(deliveryBroadcastReciever, new IntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
class deliverReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), sms_delivered,
Toast.LENGTH_SHORT).show();
//Here you write any code to put the number in DB or filebased etc
that number is active
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), sms_not_delivered,
Toast.LENGTH_SHORT).show();
break;
}
}
}
class sentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), sms_sent, Toast.LENGTH_SHORT)
.show();
startActivity(new Intent(SendSMS.this, ChooseOption.class));
overridePendingTransition(R.anim.animation, R.anim.animation2);
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT)
.show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}