Background:
This is used for our GSM Module which monitors industrial conditions (alarms etc.). A SMS will be sent to the user when an event is raised. The notification on the phone must be raised, be audible and vibrate irrespective of the settings on the phone.
This code works perfectly until I enable "Blocking Mode" on my Samsung Note 2 phone. The phone blocks any audible or vibration raised by a notification. see: http://eguides.sprint.com/support/e...sung_galaxy_note_ii_eguide/blocking_mode.html
I could change the Blocking Mode settings to allow the mobile number to be exempt from the Blocking Mode rules, but I have to consider other phones that may have similar features. Therefore, I have to find a way to override these settings.
I have been searching for a few days now to find what setting "Blocking Mode" switches on or off and don't even know where or how to change it.
Just a nudge in the right direction will be appreciated!
I have also attached the following code in the file below.
Main:
s1:
In order to test it, I was sending an SMS back to myself. The number ending with xxx in s1 would need to reflect the user's phone number.
By the way, this is brilliant the way that Erel has written the basis for all this (Intent Filters). Even if I Force Close my application, it starts up again as soon as I have an incoming SMS. Pure Genius!
This is used for our GSM Module which monitors industrial conditions (alarms etc.). A SMS will be sent to the user when an event is raised. The notification on the phone must be raised, be audible and vibrate irrespective of the settings on the phone.
This code works perfectly until I enable "Blocking Mode" on my Samsung Note 2 phone. The phone blocks any audible or vibration raised by a notification. see: http://eguides.sprint.com/support/e...sung_galaxy_note_ii_eguide/blocking_mode.html
I could change the Blocking Mode settings to allow the mobile number to be exempt from the Blocking Mode rules, but I have to consider other phones that may have similar features. Therefore, I have to find a way to override these settings.
I have been searching for a few days now to find what setting "Blocking Mode" switches on or off and don't even know where or how to change it.
Just a nudge in the right direction will be appreciated!
I have also attached the following code in the file below.
Main:
B4X:
#Region Project Attributes
#ApplicationLabel: IMF SMS Interceptor
#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
Dim textAddress As String
Dim textBody As String
End Sub
Sub Globals
Dim lblAddress As Label
Dim lblBody As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
End Sub
Sub Activity_Resume
lblAddress.Text = textAddress
lblBody.Text = textBody
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
s1:
B4X:
#Region Service Attributes
#StartAtBoot: False
#End Region
'Service module
Sub Process_Globals
Type Message (Address As String, Body As String)
Dim currentAddress As String
Dim currentBody As String
Dim p As Phone
Dim OriginalRingerMode As Int
Dim OriginalVOLUME_NOTIFICATION As Int
End Sub
Sub Service_Create
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))
If messages(i).Address = "+447507878xxx" Then
currentAddress = messages(i).Address
currentBody = messages(i).Body
raiseAlarm
End If
Next
End If
End Sub
Sub raiseAlarm
' Dim pv As PhoneVibrate
' pv.Vibrate(500) 'This runs irrespective of RingerMode etc
SetRingerMode
SetVOLUME_NOTIFICATIONtoMaximum
RaiseNotification
ReinstateVOLUME_NOTIFICATION
ReinstateRingerMode
End Sub
Sub SetRingerMode
' Dim RingerMode As Int
' Dim Target As Object
' Dim r As Reflector
'
' r.Target = "android.media.AudioManager"
' Log("r.Target: " & r.Target)
' RingerMode = r.RunMethod("getRingerMode")
' 'RingerMode = r.RunStaticMethod("android.media.AudioManager","getRingerMode",Null,Null)
' Log("RingerMode in CheckNotificationSetting: " & RingerMode)
'--------------------------------------------------------------------------------------------
'RINGER_MODE_SILENT = 0
'RINGER_MODE_VIBRATE = 1
'RINGER_MODE_NORMAL = 2 Audible & Vibrate
Log("Ringer Mode: " & p.GetRingerMode)
OriginalRingerMode = p.GetRingerMode 'Global variable to reinstate original settings
If p.GetRingerMode <> 2 Then
p.SetRingerMode(p.RINGER_NORMAL)
End If
End Sub
Sub SetVOLUME_NOTIFICATIONtoMaximum
Log("Volume Notification: " & p.GetVolume(p.VOLUME_NOTIFICATION))
OriginalVOLUME_NOTIFICATION = p.GetVolume(p.VOLUME_NOTIFICATION) 'Get the volume before setting max volume
Dim maxVolume As Int
maxVolume = p.GetMaxVolume(p.VOLUME_NOTIFICATION)
p.SetVolume(p.VOLUME_NOTIFICATION,maxVolume,False) 'Set Max Volume
Log("Notification MaxVolume: " & maxVolume)
End Sub
Sub RaiseNotification
Dim n As Notification
n.Initialize
n.Light = True
n.Insistent = True
n.Sound = True
n.Icon = "icon"
n.SetInfo("IMF GSM 1301 Message", ("From " & currentAddress),Main)
n.Notify(1)
Main.textAddress = currentAddress
Main.textBody = currentBody
End Sub
Sub ReinstateVOLUME_NOTIFICATION
Log("Temporary Volume Notification: " & p.GetVolume(p.VOLUME_NOTIFICATION))
p.SetVolume(p.VOLUME_NOTIFICATION,OriginalVOLUME_NOTIFICATION,False) 'Return the volume to its original volume
Log("Reinstated Volume Notification: " & p.GetVolume(p.VOLUME_NOTIFICATION))
End Sub
Sub ReinstateRingerMode
Log("Temporary Ringer Mode: " & p.GetRingerMode)
p.SetRingerMode(OriginalRingerMode)
Log("Reinstated Ringer Mode: " & p.GetRingerMode)
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
In order to test it, I was sending an SMS back to myself. The number ending with xxx in s1 would need to reflect the user's phone number.
By the way, this is brilliant the way that Erel has written the basis for all this (Intent Filters). Even if I Force Close my application, it starts up again as soon as I have an incoming SMS. Pure Genius!
Attachments
Last edited: