use of com.manan.dev.ec2018app.Utilities.SmsListener in project EC2018App by Manan-YMCA.
the class FragmentOtpChecker method sendSMS.
private void sendSMS(final String phone, final String otpNum) {
bar.setVisibility(View.VISIBLE);
String url = getResources().getString(R.string.send_sms_api);
RequestQueue queue = Volley.newRequestQueue(mContext);
StringRequest smsReq = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// TODO
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO
bar.setVisibility(View.GONE);
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("From", "CLMYCA");
params.put("To", phone);
params.put("TemplateName", "culmyca-otp");
params.put("VAR1", otpNum);
return params;
}
};
queue.add(smsReq);
if (ActivityCompat.checkSelfPermission(mContext, android.Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED) {
bar.setVisibility(View.GONE);
} else {
IncomingSms.bindListener(new SmsListener() {
@Override
public void messageReceived(String messageText) {
if (messageText.contains("Culmyca")) {
otp = messageText.substring(0, 6);
if (otp.length() == 6) {
et1.setText(otp.substring(0, 1));
et2.setText(otp.substring(1, 2));
et3.setText(otp.substring(2, 3));
et4.setText(otp.substring(3, 4));
et5.setText(otp.substring(4, 5));
et6.setText(otp.substring(5, 6));
} else {
bar.setVisibility(View.GONE);
}
} else {
bar.setVisibility(View.GONE);
}
}
});
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
bar.setVisibility(View.GONE);
et1.requestFocus();
}
}, 10000);
}
}
Aggregations