use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class MprisReceiverPlugin method sendPlayerList.
private void sendPlayerList() {
NetworkPacket np = new NetworkPacket(PACKET_TYPE_MPRIS);
np.set("playerList", players.keySet());
device.sendPacket(np);
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class SMSPlugin method onPacketReceived.
@Override
public boolean onPacketReceived(NetworkPacket np) {
long subID;
switch(np.getType()) {
case PACKET_TYPE_SMS_REQUEST_CONVERSATIONS:
return this.handleRequestAllConversations(np);
case PACKET_TYPE_SMS_REQUEST_CONVERSATION:
return this.handleRequestSingleConversation(np);
case PACKET_TYPE_SMS_REQUEST:
String textMessage = np.getString("messageBody");
subID = np.getLong("subID", -1);
List<SMSHelper.Address> addressList = SMSHelper.jsonArrayToAddressList(np.getJSONArray("addresses"));
if (addressList == null) {
// If the List of Address is null, then the SMS_REQUEST packet is
// most probably from the older version of the desktop app.
addressList = new ArrayList<>();
addressList.add(new SMSHelper.Address(np.getString("phoneNumber")));
}
List<SMSHelper.Attachment> attachedFiles = SMSHelper.jsonArrayToAttachmentsList(np.getJSONArray("attachments"));
SmsMmsUtils.sendMessage(context, textMessage, attachedFiles, addressList, (int) subID);
break;
case TelephonyPlugin.PACKET_TYPE_TELEPHONY_REQUEST:
if (np.getBoolean("sendSms")) {
String phoneNo = np.getString("phoneNumber");
String sms = np.getString("messageBody");
subID = np.getLong("subID", -1);
try {
SmsManager smsManager = subID == -1 ? SmsManager.getDefault() : SmsManager.getSmsManagerForSubscriptionId((int) subID);
ArrayList<String> parts = smsManager.divideMessage(sms);
// If this message turns out to fit in a single SMS, sendMultipartTextMessage
// properly handles that case
smsManager.sendMultipartTextMessage(phoneNo, null, parts, null, null);
// TODO: Notify other end
} catch (Exception e) {
// TODO: Notify other end
Log.e("SMSPlugin", "Exception", e);
}
}
break;
case PACKET_TYPE_SMS_REQUEST_ATTACHMENT:
long partID = np.getLong("part_id");
String uniqueIdentifier = np.getString("unique_identifier");
NetworkPacket networkPacket = SmsMmsUtils.partIdToMessageAttachmentPacket(context, partID, uniqueIdentifier, PACKET_TYPE_SMS_ATTACHMENT_FILE);
if (networkPacket != null) {
device.sendPacket(networkPacket);
}
break;
}
return true;
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class SMSPlugin method constructBulkMessagePacket.
/**
* Construct a proper packet of PACKET_TYPE_SMS_MESSAGE from the passed messages
*
* @param messages Messages to include in the packet
* @return NetworkPacket of type PACKET_TYPE_SMS_MESSAGE
*/
private static NetworkPacket constructBulkMessagePacket(Collection<SMSHelper.Message> messages) {
NetworkPacket reply = new NetworkPacket(PACKET_TYPE_SMS_MESSAGE);
JSONArray body = new JSONArray();
for (SMSHelper.Message message : messages) {
try {
JSONObject json = message.toJSONObject();
body.put(json);
} catch (JSONException e) {
Log.e("Conversations", "Error serializing message", e);
}
}
reply.set("messages", body);
reply.set("version", SMS_MESSAGE_PACKET_VERSION);
return reply;
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class SendKeystrokesToHostActivity method sendKeys.
private void sendKeys(Device deviceId) {
String toSend;
if (binding.textToSend.getText() != null && (toSend = binding.textToSend.getText().toString().trim()).length() > 0) {
final NetworkPacket np = new NetworkPacket(MousePadPlugin.PACKET_TYPE_MOUSEPAD_REQUEST);
np.set("key", toSend);
BackgroundService.RunWithPlugin(this, deviceId.getDeviceId(), MousePadPlugin.class, plugin -> plugin.sendKeyboardPacket(np));
Toast.makeText(getApplicationContext(), getString(R.string.sendkeystrokes_sent_text, toSend, deviceId.getName()), Toast.LENGTH_SHORT).show();
}
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class PresenterPlugin method sendNext.
public void sendNext() {
NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
np.set("specialKey", SpecialKeysMap.get(KeyEvent.KEYCODE_PAGE_DOWN));
device.sendPacket(np);
}
Aggregations