Skip to content

Commit

Permalink
forward incoming text messages
Browse files Browse the repository at this point in the history
  • Loading branch information
serggl committed Oct 26, 2015
1 parent 7cece49 commit f1128ff
Show file tree
Hide file tree
Showing 9 changed files with 449 additions and 235 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,4 +8,5 @@ build
.idea
.settings
.metadata
*.iml

2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -16,7 +16,7 @@ repositories {
dependencies {
compile 'com.google.android.gms:play-services:3.1.36'
compile 'com.android.support:support-v4:19.0.0'
compile 'com.anjlab.android:fx:1.0.6@aar'
compile 'com.jakewharton:butterknife:6.1.0'
}

android {
Expand Down
2 changes: 1 addition & 1 deletion local.properties
Expand Up @@ -7,5 +7,5 @@
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Mon Oct 26 17:23:50 MSK 2015
#Mon Oct 26 18:02:23 MSK 2015
sdk.dir=/Users/sergeyglukhov/android-sdk
10 changes: 8 additions & 2 deletions src/main/AndroidManifest.xml
Expand Up @@ -4,14 +4,13 @@
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />

<permission
android:name="com.anjlab.android.smsgateway.gcm.permission.C2D_MESSAGE"
Expand Down Expand Up @@ -45,7 +44,14 @@
</intent-filter>
</receiver>

<receiver android:name=".SmsMessageReceiver">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>

<service android:name=".SmsIntentService" />
<service android:name=".HttpHookIntentService" />
</application>

</manifest>
@@ -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();
}

}
}

0 comments on commit f1128ff

Please sign in to comment.