B4A Library Phone library update - v1.34

Status
Not open for further replies.
Edit: V1.34 is available.
This version adds two new events: ConnectivityChanged and TextToSpeechFinish. This version also adds a new object named SmsInterceptor that handles new incoming Sms messages.

A simple example that prints the events to the LogCat:
Main activity
B4X:
Sub Process_Globals
    Dim TTS As TTS
End Sub
Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    StartService(S1)
    TTS.Initialize("tts")
End Sub
Sub TTS_Ready (Success As Boolean)
    If Success Then TTS.Speak("hello world", False)
End Sub
S1 service
B4X:
'Service module
Sub Process_Globals
    Dim PE As PhoneEvents
    Dim SI As SMSInterceptor
End Sub
Sub Service_Create
    PE.Initialize("PE")
    SI.Initialize("SI")
End Sub

Sub Service_Start

End Sub
Sub SI_MessageReceived (From As String, Body As String)
    Log("MessageReceived: From = " & From & ", Body = " & Body)
End Sub
Sub PE_TextToSpeechFinish (Intent As Intent)
    Log("TextToSpeechFinish")
End Sub
Sub PE_ConnectivityChanged (NetworkType As String, State As String, Intent As Intent)
    Log("ConnectivityChanged: " & NetworkType & ", state = " & State)
    Log(Intent.ExtrasToString)
End Sub
Sub PE_AirplaneModeChanged (State As Boolean, Intent As Intent)
    Log("AirplaneModeChanged: "& state)
    Log(Intent.ExtrasToString)
End Sub
Sub PE_BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent)
    Log("BatteryChanged: Level = " & level & ", Scale = " & scale & ", Plugged = " & Plugged)
End Sub
Sub PE_CameraButtonPressed (Intent As Intent)
    Log("CameraButtonPressed")
    Log(Intent.ExtrasToString)
End Sub
Sub PE_PackageRemoved (Package As String, Intent As Intent)
    Log("PackageRemoved: " & Package)
    Log(Intent.ExtrasToString)
End Sub
Sub PE_PackageAdded (Package As String, Intent As Intent)
    Log("PackageAdded: " & Package)
    Log(intent.ExtrasToString)
End Sub
Sub PE_ScreenOff (Intent As Intent)
    Log("ScreenOff")
End Sub
Sub PE_ScreenOn (Intent As Intent)
    Log("ScreenOn")
End Sub
Sub PE_Shutdown (Intent As Intent)
    Log("Shutdown")
End Sub
Sub PE_UserPresent (Intent As Intent)
    Log("UserPresent")
End Sub
Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    Log("PhoneStateChanged, State = " & State & ", IncomingNumber = " & IncomingNumber)
    Log(Intent.ExtrasToString)
End Sub
Sub Service_Destroy
    
End Sub
Installation instructions: Unzip the attached file and copy both files to the internal libraries folder. The default is: C:\Program Files\Anywhere Software\Basic4android\Libraries
 

Attachments

  • Phone.zip
    50.5 KB · Views: 2,026

TomK

Member
Licensed User
Longtime User
Hi Erel thanks for getting back to me so quickly,

You're right I should have been more specific. I currently have 3 Android devices, a Motorola Droid 2, a Motorola XOOM, and a Samsung Galaxy Tab.

I have not tried yet on the 2 tabs (although I only have gmail contacts on them both to begin with), but on the Droid 2 I have created contacts on the phone itself as well as having gmail contacts. If I create (from a web browser) a contact in gmail it automatically syncs itself with my phone and becomes available as a contact there.

Any of the contacts I have created on my mobile however, are the ones that do not get listed while using the .GetAll.... also I have not tried using native java code to extract the results so it may well be that it wouldn't do it anyway.

I'm wondering if anyone else also has noticed this behavior?

Thanks again and regards,


Tom
 

FrankR

Member
Licensed User
Longtime User
Tom - if you would, please create a thread for the Xoom after you have some experience with it.

None of us can have high expectations for compatibility since we're talking about 3.0 Android, but it would still be helpful to hear your experiences.
 

TomK

Member
Licensed User
Longtime User
Sure thing Frank,

I plan on working quite a bit with it this weekend, so after poking around inside and getting my ducks in a row with it, I'll post some of my findings as well as perhaps trying out some rudimentary coding on it and see where that takes me :)

Take care for now Frank


Regards,


Tom
 

tsteward

Well-Known Member
Licensed User
Longtime User
I have run the example in the first post.
Making, receiving calls does not raise any event. I am wanting to know when a call has ended if possible.
I am running this on my Galaxy S2 Android 4.1.2, B4A 2.52

Also when receiving an SMS I get the following error "Error receiving broadcast Intent"

PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (s2) Create **
** Service (s2) Start **
ConnectivityChanged: WIFI, state = CONNECTED
Bundle[{networkInfo=NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true, inetCondition=0}]
BatteryChanged: Level = 68, Scale = 100, Plugged = false
TextToSpeechFinish
BatteryChanged: Level = 68, Scale = 100, Plugged = false
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (s2) Create **
** Service (s2) Start **
ConnectivityChanged: WIFI, state = CONNECTED
Bundle[{networkInfo=NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true, inetCondition=0}]
BatteryChanged: Level = 67, Scale = 100, Plugged = false
TextToSpeechFinish
** Activity (main) Pause, UserClosed = false **
ScreenOff
ScreenOn
BatteryChanged: Level = 67, Scale = 100, Plugged = false
ScreenOff
ScreenOn
MessageReceived: From = +61425346394, Body = Boo
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x30 (has extras) } in anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$2@41973468
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:766)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$2.onReceive(PhoneEvents.java:398)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:756)
... 9 more
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (s2) Create **
** Service (s2) Start **
ConnectivityChanged: WIFI, state = CONNECTED
Bundle[{networkInfo=NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true, inetCondition=0}]
BatteryChanged: Level = 67, Scale = 100, Plugged = false
TextToSpeechFinish
ScreenOff
ScreenOn
UserPresent
BatteryChanged: Level = 67, Scale = 100, Plugged = false
ScreenOff
BatteryChanged: Level = 67, Scale = 100, Plugged = false
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

tsteward

Well-Known Member
Licensed User
Longtime User
Making, receiving calls does not raise any event. I am wanting to know when a call has ended if possible.
Still need help determining when A phone call has ended as I want to ask the user to record a note for that phone call.
 

Vincent HURET

Member
Licensed User
Longtime User
Hello
Is there a way with the phonesms library to automatically download and then store an image received by MMS ? Today, you need to press and download, I would like to avoid doing that and that could be automatic. Thanks for your help.
 

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Erel,

Is correct this version? 1.34?

The last one was 2.25, look:

Phone225.png


and this update going to 1.34?
 

corwin42

Expert
Licensed User
Longtime User
Erel,

Is correct this version? 1.34?

The last one was 2.25, look:

Phone225.png


and this update going to 1.34?

Phone library is part of the B4A distribution, so new versions of this library will normally ship with a new B4A version. This thread is from february 2011 so it is totally outdated. Use the library which is shipped with B4A.
 
Status
Not open for further replies.
Top