Skip to content
This repository has been archived by the owner on Sep 28, 2019. It is now read-only.

Commit

Permalink
sms forwarding added
Browse files Browse the repository at this point in the history
  • Loading branch information
jochen@homeland committed Feb 16, 2019
1 parent 1e7a7a5 commit f309117
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Sometimes a new giant smartphone is too big for me at parties. It's nice to
be able to redirect all your messages to a little old one. In an emergency
you can at least answer via SMS. My app redirects almost everything to a
Jabber account or to a Gotify server. It's a little everyday hack that I
Jabber account, to your Gotify server or as sms. It's a little everyday hack that I
don't want to keep from the FOSS community.

The App sends all Android text notifications to a xmpp jabber account. It
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
minSdkVersion 19
// upload alias
targetSdkVersion 22
versionCode 82
versionName "0.82"
versionCode 83
versionName "0.83"
}
buildTypes {
release {
Expand Down
Binary file modified app/release/click.dummer.notify_to_jabber.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":82,"versionName":"0.82","enabled":true,"outputFile":"click.dummer.notify_to_jabber.apk","fullName":"release","baseName":"release"},"path":"click.dummer.notify_to_jabber.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":83,"versionName":"0.83","enabled":true,"outputFile":"click.dummer.notify_to_jabber.apk","fullName":"release","baseName":"release"},"path":"click.dummer.notify_to_jabber.apk","properties":{}}]
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- uses-permission android:name="android.permission.SEND_SMS" / -->
<uses-permission android:name="android.permission.SEND_SMS" />

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package click.dummer.notify_to_jabber;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -13,6 +14,7 @@
import android.preference.PreferenceManager;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.telephony.SmsManager;
import android.text.SpannableString;
import android.util.Log;

Expand All @@ -32,6 +34,7 @@
import java.io.IOException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

Expand All @@ -42,6 +45,12 @@ public class NotificationService extends NotificationListenerService {
private static String TAG = "NotificationService";
private static SharedPreferences mPreferences;

private SmsManager smsManager = SmsManager.getDefault();
private ArrayList<String> parts;
private String phone;
private ArrayList<PendingIntent> sentPIs;
private ArrayList<PendingIntent> deliveredPIs;

private String lastPost = "";

public static class GotifyMessage {
Expand Down Expand Up @@ -148,6 +157,11 @@ public void onNotificationPosted(StatusBarNotification sbn) {

lastPost = msg;

title = title.trim();
if (title.endsWith(":")) {
title = title.substring(0, title.lastIndexOf(":"));
}

//sendNetBroadcast(title, msg, pack, formatOut.format(new Date()), icon);
Intent i = new Intent(ACTION_INCOMING_MSG);
i.putExtra("notification_event", msg);
Expand All @@ -172,8 +186,44 @@ public void onNotificationPosted(StatusBarNotification sbn) {
default:
}
if (mPreferences.getBoolean("with_source", true) == false) pack = "";

// ++++ Jabber
new SendJabberTask().execute(title, msg, pack, time);

// ++++ Gotify
sendGotify(title, msg, pack, time);

// ++++ SMS
phone = mPreferences.getString("phone", "").trim();
if (mPreferences.getBoolean("sms_forward", false) && phone.equals("") == false) {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";

PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);

sentPIs = new ArrayList<>();
deliveredPIs = new ArrayList<>();
sentPIs.add(sentPI);
deliveredPIs.add(deliveredPI);

String message = "";
if (!time.equals("")) time = time + "\n";
if (pack.equals("")) {
message = time + title + ": " + msg;
} else {
message = "["+pack+"] " + time + title + ": " + msg;
}

int limit = mPreferences.getInt("maxchars", 140);
if (limit>0 && message.length()>limit) {
message = message.substring(0, limit-1);
}
//smsManager.sendTextMessage(phone, null, message, null, null);
parts = smsManager.divideMessage(message);
smsManager.sendMultipartTextMessage(phone, null, parts, sentPIs, deliveredPIs);
}

}

private void sendGotify(String... strings) {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/menu/options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@
<item
android:id="@+id/action_sms"
android:title="@string/settings"
android:visible="false"
app:showAsAction="never" />
</menu>
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<string name="sms_hint">Alle Benachrichtigungen lassen sich auch via SMS an ein anderes Handy senden. Auch hier gilt: KEINE NACHRICHTEN SCHLEIFEN BILDEN! Es sollte sich um ein anderes Gerät handeln!</string>
<string name="sms_maxparts">SMS Länge</string>
<string name="sms_maxparts_hint">In wie viele (Teil-)SMS darf eine Benachrichtigung versendet werden?\n\n0 = unbegrenzt</string>
<string name="sms_maxparts_hint">Nach wie vielen Zeichen soll eine SMS abgeschnitten werden?\n\n0 = nicht abschneiden</string>
<string name="sms_daily">Tageslimit</string>
<string name="sms_daily_hint">Wie viele (Teil-)SMS dürfen am Tag versendet werden?\n\n0 = unbegrenzt</string>
<string name="sms_nr">Empfängernummer</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<string name="sms_hint">Notifications could be sent to another phone via sms. Attention! DO NOT BUILD LOOPS! It should really be another phone!</string>
<string name="sms_maxparts">sms length</string>
<string name="sms_maxparts_hint">How many (multipart) sms should a notification use?\n\n0 = unlimited</string>
<string name="sms_maxparts_hint">After how many letters should a sms cut off?\n\n0 = no cut</string>
<string name="sms_daily">day limit</string>
<string name="sms_daily_hint">How many (multipart) sms should be send a day?\n\n0 = unlimited</string>
<string name="sms_nr">send to phone number...</string>
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
android:summary="@string/sms_hint" />

<click.dummer.notify_to_jabber.IntEditPreference
android:key="maxparts"
android:key="maxchars"
android:title="@string/sms_maxparts"
android:summary="@string/sms_maxparts_hint"
android:numeric="integer"
android:defaultValue="1"
android:maxLength="2" />
android:defaultValue="140"
android:maxLength="3" />

<click.dummer.notify_to_jabber.IntEditPreference
<!-- click.dummer.notify_to_jabber.IntEditPreference
android:key="maxday"
android:title="@string/sms_daily"
android:summary="@string/sms_daily_hint"
android:numeric="integer"
android:defaultValue="1"
android:maxLength="3" />
android:defaultValue="10"
android:maxLength="3" / -->

<EditTextPreference
android:key="phone"
Expand Down
2 changes: 1 addition & 1 deletion metadata/de-DE/full_description.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Manchmal ist es sehr unpraktisch sein großes Smartphone mit zu Partys zu nehmen. Da wäre es doch praktisch alle Benachrichtigungen auf ein kleineres, älters Handy weiter zu senden. In Notfällen kann man dann immer noch via SMS antworten. Jabber2Notify versucht alle Textnachrichten an einen <a href="https://www.jabber.org/">Jabber</a> Account oder einen <a href="https://github.com/gotify/server/">Gotify</a> Server weiter zu leiten. Diesen kleinen Altags-Hack möchte ich der FOSS-Community nicht vorenthalten. 😉
Manchmal ist es sehr unpraktisch sein großes Smartphone mit zu Partys zu nehmen. Da wäre es doch praktisch alle Benachrichtigungen auf ein kleineres, älters Handy weiter zu senden. In Notfällen kann man dann immer noch via SMS antworten. Jabber2Notify versucht alle Textnachrichten an einen <a href="https://www.jabber.org/">Jabber</a> Account oder einen <a href="https://github.com/gotify/server/">Gotify</a> Server weiter zu leiten. Es geht auch eine Umleitung der Nachrichten als SMS. Diesen kleinen Altags-Hack möchte ich der FOSS-Community nicht vorenthalten. 😉

Die App benutzt die <a href="https://github.com/igniterealtime/Smack/">Smack lib</a> (Apache 2.0 license), um sich bei Jabber anzumelden und die Nachrichten an einen anderen Jabber Account weiter zu leiten.

Expand Down
Binary file modified metadata/de-DE/images/phoneScreenshots/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added metadata/de-DE/images/phoneScreenshots/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added metadata/de-DE/images/phoneScreenshots/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion metadata/de-DE/short_description.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Leitet Handy Nachrichten weiter an Jabber oder einen Gotify Server
Leitet Handy Nachrichten weiter an Jabber, deinen Gotify Server oder via SMS
2 changes: 1 addition & 1 deletion metadata/en-US/full_description.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Sometimes a new giant smartphone is too big for me at parties. It is nice to be able to redirect all your messages to a little old one. In an emergency you can at least answer via SMS. Jabber2Notify redirects almost everything to a <a href="https://www.jabber.org/">Jabber</a> account or to a <a href="https://github.com/gotify/server/">Gotify</a> server. The app is a little everyday hack that I do not want to keep from the FOSS community. 😉
Sometimes a new giant smartphone is too big for me at parties. It is nice to be able to redirect all your messages to a little old one. In an emergency you can at least answer via SMS. Jabber2Notify redirects almost everything to a <a href="https://www.jabber.org/">Jabber</a> account or to a <a href="https://github.com/gotify/server/">Gotify</a> server. Forwarding with sms is possible, too. The app is a little everyday hack that I do not want to keep from the FOSS community. 😉

The app sends all text notifications to a xmpp jabber account. It uses the <a href="https://github.com/igniterealtime/Smack/">Smack lib</a> (Apache 2.0 license) for this.

Expand Down
Binary file modified metadata/en-US/images/phoneScreenshots/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added metadata/en-US/images/phoneScreenshots/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added metadata/en-US/images/phoneScreenshots/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion metadata/en-US/short_description.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Forward all notifications to a Jabber account or your Gotify server
Forward all notifications to a Jabber account, your Gotify server or creates sms

0 comments on commit f309117

Please sign in to comment.