Android Question Dealing with intents and broadcast receiver ?

hookshy

Well-Known Member
Licensed User
Longtime User
I have multiple intents settings over my app like :
1.detecting headset wire plugged in
2.detecting bluettooth headset
3.a process that intercept sms with sms interceptor
this service starts every 9 minutes due to location manager issue
StartServiceAt("", DateTime.Now +DateTime.TicksPerMinute*9 ,True)
4.I have set up intent for starting app when headset button is pressed

My problems:
hsmes_MessageReceived sub is starting every 9 minutes and it is related to the service nr 3

Questions :
Did I use correct Broadcast.SetPriority(2147483647) ??????
Did I use the correct sms interceptor in a service togeder with a location manager function ?
An incoming sms is marked automatically as read ?
When do the sms interceptor fire MessageReceived ?


I guess I need more that a strong advice .

B4X:
#Region Module 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.
  
      Dim Broadcast As BroadCastReceiver

End Sub

Sub Service_Create

      Broadcast.Initialize("BroadcastReceiver")

End Sub

Sub Service_Start(StartingIntent As Intent)

      Broadcast.SetPriority(2147483647)
    Broadcast.registerReceiver("android.intent.action.HEADSET_PLUG")

End Sub

Sub Service_Destroy

End Sub

Sub BroadcastReceiver_OnReceive(Action As String, Extras As Object)

    Dim i As Intent = Extras
                Dim HeadsetState() As String
              
                HeadsetState = Array As String("Unplugged", "Plugged")
              
                Log(i.ExtrasToString)

      'ToastMessageShow("State: " & HeadsetState(i.GetExtra("state")), False)

Select HeadsetState(i.GetExtra("state"))

  Case "Plugged"
  Main.headset=True
  CallSubDelayed(Main,"show_headset") 'seteaza mod casti ...bluetooth


  Case "Unplugged"
  Main.headset=False
  CallSubDelayed(Main,"hide_headset") 'setteaza mod casti ...

End Select


End Sub

my manifest editor
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.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" 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$")
'End of default text.

SetActivityAttribute(main, android:windowSoftInputMode, adjustResize|stateHidden)'tastatura

AddApplicationText(
<activity android:name="com.tapit.adview.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
)

AddReceiverText(s2, <intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED"/>
<action android:name="android.bluetooth.device.action.ACTION_ACL_DISCONNECTED"/>
</intent-filter>)
AddPermission(android.permission.BLUETOOTH)


AddActivityText(main,  <intent-filter android:priority="1000">
      
      <action android:name="android.intent.action.VOICE_COMMAND" />
      <category android:name="android.intent.category.DEFAULT" />
    
    </intent-filter>
)
AddActivityText(Main, <meta-data android:name="android.app.default_searchable"
                  android:value=".result" />)

AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)
AddPermission(android.permission.BLUETOOTH_ADMIN)
AddPermission(android.permission.BROADCAST_STICKY)


AddPermission(android.permission.CALL_PHONE)
AddPermission(android.permission.CHANGE_NETWORK_STATE)
AddPermission(android.permission.SEND_SMS)
AddPermission(android.permission.RECEIVE_SMS)
AddPermission(com.android.alarm.permission.SET_ALARM)
AddPermission(android.permission.CHANGE_WIFI_STATE)
AddPermission(android.permission.WRITE_SMS)
 

hookshy

Well-Known Member
Licensed User
Longtime User
I have checked my logs on the below sub and indeed the message I receive is old
I use : registru=sms2.GetByType(sms2.TYPE_INBOX) to read sms inbox and it seems it does not sincronize
Someplace I am doing a mistake ..Or I am totally gone


B4X:
Sub hsmes_MessageReceived (From As String, Body As String) As Boolean

Log("from:"&From)
Log("body:"&Body)


end sub
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
Maybe I will come out with my problems ...
I have received an sms from another contact ..and suddenly all inbox and the current sms are showing in my inbox scrolview
and described log on post nr2 fired all the missing sms

All these happens on two occurrences ...sms from other contact and inhibited broadcast receiver that detect the headset .
now things are back to normal ..hope to catch the issue
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…