victordiaz / PHONK

PHONK is a coding playground for new and old Android devices
https://phonk.app
GNU General Public License v3.0
457 stars 27 forks source link

No example for sms send/receive #113

Open t-oster opened 2 years ago

t-oster commented 2 years ago

Hi, Nice app. Unfortunately I cannot find any information regarding the SMS API. I want to build a simple SMS to MQTT gateway (bidirectional), which should be very easy with Phonk. Can you point me to the docs or the sources with the SMS functionality?

polhomarkho commented 2 years ago

Hi!

The SMS functions are defined here phonk_apprunner/src/main/java/io/phonk/runner/apprunner/api/PDevice.java: device.onSmsReceived() and device.smsSend(). Here is a small example that sends and receives a SMS. The phone number is asked when running:

/*  
 *  Description Send and receive a SMS
 *  by Paul-Emile Sublet <polhomarkho@gmail.com>
 */

ui.addTitle(app.name);

var phoneNumber;

const receivedSmsDetails = ui.addText(0, 0, 1, 0.5);
ui.popup()
  .title('Enter the phone number to send an SMS to')
  .ok('ok')
  .input('phone number')
  .onAction(function(phoneNumberInput) {
    phoneNumber = phoneNumberInput.answer;
  })
  .show();

// these methods are defined in phonk_apprunner/src/main/java/io/phonk/runner/apprunner/api/PDevice.java
device.onSmsReceived(function(sms) {
  receivedSmsDetails.text('from: ' + sms.from + "\n" + 'message: ' + sms.message);
});

ui.addButton('send sms', 0, 0.5, 1, 0.5)
  .onClick(function() {
    device.smsSend(phoneNumber, 'hello world!');
  });
polhomarkho commented 2 years ago

Here is the PR adding this example: https://github.com/victordiaz/PHONK/pull/119