Press on the image to return to the main documentation page.
Phone
The Phone library changed and several methods belonging to the Phone object have moved to PhoneId and PhoneVibrate. The reason for this change is to avoid adding unnecessary permissions. The Phone library contains all kinds of features related to the Android phone. Phone object includes information about the device and also other general features. PhoneAccelerometer and PhoneOrientation objects are now replaced with PhoneSensors which support other sensors as well. PhoneEvents allows you to handle all kinds of system events. PhoneId gives access to the the specific phone values. PhoneSms supports sending Sms messages. PhoneVibrate vibrates the phone. SmsMessages together with Sms support fetching messages from the phone database. SmsInterceptor intercepts incoming Sms messages. PhoneIntents and PhoneCalls include several useful intents. Email helps with building an Intent that sends an email. PhoneWakeState allows you to force the screen and power to keep on. Contact and Contacts give access to the stored contacts. CallLog and CallItem give access to the phone calls log. ContentChooser allows the user to choose content from other applications. For example the user can choose an image from the Gallery application. VoiceRecognition converts speech to text. LogCat tracks the internal phone logs. PackageManager allows you to retrieve information about the installed applications.
Represents a single contact. The Contacts object should be used to get lists of Contact objects. EMAIL_x constants are the possible email types. PHONE_x constants are the possible phone types.
Contacts object allows you to access the device stored contacts. The following code finds all contacts named John (actually it will find all contacts which their name contains the string "john"), and print their fields to the LogCat. It will also fetch the contact photo if it exists. Example: DimContacts1AsContacts DimlistOfContactsAsList listOfContacts = Contacts1.FindByName("John", False)
Fori = 0TolistOfContacts.Size - 1 DimContactAsContact Contact = listOfContacts.Get(i)
Log(Contact) 'will print the fields to the LogCat DimphotoAsBitmap photo = Contact.GetPhoto Ifphoto <> NullThenActivity.SetBackgroundImage(photo)
DimemailsAsMap emails = Contact.GetEmails Ifemails.Size > 0ThenLog("Email addresses: " & emails)
DimphonesAsMap phones = Contact.GetPhones Ifphones.Size > 0ThenLog("Phone numbers: " & phones)
Next
Contacts2 object allows you to access the device stored contacts. This type is based on a new API supported by Android 2.0 and above. This type supersedes Contacts type. The following code finds all contacts named John (actually it will find all contacts which their name contains the string "john"), and print their fields to the LogCat. It will also fetch the contact photo if it exists. Example: DimContacts2AsContacts2 DimlistOfContactsAsList listOfContacts = Contacts2.FindByName("John", False, True, True)
Fori = 0TolistOfContacts.Size - 1 DimContactAsContact Contact = listOfContacts.Get(i)
Log(Contact) 'will print the fields to the LogCat DimphotoAsBitmap photo = Contact.GetPhoto Ifphoto <> NullThenActivity.SetBackgroundImage(photo)
DimemailsAsMap emails = Contact.GetEmails Ifemails.Size > 0ThenLog("Email addresses: " & emails)
DimphonesAsMap phones = Contact.GetPhones Ifphones.Size > 0ThenLog("Phone numbers: " & phones)
Next
The ContentChooser object allows the user to select a specific type of content using other installed applications. For example the user can use the internal Gallery application to select an image. If the user has installed a file manager then the ContentChooser can be used to select general files. This object should usually be declared as a process global object. After initializing the object you can let the user select content by calling Show with the required MIME types. The Result event will be raised with a Success flag and with the content Dir and FileName. Note that these values may point to resources other than regular files. Still you can pass them to methods that expect Dir and FileName. Only content types that can be opened with an InputStream are supported.
Events:
Result (Success As Boolean, Dir As String, FileName As String)
Using an Email object you can create an intent that holds a complete email message. You can then launch the email application by calling StartActivity. Note that the email will not be sent automatically. The user will need to press on the send button. Example: DimMessageAsEmail Message.To.Add("SomeEmail@example.com")
Message.Attachments.Add(File.Combine(File.DirRootExternal, "SomeFile.txt"))
StartActivity(Message.GetIntent)
LogCat allows you to read the internal phone logs. Refer to the LogCat documentation for more information about the optional arguments. The LogCatData event is raised when there is new data available. You should use BytesToString to convert the raw bytes to string. Note that the LogCatData event is raised in a different thread. This means that you can only log the messages. You can also use the Threading library to delegate the data to the main thread.
The PackageManager allows you to find information about installed applications. Applications are referenced using their package name. You can get a list of all the packages by calling GetInstalledPackages.
Returns an internal drawable object. See this page for a list of available resources. Example: DimpAsPhone DimbdAsBitmapDrawable bd = p.GetResourceDrawable(17301618)
Activity.AddMenuItem2("Menu1", "Menu1", bd.Bitmap)
This object gives access to the internal accelerometers sensors. See the Orientation and accelerometers example. This object should be declared as a process global object.
Events:
AccelerometerChanged (X As Float, Y As Float, Z As Float)
This object creates an intent that launches the phone application. The reason that it is not part of the PhoneIntents library is that it requires an additional permission.
The Android OS sends all kinds of messages to notify applications of changes in the system. The PhoneEvents object allows you to catch such messages and handle those events in your program. Usually you will want to add this object to a Service module instead of an Activity module in order not to miss events that happen while your activity is paused. Working with this object is quite simple. You should declare this object in Sub Process_Globals and initialize it in Sub Service_Create. From now on your declared sub events will handle the events. The Intent object which was sent by the system is passed as the last parameter. The events supported are: AirplaneModeChanged - Raised when the "airplane mode" state changes. State - True when airplane mode is active. BatteryChanged - Raised when the battery status changes. Level - The current level. Scale - The maximum level. Plugged - Whether the device is plugged to an electricity source. ConnectivityChanged - There was a change in the state of the WIFI network or the MOBILE network (other network). NetworkType - WIFI or MOBILE. State - One of the following values: CONNECTING, CONNECTED, SUSPENDED, DISCONNECTING, DISCONNECTED, UNKNOWN. DeviceStorageLow - The device internal memory condition is low. DeviceStorageOk - The device internal low memory condition no longer exists. PackageAdded - An application was installed. Package - The application package name. PackageRemoved - An application was uninstalled. Package - The application package name. PhoneStateChanged - The phone state has changed. State - One of the three values: IDLE, OFFHOOK, RINGING. OFFHOOK means that there is a call or that the phone is dialing. IncomingCall - Available when the State value is RINGING. ScreenOff - The screen has turned off. ScreenOn - The screen has turned on. Shutdown - The phone is shutting down (turned off not just sleeping). SmsDelivered - An Sms message sent by your application was delivered to the recipient. PhoneNumber - The target phone number. SmsSentStatus - Raised after your application sends an Sms message. Success - Whether the message was sent successfully. ErrorMessage - One of the following values: GENERIC_FAILURE, NO_SERVICE, RADIO_OFF, NULL_PDU or OK. PhoneNumber - The target phone number. TextToSpeechFinish - The Text To Speech engine has finished processing the messages in the queue. UserPresent - The user has unlocked the keyguard screen.
Events:
AirplaneModeChanged (State As Boolean, Intent As Intent) BatteryChanged (Level As Int, Scale As Int, Plugged As Boolean, Intent As Intent) ConnectivityChanged (NetworkType As String, State As String, Intent As Intent) DeviceStorageLow (Intent As Intent) DeviceStorageOk (Intent As Intent) PackageAdded (Package As String, Intent As Intent) PackageRemoved (Package As String, Intent As Intent) PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent) ScreenOff (Intent As Intent) ScreenOn (Intent As Intent) SmsDelivered (PhoneNumber As String, Intent As Intent) SmsSentStatus (Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent) Shutdown (Intent As Intent) TextToSpeechFinish (Intent As Intent) UserPresent (Intent As Intent)
This object contains methods that create intents objects. An intent does nothing until you call StartActivity with the intent. Calling StartActivity sends the intent to the OS.
This object gives access to the internal orientation sensors. See the Orientation and accelerometers example. This object should be declared as a process global object.
Events:
OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)
The PhoneSensors object allows you to listen for changes in one of the device sensors. See the Sensors example. Most devices do not support all sensors. The StartListening method returns False if the sensor is not supported. After initializing the object and calling StartListening, the SensorChanged event will be raised each time the sensor value changes. The value is passed as an array of Floats. Some sensors pass a single value and some pass three values.
The PhoneWakeState object allows you to prevent the device from turning off the screen. Once you call KeepAlive the phone screen will stay on till you call ReleaseKeepAlive. It is important to eventually release it. A recommended usage is to call KeepAlive in Activity_Resume and call ReleaseKeepAlive in Activity_Pause. Note that the user can still turn off the screen by pressing on the power button. Calling PartialLock will prevent the CPU from going to sleep even if the user presses on the power button. It will not however affect the screen.
The RingtoneManager object allows you to set or get the default ringtone. It also provides access to the default ringtone picker. The RingtoneResult event will be raised when the picker is closed with the Uri of the selected ringtone. Note that an empty string will be returned if the "Silence" option was selected. Example of playing the selected ringtone with MediaPlayer: SubProcess_Globals PrivatermAsRingtoneManager EndSub
Listens for incoming SMS messages. The MessageReceived event is raised when a new message arrives. Returning True from the MessageReceived event will cause the broadcasted message to be aborted. This can be used to prevent the message from reaching the standard SMS application. However in order for your application to receive the message before other applications you should use Initialize2 and set the priority value to a value larger than 0. It should be 999 according to the Android documentation.
Permissions:
android.permission.RECEIVE_SMS
Events:
MessageReceived (From As String, Body As String) As Boolean MessageSent (MessageId As Int)
Provides access to the stored SMS messages. Note that you can use PhoneSms to send SMS messages. Example of printing all messages from the last week: DimSmsMessages1AsSmsMessages DimList1AsList List1 = SmsMessages1.GetAllSince(DateTime.Add(DateTime.Now, 0, 0, -7))
Fori = 0ToList1.Size - 1 DimSmsAsSms Sms = List1.Get(i)
Log(Sms)
Next
Most Android devices support voice recognition (speech to text). Usually the service works by sending the audio stream to some external server which analyzes the stream and returns the possible results. Working with this object is quite simple. You should declare a VoiceRecognition object as a process global object and initialize it in Activity_Create when FirstTime is True. Later when you call Listen a dialog will be displayed, asking the user to speak. The Result event will be raised with a Success flag and a list with the possible results (usually one result).