簡體   English   中英

如何檢測某人的SIM卡是否處於活動狀態

[英]How to detect someone's sim card is active or not

我每天有40到50個電話號碼。 目前,我們正在手動調用每個人,以檢測每個人的狀態,例如電話號碼是否處於活動狀態(如果電話正在響鈴)。我想以編程方式進行操作。 是否可以通過編程方式呼叫每個號碼,並且如果電話鈴響正在進行,則將其設置為活動狀態,否則為非活動狀態?

是的,可以,但是最好使用sms Delivery Report來簽入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;
            }

        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM