Android Question SMS revice status problem with Phone lib

Tayfur

Well-Known Member
Licensed User
Longtime User
HEllo;
I want sent sms with my list.
I can send sms. But, I cant good recive smsstatus and smsdelivery notifications.

This my code
B4X:
Sub Button_gonder_Click
        ' SEND SMS BUTTON
sms_gonder(1)
End Sub


Sub sms_gonder(sira_no As Int) ' SMS SENDING PROCESS
Dim xsms As PhoneSms
  
    Dim  PE As PhoneEvents
    Dim PhoneId As PhoneId
    'Dim PE As
  
    PE.InitializeWithPhoneState("PE",PhoneId)
    Log("-1--------SMS gönder kodu-----------")

    Log("Gönderim Saat: "& DateTime.Time(DateTime.Now))
  
    If sira_no=1 Then
        Log("SMS no:"&"054??????")
        xsms.Send("054??????".Text,EditText_msj.Text)
     End If
    If sira_no=2 Then
        Log("SMS no:"&"053??????")
        xsms.Send("053???????",EditText_msj.Text)
        End If
    'sonuc.Initialize("PE")
     Log("--------------------")
End Sub

Sub PE_SmsDelivered (PhoneNumber As String, Intent As Intent)
Log("-2------------ SMS delivery---------")  
Log("SMS Delivery Saat: "& DateTime.Time(DateTime.Now))
Log("PhoneNumber :"&PhoneNumber)
Log("--------------------------")  
End Sub

Sub PE_SmsSentStatus (Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
Log ( "-3---------SMS sent Status------------")
Log("SMS sent Status Saat: "& DateTime.Time(DateTime.Now))
Log("Success :" & Success)
Log("ErrorMessage : "&ErrorMessage)
Log("PhoneNumber :"&PhoneNumber)
Log("--------------------------")  
sira=sira+1
If sira<3 Then sms_gonder(sira)
End Sub


Sub Button_Temizle_Click ' CLEAN
    EditText_msj.Text=""
    EditText_tel.Text=""
End Sub

this my app logs:


Installing file.
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
-1--------SMS gönder kodu-----------
Gönderim Saat: 15:19:14
SMS no:054??????
--------------------
-3---------SMS sent Status------------
SMS sent Status Saat: 15:19:31
Success :true
ErrorMessage : OK
PhoneNumber :054??????
--------------------------
-1--------SMS gönder kodu-----------
Gönderim Saat: 15:19:31
SMS no:053?????
--------------------
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
-2------------ SMS delivery---------
SMS Delivery Saat: 15:19:47
PhoneNumber :053?????
--------------------------
-2------------ SMS delivery---------
SMS Delivery Saat: 15:19:49
PhoneNumber :053?????
--------------------------
-2------------ SMS delivery---------
SMS Delivery Saat: 15:19:50
PhoneNumber :053?????
--------------------------
-2------------ SMS delivery---------
SMS Delivery Saat: 15:19:52
PhoneNumber :053?????
--------------------------
** Activity (main) Pause, UserClosed = true **

normally, I am waiting;
1pcs SMS sent Status, 1pcs SMS delivery for tel 053????????.
and
1pcs SMS sent Status, 1pcs SMS delivery for tel 054????????.

so I cant recive it.
You can look my logs.
i recive ... :
0pcs SMS sent Status, 4pcs SMS delivery for tel 053????????.
and
1pcs SMS sent Status, 0pcs SMS delivery for tel 054????????.


how fix it??
 

Tayfur

Well-Known Member
Licensed User
Longtime User
Make PE a process global variable and initialize it in Activity_Create (when FirstTime is true).



B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A phone SMS
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim xsms As PhoneSms
    'Telefon msj sıfırlama #330*0000# ara yapa resetle telfonu
    Dim  PE As PhoneEvents
    Dim PhoneId As PhoneId
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
     Public NativeMe As JavaObject
    Private Button_gonder As Button
    Private Button_Temizle As Button
    Private Button_uydur As Button
    Private EditText_tel As EditText
    Private EditText_msj As EditText
    Dim sira As Int=1
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("L")
    If FirstTime Then
        PE.InitializeWithPhoneState("PE",PhoneId)
    End If

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub Button_gonder_Click
        ' SEND SMS BUTTON
sms_gonder(1)
End Sub

Sub SendSMS(Message As Map)
   Dim Extra As Map

   ' Extra Data
   Extra.Initialize
   Extra.Put("message_id", "msj_id_"&Message.Get("to"))
    NativeMe=Me
   NativeMe.RunMethod("Send3", Array(Message.Get("to"), Message.Get("message"), Extra, True, True))
End Sub

Sub SendSms2(PhoneNumber As String, Text As String)
    Dim ps As PhoneSms
    Dim r As Reflector
    r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getDefault", Null, Null)
    r.RunMethod4("sendTextMessage", Array As Object(PhoneNumber, Null, Text, Null, Null), _
        Array As String("java.lang.String", "java.lang.String", "java.lang.String", _
            "android.app.PendingIntent", "android.app.PendingIntent"))
End Sub


Sub sms_gonder(sira_no As Int) ' SMS SENDING PROCESS

    'Dim PE As
  
    PE.InitializeWithPhoneState("PE",PhoneId)
    Log("-1--------SMS gönder kodu-----------")

    Log("Gönderim Saat: "& DateTime.Time(DateTime.Now))
  
    If sira_no=1 Then
        Log("SMS no:"&EditText_tel.Text)
        xsms.Send("0533*****","**"&EditText_msj.Text)
      
     End If
    If sira_no=2 Then
      
        xsms.Send("0536*****",EditText_msj.Text)
        End If
    If sira_no=3 Then
        xsms.Send("0533*****","*asd*"&EditText_msj.Text)

     End If
     If sira_no=4 Then
        xsms.Send("0536*****",EditText_msj.Text)
        End If
     Log("--------------------")
End Sub

Sub PE_SmsDelivered (PhoneNumber As String, Intent As Intent)
Log("-2------------ SMS delivered---------")  
Log("SMS Delivery Saat: "& DateTime.Time(DateTime.Now))
Log("PhoneNumber :"&PhoneNumber)
Log("-"&Intent.Action)
Log("-"&Intent.GetData)
Log("-"&Intent.ExtrasToString)
Log("-"&Intent.Flags)
Log("phone:"&Intent.GetExtra("phone"))
Log("msj.id:"&Intent.GetExtra("message_id"))
Log("--------------------------")  
End Sub

Sub PE_SmsSentStatus (Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
Log ( "-3---------SMS sent Status------------")
Log("SMS sent Status Saat: "& DateTime.Time(DateTime.Now))
Log("Success :" & Success)
Log("ErrorMessage : "&ErrorMessage)
Log("PhoneNumber :"&PhoneNumber)
Log("-"&Intent.Action)
Log("-"&Intent.ACTION_SEND)
Log("-"&Intent.GetData)
Log("phone:"&Intent.GetExtra("phone"))
Log("msj.id:"&Intent.GetExtra("message_id"))

Log("--------------------------")  
sira=sira+1
If sira<10 Then sms_gonder(sira)
End Sub


Sub Button_Temizle_Click ' CLEAN
    EditText_msj.Text=""
    EditText_tel.Text=""
    Dim x As Int=0
    Do Until x>10
            Log(x)
            x=x+1
            DoEvents
          Loop
      
  
End Sub
Sub Button_uydur_Click
    EditText_msj.Text="Saat: "& DateTime.Time(DateTime.Now) & " kamil bu deneme mesajı:"
    EditText_tel.Text="Saat: "& DateTime.Time(DateTime.Now) & " slema bu deneme mesayı:"
End Sub


Result logs.

B4X:
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
-1--------SMS gönder kodu-----------
Gönderim Saat: 13:47:54
SMS no:0533*****
--------------------
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
-3---------SMS sent Status------------
SMS sent Status Saat: 13:47:55
Success :true
ErrorMessage : OK
PhoneNumber :0533*****
-b4a.smssent
-android.intent.action.SEND
-null
phone:0533*****
msj.id:null
--------------------------
-1--------SMS gönder kodu-----------
Gönderim Saat: 13:47:56
SMS no:0536*****
--------------------
-3---------SMS sent Status------------
SMS sent Status Saat: 13:47:56
Success :true
ErrorMessage : OK
PhoneNumber :0536*****
-b4a.smssent
-android.intent.action.SEND
-null
phone:0536*****
msj.id:null
--------------------------
-1--------SMS gönder kodu-----------
Gönderim Saat: 13:47:56
SMS no:0533*****
--------------------
-3---------SMS sent Status------------
SMS sent Status Saat: 13:47:57
Success :true
ErrorMessage : OK
PhoneNumber :0533*****
-b4a.smssent
-android.intent.action.SEND
-null
phone:0533*****
msj.id:null
--------------------------
-1--------SMS gönder kodu-----------
Gönderim Saat: 13:47:57
SMS no:0536*****
--------------------
-3---------SMS sent Status------------
SMS sent Status Saat: 13:47:58
Success :true
ErrorMessage : OK
PhoneNumber :0536*****
-b4a.smssent
-android.intent.action.SEND
-null
phone:0536*****
msj.id:null
--------------------------
-1--------SMS gönder kodu-----------
Gönderim Saat: 13:47:58
--------------------
-2------------ SMS delivered---------
SMS Delivery Saat: 13:48:06
PhoneNumber :0536*****
-b4a.smsdelivered
-null
-Bundle[{pdu=[B@41a1fc00, phone=0536*****, format=3gpp}]
-16
phone:0536*****
msj.id:null
--------------------------
-2------------ SMS delivered---------
SMS Delivery Saat: 13:48:06
PhoneNumber :0536*****
-b4a.smsdelivered
-null
-Bundle[{pdu=[B@41a216a8, phone=0536*****, format=3gpp}]
-16
phone:0536*****
msj.id:null
--------------------------
-2------------ SMS delivered---------
SMS Delivery Saat: 13:48:07
PhoneNumber :0536*****
-b4a.smsdelivered
-null
-Bundle[{pdu=[B@41a22d48, phone=0536*****, format=3gpp}]
-16
phone:0536*****
msj.id:null
--------------------------
-2------------ SMS delivered---------
SMS Delivery Saat: 13:48:07
PhoneNumber :0536*****
-b4a.smsdelivered
-null
-Bundle[{pdu=[B@41a24368, phone=0536*****, format=3gpp}]
-16
phone:0536*****
msj.id:null
--------------------------
** Activity (main) Pause, UserClosed = false **
 
Upvote 0
Top