I want to send messages using textlocal.I register on the site,created a new Api Key and followed a youtube tutorial but Iam not getting the message.Instead Iam getting a toast of success only. Iam uploading the code please any can help me out that whats Iam missing here it not sending the text to device only giving me toast of success
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=" + "<SECRET-API-KEY>";
String message = "&message=" + editTextMessage.getText().toString();
String sender = "&sender=" + "<SENDER-NAME>";
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);
}