1

I'm creating an application in which I have a requirement that a user can send a message to other user but while sending message he can not see the user number and message should be send through net.Like in careem when captain call a customer the customer receive a call from the company not by Careem captain. I have seen and tried text local(Sms Gateway) in application but in that Iam getting the successful toast but message is not being send.I have created an account and created an Api Key This the code for class :

public class MainActivity extends AppCompatActivity {

    private EditText editTextTo, editTextMessage;
    RelativeLayout activity_main;
    Button button;
    private RequestQueue requestQueue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        activity_main = (RelativeLayout) findViewById(R.id.activity_main);
        editTextTo = (EditText) findViewById(R.id.editTextTo);
        editTextMessage = (EditText) findViewById(R.id.editTextMessage);
        button = (Button) findViewById(R.id.btn);
        requestQueue = Volley.newRequestQueue(this);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    // Construct data
                    String apiKey = "apikey=" + "syKXFnvCg9I-TNtZZUIeseWZX5g*************";
                    String message = "&message=" + editTextMessage.getText().toString();
                    String sender = "&sender=" + "Jims Autos";
                    String numbers = "&numbers=" + editTextTo.getText().toString();

                    // Send data
                    HttpURLConnection conn = (HttpURLConnection) new URL("https://api.txtlocal.com/send/?").openConnection();
                    String data = apiKey + numbers + message + sender;
                    conn.setDoOutput(true);
                    conn.setRequestMethod("POST");
                    conn.setRequestProperty("Content-Length", Integer.toString(data.length()));
                    conn.getOutputStream().write(data.getBytes("UTF-8"));
                    final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                    final StringBuffer stringBuffer = new StringBuffer();
                    String line;
                    while ((line = rd.readLine()) != null) {
                        Toast.makeText(MainActivity.this, line.toString(), Toast.LENGTH_LONG).show();
                    }
                    rd.close();


                } catch (Exception e) {
                    Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            }
        });

        StrictMode.ThreadPolicy st = new StrictMode.ThreadPolicy.Builder().build();
        StrictMode.setThreadPolicy(st);
    }
}

But Iam getting only this toast message.I am uploading the picture :

enter image description here

Secondly I couldn't really understand this service,according to me in this text local its also sending message from sim not the net The requirement given to me is that I dont have to setup a sim for this message service.Msg should be send through net or some network no sim should be use for this service, I have to buy some online package for this service. So my question is this possible if yes how can I do that to send message from net.Iam searching from yesterday but couldn't find a way to do that. Note : Please dont give the idea of Sms Manager I have already used that and my requirements are totally different Thanku

Umair Iqbal
  • 1,959
  • 1
  • 19
  • 38
  • Do you mean you want to send a message via internet without server? – Elias Fazel Jan 02 '20 at 08:03
  • Yes I have to use some internet service for that. Sms should be send without using any sim – Umair Iqbal Jan 02 '20 at 08:07
  • then it s normal internet message like facebook, whatsapp & etc. first save data on a server then send notification of data to target. check out this https://github.com/FirebaseExtended/firechat/blob/master/README.md – Elias Fazel Jan 03 '20 at 07:27
  • Your code looks fine and from the screenshot, it looks like the message was sent successfully. You should try formatting the phone number in [E.164 formatting](https://support.twilio.com/hc/en-us/articles/223183008-Formatting-International-Phone-Numbers). Some of the SMS Gateway services out there requires a number in this format. – Ravi Patel Feb 27 '20 at 13:09

0 Answers0