I am trying to trigger a macrodroid webhook from my app via http post but i can’t figure it out. Can someone help me?
I am trying to trigger a macrodroid webhook from my app via http post but i can’t figure it out. Can someone help me?
String string_url = "https://trigger.macrodroid.com/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
public void webhook_post(String string_url) {
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(new Runnable() {
@Override
public void run() {
HttpURLConnection conn = null;
try {
URL url = new URL(string_url);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("application/json", "ok");
conn.setDoOutput(true);
conn.connect();
} catch (Exception e) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast toast = Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT);
toast.show();
}
});
} finally {
if (conn != null) {
conn.disconnect();
}
}
}
});
}