Android Question Select SIM card slot to send SMS

Plutoam

Member
B4X:
AddPermission(android.permission.READ_PHONE_STATE)


Add this code to the manifest and request access from the user like this:

B4X:
Dim rn As RuntimePermissions
rn.CheckAndRequest(rn.PERMISSION_READ_PHONE_STATE)
 
Upvote 0
B4X:
AddPermission(android.permission.READ_PHONE_STATE)


Add this code to the manifest and request access from the user like this:

B4X:
Dim rn As RuntimePermissions
rn.CheckAndRequest(rn.PERMISSION_READ_PHONE_STATE)
Thanks for reply. But I knew this.
After a little research, I was able to solve it.

B4X:
Sub Process_Globals
   Private NativeSMS As JavaObject
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   NativeSMS.InitializeContext 'in class NativeSMS=Me '
   NativeSMS.RunMethod("SendSMS",Array("0999999999",0,"check",True,True))'phone number,sim slot,text,sent Notification,deliver Notification'
End Sub

B4X:
#If JAVA
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ShortName;
  public static void SendSMS(String PhoneNumber,int sim, String Text, boolean ReceiveSentNotification, boolean ReceiveDeliveredNotification)
  {
    SmsManager sm = SmsManager.getSmsManagerForSubscriptionId(sim);
    Intent i1 = new Intent("b4a.smssent");
    i1.putExtra("phone", PhoneNumber);
    PendingIntent pi = ReceiveSentNotification ? PendingIntent.getBroadcast(BA.applicationContext, 0, i1, 134217728) : null;
    Intent i2 = new Intent("b4a.smsdelivered");
    i2.putExtra("phone", PhoneNumber);
    PendingIntent pi2 = ReceiveDeliveredNotification ? PendingIntent.getBroadcast(BA.applicationContext, 0, i2, 134217728) : null;
    sm.sendTextMessage(PhoneNumber, null, Text, pi, pi2);
  }
#End If
 
Upvote 0
Top