Android Question incoming sms stored to file, outgoing no, why?

maachal

New Member
Licensed User
incoming sms stored to file, outgoing no, why? :-( use phone library? or something else?
i thank the local guru for kick ...
sorry for my bad english...

manifest:

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.basic4ppc.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
'End of default text.
AddPermission(android.permission.RECEIVE_SMS)
AddPermission(android.permission.SEND_SMS)
AddReceiverText(menu,
<intent-filter>
    <action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>)
AddReceiverText(menu,
<intent-filter>
    <action android:name="android.provider.Telephony.SMS_SENT" />
</intent-filter>)
service:

B4X:
#Region  Service Attributes
    #StartAtBoot: True
#End Region

'Service module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   Type Message (Address As String, Body As String)
   'Dim settings As Map
    'settings.initialize
    'Dim i As Int
End Sub

Sub Service_Start(startingIntent As Intent)
   If startingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
      Dim messages() As Message
      messages = ParseSmsIntent(startingIntent)
      For i = 0 To messages.Length - 1
        Log(messages(i))
        Dim d As String
        d = DateTime.GetYear(DateTime.Now) & "-" & DateTime.GetMonth(DateTime.Now) & "-" & DateTime.GetDayOfMonth(DateTime.Now) & "-" & DateTime.GetHour(DateTime.Now) & "-" & DateTime.GetMinute(DateTime.Now) & "-" & DateTime.GetSecond(DateTime.Now)
        Dim out As OutputStream = File.OpenOutput(File.DirInternal, "in.txt", True)
        Dim s As String = d & CRLF & messages(i) & CRLF & "------------------"
        Dim t() As Byte = s.GetBytes("UTF8")
        out.WriteBytes(t, 0, t.Length)
        out.Close
      Next
   End If
   If startingIntent.Action = "android.provider.Telephony.SMS_SENT" Then
      Dim messages() As Message
      messages = ParseSmsIntent(startingIntent)
      For i = 0 To messages.Length - 1
        Log(messages(i))
        Dim d As String
        d = DateTime.GetYear(DateTime.Now) & "-" & DateTime.GetMonth(DateTime.Now) & "-" & DateTime.GetDayOfMonth(DateTime.Now) & "-" & DateTime.GetHour(DateTime.Now) & "-" & DateTime.GetMinute(DateTime.Now) & "-" & DateTime.GetSecond(DateTime.Now)
        Dim out As OutputStream = File.OpenOutput(File.DirInternal, "out.txt", True)
        Dim s As String = d & CRLF & messages(i) & CRLF & "------------------"
        Dim t() As Byte = s.GetBytes("UTF8")
        out.WriteBytes(t, 0, t.Length)
        out.Close
      Next
   End If
End Sub

Sub Service_Destroy

End Sub

Sub Service_Create

End Sub

'Parses an SMS intent and returns an array of messages
Sub ParseSmsIntent (In As Intent) As Message()
   Dim messages() As Message
   If In.HasExtra("pdus") = False Then Return messages
   Dim pdus() As Object
   Dim r As Reflector
   pdus = In.GetExtra("pdus")
   If pdus.Length > 0 Then
      Dim messages(pdus.Length) As Message
      For i = 0 To pdus.Length - 1
         r.Target = r.RunStaticMethod("android.telephony.SmsMessage", "createFromPdu", _
            Array As Object(pdus(i)), Array As String("[B"))
         messages(i).Body = r.RunMethod("getMessageBody")
         messages(i).Address = r.RunMethod("getOriginatingAddress")
      Next
   End If
   Return messages
End Sub
 
Top