2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-22 09:58:08 +00:00

Started implementing the Send SMS plugin

This commit is contained in:
Albert Vaca 2015-09-08 01:13:39 -07:00
parent b4f8d037e6
commit 506bc8d2c2
5 changed files with 186 additions and 12 deletions

View File

@ -14,21 +14,16 @@
android:smallScreens="true"
android:xlargeScreens="true" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission
android:name="android.permission.READ_PHONE_STATE"
android:required="false" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission
android:name="android.permission.RECEIVE_SMS"
android:required="false" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" android:required="false" />
<uses-permission android:name="android.permission.RECEIVE_SMS" android:required="false" />
<uses-permission android:name="android.permission.SEND_SMS" android:required="false" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

View File

@ -153,5 +153,8 @@
<string name="refresh">Refresh</string>
<string name="unreachable_description">This paired device is not reachable. Make sure it is connected to your same network.</string>
<string name="no_file_browser">There are no file browsers installed.</string>
<string name="pref_plugin_telepathy">Send SMS</string>
<string name="pref_plugin_telepathy_desc">Send text messages from your desktop</string>
</resources>

View File

@ -33,6 +33,7 @@ import org.kde.kdeconnect.Plugins.MprisPlugin.MprisPlugin;
import org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin;
import org.kde.kdeconnect.Plugins.PingPlugin.PingPlugin;
import org.kde.kdeconnect.Plugins.SharePlugin.SharePlugin;
import org.kde.kdeconnect.Plugins.TelepathyPlugin.TelepathyPlugin;
import org.kde.kdeconnect.Plugins.TelephonyPlugin.TelephonyPlugin;
import java.util.Map;
@ -98,6 +99,7 @@ public class PluginFactory {
PluginFactory.registerPlugin(NotificationsPlugin.class);
PluginFactory.registerPlugin(MousePadPlugin.class);
PluginFactory.registerPlugin(SharePlugin.class);
PluginFactory.registerPlugin(TelepathyPlugin.class);
}
public static PluginInfo getPluginInfo(Context context, String pluginKey) {

View File

@ -0,0 +1,172 @@
/*
* Copyright 2014 Albert Vaca Cintora <albertvaka@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.kde.kdeconnect.Plugins.TelepathyPlugin;
import android.database.Cursor;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.Toast;
import org.kde.kdeconnect.NetworkPackage;
import org.kde.kdeconnect.Plugins.Plugin;
import org.kde.kdeconnect_tp.R;
import java.util.ArrayList;
import static android.provider.ContactsContract.CommonDataKinds;
import static android.provider.ContactsContract.Contacts;
public class TelepathyPlugin extends Plugin {
@Override
public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_telepathy);
}
@Override
public String getDescription() {
return context.getResources().getString(R.string.pref_plugin_telepathy_desc);
}
@Override
public boolean onCreate() {
return true;
}
@Override
public void onDestroy() {
}
@Override
public boolean onPackageReceived(NetworkPackage np) {
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_TELEPHONY)) {
return false;
}
if (np.getBoolean("sendSms")) {
String phoneNo = np.getString("phoneNumber");
String sms = np.getString("messageBody");
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
//TODO: Notify other end
} catch (Exception e) {
//TODO: Notify other end
Log.e("TelepathyPlugin", e.getMessage());
e.printStackTrace();
}
}
/*
if (np.getBoolean("requestContacts")) {
ArrayList<String> vCards = new ArrayList<String>();
Cursor cursor = context.getContentResolver().query(
Contacts.CONTENT_URI,
null,
Contacts.HAS_PHONE_NUMBER + " > 0 ",
null,
null
);
if (cursor != null && cursor.moveToFirst()) {
try {
do {
String lookupKey = cursor.getString(cursor.getColumnIndex(Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey);
AssetFileDescriptor fd = null;
try {
fd = context.getContentResolver()
.openAssetFileDescriptor(uri, "r");
FileInputStream fis = fd.createInputStream();
byte[] b = new byte[(int) fd.getDeclaredLength()];
fis.read(b);
String vCard = new String(b);
vCards.add(vCard);
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.e("RequestContacts", e.getMessage());
} catch (Exception e) {
e.printStackTrace();
Log.e("RequestContacts", e.getMessage());
} finally {
if (fd != null) fd.close();
}
} while (cursor.moveToNext());
Log.e("Contacts","Size: "+vCards.size());
} catch (Exception e) {
e.printStackTrace();
Log.e("RequestContacts", e.getMessage());
} finally {
cursor.close();
}
}
NetworkPackage answer = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_TELEPHONY);
answer.set("contacts",vCards);
device.sendPackage(answer);
}
*/
/*
if (np.getBoolean("requestNumbers")) {
ArrayList<String> numbers = new ArrayList<String>();
Cursor cursor = context.getContentResolver().query(
CommonDataKinds.Phone.CONTENT_URI,
new String[]{
CommonDataKinds.Phone.DISPLAY_NAME,
CommonDataKinds.Phone.NUMBER
},
Contacts.HAS_PHONE_NUMBER + " > 0 ",
null,
null
);
if (cursor != null && cursor.moveToFirst()) {
try {
do {
String number = cursor.getString(cursor.getColumnIndex(CommonDataKinds.Phone.NUMBER));
String name = cursor.getString(cursor.getColumnIndex(CommonDataKinds.Phone.DISPLAY_NAME));
numbers.add(number);
} while (cursor.moveToNext());
Log.e("Numbers","Size: "+numbers.size());
} catch (Exception e) {
e.printStackTrace();
Log.e("RequestContacts", e.getMessage());
} finally {
cursor.close();
}
}
NetworkPackage answer = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_TELEPHONY);
answer.set("numbers",numbers);
device.sendPackage(answer);
}
*/
return true;
}
}

View File

@ -28,6 +28,7 @@ import android.media.AudioManager;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.util.Log;
import org.kde.kdeconnect.Helpers.ContactsHelper;
import org.kde.kdeconnect.NetworkPackage;
@ -98,8 +99,8 @@ public class TelephonyPlugin extends Plugin {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_TELEPHONY);
if (phoneNumber != null) {
phoneNumber = ContactsHelper.phoneNumberLookup(context,phoneNumber);
np.set("phoneNumber", phoneNumber);
np.set("contactName", ContactsHelper.phoneNumberLookup(context, phoneNumber));
}
switch (state) {
@ -144,6 +145,7 @@ public class TelephonyPlugin extends Plugin {
if (lastState == TelephonyManager.CALL_STATE_RINGING) {
np.set("event","missedCall");
np.set("phoneNumber", lastPackage.getString("phoneNumber",null));
np.set("contactName", lastPackage.getString("contactName",null));
device.sendPackage(np);
}
@ -172,8 +174,8 @@ public class TelephonyPlugin extends Plugin {
String phoneNumber = message.getOriginatingAddress();
if (phoneNumber != null) {
phoneNumber = ContactsHelper.phoneNumberLookup(context, phoneNumber);
np.set("phoneNumber",phoneNumber);
np.set("phoneNumber", phoneNumber);
np.set("contactName", ContactsHelper.phoneNumberLookup(context, phoneNumber));
}
device.sendPackage(np);