Home » Java » java – i want to send sms,location to phone number using android-Exceptionshub

java – i want to send sms,location to phone number using android-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

i need the phone number use to send sms use phone number save in firebase database and need to send current location via sms using android

i try this:

buttonSend.setEnabled(false);
        if (checkpermission(Manifest.permission.SEND_SMS)) {
            buttonSend.setEnabled(true);
        } else {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS}, SEND_SMS_REQUEST_CODE);
        }

        buttonSend.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                String sms = "help me i am in trouble";
                modelClass.setEphone1(ephone1.getText().toString());
                if (modelClass.getEphone1() == null | modelClass.getEphone1().length() == 0 || sms == null || sms.length() == 0) {
                    return;
                }
                if (checkpermission(Manifest.permission.SEND_SMS)) {

                    SmsManager smsManager = SmsManager.getDefault();
                    smsManager.sendTextMessage(modelClass.getEphone1(), null, sms, null, null);
                    Toast.makeText(getApplicationContext(), "SMS Sent!",
                            Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(getApplicationContext(),
                            "SMS faild, please try again later!",
                            Toast.LENGTH_LONG).show();
                }

            }
        });
    }

    public boolean checkpermission(String permission) {`enter code here`
        int check = ContextCompat.checkSelfPermission(this, permission);
        return (check == PackageManager.PERMISSION_GRANTED);
    }
How to&Answers: