Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
449 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ build | |
.idea | ||
.settings | ||
.metadata | ||
*.iml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/com/anjlab/android/smsgateway/gcm/HttpHookIntentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.anjlab.android.smsgateway.gcm; | ||
|
||
import android.app.IntentService; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.OutputStream; | ||
import java.io.OutputStreamWriter; | ||
import java.net.URL; | ||
|
||
import javax.net.ssl.HttpsURLConnection; | ||
|
||
public class HttpHookIntentService extends IntentService { | ||
public static final String URL = "url"; | ||
public static final String TEXT = "text"; | ||
public static final String SENDER = "sender"; | ||
|
||
public HttpHookIntentService() { | ||
super("HttpHookIntentService"); | ||
} | ||
|
||
@Override | ||
protected void onHandleIntent(Intent intent) { | ||
Bundle extras = intent.getExtras(); | ||
|
||
try | ||
{ | ||
java.net.URL url = new URL(extras.getString(URL)); | ||
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); | ||
conn.setReadTimeout(10000); | ||
conn.setConnectTimeout(15000); | ||
conn.setRequestMethod("POST"); | ||
conn.setDoInput(true); | ||
conn.setDoOutput(true); | ||
|
||
OutputStream os = conn.getOutputStream(); | ||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); | ||
writer.write(String.format("content=%s&from_number=%s", | ||
extras.getString(TEXT), | ||
extras.getString(SENDER))); | ||
writer.flush(); | ||
writer.close(); | ||
os.close(); | ||
conn.getInputStream().close(); | ||
} | ||
catch (Exception e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.