Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim NativeMe As JavaObject
Dim PE As PhoneEvents
Dim smsParts, smsPartsACK As Int
End Sub
Sub Service_Create
Try
' // phone events
PE.Initialize("PE")
Catch
log($"svc_sms::Service_Create:: - error - ${LastException.Message}"$)
End Try
End Sub
Sub Service_Start (StartingIntent As Intent)
Try
NativeMe.InitializeContext
Catch
log($"svc_sms::Service_Start:: - error - ${LastException.Message}"$)
End Try
End Sub
Sub SendLargeSMS(Destination As String, Message As String)
Dim Extra As Map, id As String, ph As Phone
id = DateTime.now
Extra.Initialize
Extra.Put("message_id", id )
Dim tM As String = DateTime.Now
Extra.Put("message_time", tM)
Try
smsPartsACK = 0
If ph.SdkVersion >= 31 Then
smsParts = NativeMe.RunMethod("Send4", Array(Destination, Message, Extra, True, False))
Else
smsParts = NativeMe.RunMethod("Send3", Array(Destination, Message, Extra, True, False))
End If
If smsParts = 0 Then
smsParts = 1
End If
Catch
log($"SendLargeSMS_ERROR ${LastException.Message}"$)
End Try
End Sub
#If JAVA
import java.util.Random;
import java.util.ArrayList;
import java.util.Map;
import android.content.Context;
import android.content.Intent;
import android.app.PendingIntent;
import android.telephony.SmsManager;
public static int Send3(String PhoneNumber, String Text, Map<String, String> Extra, boolean ReceiveSentNotification, boolean ReceiveDeliveredNotification) {
SmsManager sm = SmsManager.getDefault();
/* Generate a unique requestCode for each Intent */
Random randomNo = new Random();
int requestCode = (int)(System.currentTimeMillis()/1000) + randomNo.nextInt(1000);
int numParts = 0;
Intent mSendIntent = new Intent("b4a.smssent");
mSendIntent.putExtra("phone", PhoneNumber);
// Add additional Extra Data
for (Map.Entry<String, String> entry : Extra.entrySet()) {
mSendIntent.putExtra(entry.getKey(), entry.getValue());
}
PendingIntent sentIntent = ReceiveSentNotification ? PendingIntent.getBroadcast(BA.applicationContext, requestCode, mSendIntent, PendingIntent.FLAG_UPDATE_CURRENT) : null;
Intent mDeliveryIntent = new Intent("b4a.smsdelivered");
mDeliveryIntent.putExtra("phone", PhoneNumber);
// Add additional Extra Data
for (Map.Entry<String, String> entry : Extra.entrySet()) {
mDeliveryIntent.putExtra(entry.getKey(), entry.getValue());
}
PendingIntent deliveryIntent = ReceiveDeliveredNotification ? PendingIntent.getBroadcast(BA.applicationContext, requestCode, mDeliveryIntent, PendingIntent.FLAG_UPDATE_CURRENT) : null;
ArrayList<String> parts = sm.divideMessage(Text);
numParts = parts.size();
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();
for (int i = 0; i < numParts; i++) {
if (ReceiveSentNotification) {
sentIntents.add(PendingIntent.getBroadcast(BA.applicationContext, requestCode, mSendIntent, PendingIntent.FLAG_UPDATE_CURRENT));
}
if (ReceiveDeliveredNotification) {
deliveryIntents.add(PendingIntent.getBroadcast(BA.applicationContext, requestCode, mDeliveryIntent, PendingIntent.FLAG_UPDATE_CURRENT));
}
}
sm.sendMultipartTextMessage(PhoneNumber, null, parts, ReceiveSentNotification ? sentIntents : null, ReceiveDeliveredNotification ? deliveryIntents : null);
return numParts;
}
public static int Send4(String PhoneNumber, String Text, Map<String, String> Extra, boolean ReceiveSentNotification, boolean ReceiveDeliveredNotification) {
SmsManager sm = SmsManager.getDefault();
/* Generate a unique requestCode for each Intent */
Random randomNo = new Random();
int requestCode = (int)(System.currentTimeMillis()/1000) + randomNo.nextInt(1000);
int numParts = 0;
Intent mSendIntent = new Intent("b4a.smssent");
mSendIntent.putExtra("phone", PhoneNumber);
// Add additional Extra Data
for (Map.Entry<String, String> entry : Extra.entrySet()) {
mSendIntent.putExtra(entry.getKey(), entry.getValue());
}
PendingIntent sentIntent = ReceiveSentNotification ? PendingIntent.getBroadcast(BA.applicationContext, requestCode, mSendIntent, PendingIntent.FLAG_MUTABLE) : null;
Intent mDeliveryIntent = new Intent("b4a.smsdelivered");
mDeliveryIntent.putExtra("phone", PhoneNumber);
// Add additional Extra Data
for (Map.Entry<String, String> entry : Extra.entrySet()) {
mDeliveryIntent.putExtra(entry.getKey(), entry.getValue());
}
PendingIntent deliveryIntent = ReceiveDeliveredNotification ? PendingIntent.getBroadcast(BA.applicationContext, requestCode, mDeliveryIntent, PendingIntent.FLAG_MUTABLE) : null;
ArrayList<String> parts = sm.divideMessage(Text);
numParts = parts.size();
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();
for (int i = 0; i < numParts; i++) {
if (ReceiveSentNotification) {
sentIntents.add(PendingIntent.getBroadcast(BA.applicationContext, requestCode, mSendIntent, PendingIntent.FLAG_MUTABLE));
}
if (ReceiveDeliveredNotification) {
deliveryIntents.add(PendingIntent.getBroadcast(BA.applicationContext, requestCode, mDeliveryIntent, PendingIntent.FLAG_MUTABLE));
}
}
sm.sendMultipartTextMessage(PhoneNumber, null, parts, ReceiveSentNotification ? sentIntents : null, ReceiveDeliveredNotification ? deliveryIntents : null);
return numParts;
}
#End If