Umair Iqbal
Umair Iqbal

Reputation: 2069

Sending messages through net in android

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

Upvotes: 1

Views: 537

Answers (0)

Related Questions