Sub Process_Globals
Dim rv As RemoteViews
End Sub
Sub Service_Create
rv = ConfigureHomeWidget("widget", "rv", 0, "Nome App",True)
End Sub
Sub Service_Start (StartingIntent As Intent)
If rv.HandleWidgetEvents(StartingIntent) Then Return
End Sub
Sub rv_RequestUpdate
rv.UpdateWidget
End Sub
Sub rv_Disabled
StopService("")
End Sub
Sub Service_Destroy
End Sub
Sub BtnDisattiva_Click
ToastMessageShow("Disattivato",False)
End Sub
Sub BtnAttiva_Click
ToastMessageShow("Attivato",False)
End Sub
Allora vediamo se ho capito:
1 crei widget usando modulo di tipo service
B4X:Sub Process_Globals Dim rv As RemoteViews End Sub Sub Service_Create rv = ConfigureHomeWidget("widget", "rv", 0, "Nome App",True) End Sub Sub Service_Start (StartingIntent As Intent) If rv.HandleWidgetEvents(StartingIntent) Then Return End Sub Sub rv_RequestUpdate rv.UpdateWidget End Sub Sub rv_Disabled StopService("") End Sub Sub Service_Destroy End Sub Sub BtnDisattiva_Click ToastMessageShow("Disattivato",False) End Sub Sub BtnAttiva_Click ToastMessageShow("Attivato",False) End Sub
2 Ti crei il layou del widget contenente i due pulsanti:
che risponde agli eventi ed il gioco è fatto.
Qui c'è il tutorial per il widget:
http://www.b4x.com/forum/basic4android-getting-started-tutorials/10166-android-home-screen-widgets-tutorial-part-i.html
Spero ti possa essere di aiuto
Scoperta del giorno
nel service non sono accettati ( quanto ho scoperto per il mio caso )
- return
- mesgbo
- dialobox
- ToastMessageShow
Tutti questi comandi mandano in bomba app, cosa brutta da vedere, quindi ho creato un modo per dialogare con main attraverso dei parametri, esempio se per chiamare non ho il numero memorizzato, apro main e richiamo una determinata funzione, tutto attraverso dei parametri scritti nel sistema.
Esempio che poi formulerò per il libro del nostro amico.
Ivano scusa se ti contraddico, io uso senza problemi ToastMessageShow e sono pronto a scommettere che posso usare anche tutti gli altri. Nel codice che ti ho postato, del service ci sono due button , uno che attiva un service ed un altro che lo disattiva, come vedi contengono dei ToastMessageShow e funzionano.
Posta il codice del service...:sign0098:
Sub Process_Globals
Dim rv As RemoteViews
End Sub
Sub Service_Create
rv = ConfigureHomeWidget("Main_widget", "rv", 0, "MIMM SOS", True)
If Setting.GPS1 = Null Then
Setting.GPS1.Initialize("GPS")
Setting.tl.Initialize
Setting.gpsActive
End If
End Sub
Sub Service_Start (StartingIntent As Intent)
If rv.HandleWidgetEvents(StartingIntent) Then Return
End Sub
Sub Service_Destroy
End Sub
Sub rv_RequestUpdate
rv.UpdateWidget
End Sub
Sub rv_Disabled
StopService("")
End Sub
Sub ImageView1_Click
StartActivity(Main)
ToastMessageShow("Attivato",False)
End Sub
Sub Panel1_Click
StartActivity(Main)
ToastMessageShow("Attivato",False)
End Sub
Sub ImageView5_Click ' 118
If Setting.xchiave4 = "empty" OR Setting.xchiave4 = Null OR Setting.xchiave4 = "" Then
Setting.FileSettingApp.SetString("chiave0","4")
StartActivity(Main)
Else
Dim p As PhoneCalls
StartActivity(p.Call(Setting.xchiave4))
ToastMessageShow("Chiamata di soccorso attiva",False)
End If
End Sub
Sub ImageView4_Click ' Sms
If Setting.xchiave3 = "empty" OR Setting.xchiave3 = Null OR Setting.xchiave3 = "" Then
Setting.FileSettingApp.SetString("chiave0","3")
StartActivity(Main)
Else
If Setting.GPS1 = Null Then
Setting.GPS1.Initialize("GPS")
Setting.tl.Initialize
Setting.gpsActive
End If
Dim Sms As PhoneSms
Dim numerphone As Phone
If Setting.lat = 0 AND Setting.lon = 0 Then
Sms.Send(Setting.xchiave3, "Richiesta di aiuto! chiamami ")
Else
Dim s As String
s = Setting.lat & "," & Setting.lon
s = Setting.mappaLink(s)
Sms.Send(Setting.xchiave3, "Richiesta di aiuto! sono qui " & s)
End If
ToastMessageShow("SMS Inviato",False)
End If
End Sub
Sub ImageView3_Click ' chiama
If Setting.xchiave2 = "empty" OR Setting.xchiave2 = Null OR Setting.xchiave2 = "" Then
Setting.FileSettingApp.SetString("chiave0","2")
StartActivity(Main)
Else
Dim p As PhoneCalls
StartActivity(p.Call(Setting.xchiave2))
ToastMessageShow("Chiamata attiva",False)
End If
End Sub
Sub ImageView2_Click ' navigatore
If Setting.xchiave1 = "empty" OR Setting.xchiave1 = Null OR Setting.xchiave1 = "" Then
Setting.FileSettingApp.SetString("chiave0","1")
StartActivity(Main)
Else
Dim s As String
s = Setting.xchiave1
Setting.mappa(s)
ToastMessageShow("Navigazione attiva",False)
End If
End Sub
Sub ImageView6_Click
Setting.FileSettingApp.SetString("chiave0","5")
StartActivity(Main)
End Sub
Che significa? che passi dei parametri alla funzione?dei parametri scritti nel sistema.
ma librerie a se no mio vedere
Che significa? che passi dei parametri alla funzione?
per favore non scrivere troppo di fretta
Sub Process_Globals
Dim FileSettingApp As PreferenceManager
End Sub
Sub startup
FileSettingApp.SetString("chiave0","0")
End Sub
If Setting.FileSettingApp.GetString("chiave0") = "1" Then
Setting.FileSettingApp.SetString("chiave0","0")
m_setting_Click
End If
If Setting.xchiave1 = "empty" OR Setting.xchiave1 = Null OR Setting.xchiave1 = "" Then
Setting.FileSettingApp.SetString("chiave0","1")
StartActivity(Main)
End if
Dim In As Intent
In.Initialize(In.ACTION_MAIN, "")
In.SetComponent("phoneblockedlight.luigi.it/.info")
StartActivity(In)
Ivano,confermo che non puoi inserire una message box in un widget.
Però ho trovato questo pezzo di codice, che ti permette di chiamare un activity specificando il package.
B4X:Dim In As Intent In.Initialize(In.ACTION_MAIN, "") In.SetComponent("phoneblockedlight.luigi.it/.info") StartActivity(In)
Ti commento questa istruzione:
In.SetComponent("phoneblockedlight.luigi.it/.info"), il primo parametro è il nome del package che vuoi utilizzare, il secondo è il nome dell'activity.
COme puoi usare questa porzione di codice ?
Nella tua app ti crei due activity, dove in una inserisci una message box con il messaggio "Funzione attivata", nell'altra sempre una message box con la scritta "Funzione Non attivata".
Ovvio che nel parametro devi mettere il nome dele package della tua applicazione.
Spero ti torni utile.
If GPS1.GPSEnabled = False Then
ToastMessageShow("GPS disabilitato.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
Else
GPS1.Start(0, 0)
End If
rv.SetImage("image5",LoadBitmap(File.DirAssets,"enable.png")
rv.SetImage("image5",LoadBitmap(File.DirAssets,"disable.png")
If GPS1.GPSEnabled = False Then
ToastMessageShow("GPS disabilitato.", True)
rv.SetImage("image5",LoadBitmap(File.DirAssets,"enable.png")
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
Else
rv.SetImage("image5",LoadBitmap(File.DirAssets,"disable.png")
End If
Sub Process_Globals
Dim rv As RemoteViews
End Sub
Sub Service_Create
rv = ConfigureHomeWidget("Main_widget", "rv", 0, "MIMM SOS", True)
If Setting.GPS1 = Null Then
Setting.GPS1.Initialize("GPS")
Setting.tl.Initialize
Setting.gpsActive
End If
End Sub
Sub Service_Start (StartingIntent As Intent)
If rv.HandleWidgetEvents(StartingIntent) Then Return
End Sub
Sub Service_Destroy
End Sub
Sub rv_RequestUpdate
rv.UpdateWidget
End Sub
Sub rv_Disabled
StopService("")
End Sub
Sub ImageView1_Click
StartActivity(Main)
ToastMessageShow("Attivato",False)
End Sub
Sub Panel1_Click
StartActivity(Main)
ToastMessageShow("Attivato",False)
End Sub
Sub ImageView6_Click
Setting.FileSettingApp.SetString("chiave0","5")
StartActivity(Main)
End Sub
Sub ImageView5_Click ' 118
If Setting.xchiave4 = "empty" OR Setting.xchiave4 = Null OR Setting.xchiave4 = "" Then
Setting.FileSettingApp.SetString("chiave0","4")
StartActivity(Main)
Else
Dim p As PhoneCalls
StartActivity(p.Call(Setting.xchiave4))
ToastMessageShow("Chiamata di soccorso attiva",False)
End If
End Sub
Sub ImageView4_Click ' Sms
If Setting.xchiave3 = "empty" OR Setting.xchiave3 = Null OR Setting.xchiave3 = "" Then
Setting.FileSettingApp.SetString("chiave0","3")
StartActivity(Main)
Else
If Setting.GPS1 = Null Then
Setting.GPS1.Initialize("GPS")
Setting.tl.Initialize
Setting.gpsActive
End If
Dim Sms As PhoneSms
Dim numerphone As Phone
If Setting.lat = 0 AND Setting.lon = 0 Then
Sms.Send(Setting.xchiave3, "Richiesta di aiuto! chiamami ")
Else
Dim s As String
s = Setting.lat & "," & Setting.lon
s = Setting.mappaLink(s)
Sms.Send(Setting.xchiave3, "Richiesta di aiuto! sono qui " & s)
End If
ToastMessageShow("SMS Inviato",False)
End If
End Sub
Sub ImageView3_Click ' chiama
If Setting.xchiave2 = "empty" OR Setting.xchiave2 = Null OR Setting.xchiave2 = "" Then
Setting.FileSettingApp.SetString("chiave0","2")
StartActivity(Main)
Else
Dim p As PhoneCalls
StartActivity(p.Call(Setting.xchiave2))
ToastMessageShow("Chiamata attiva",False)
End If
End Sub
Sub ImageView2_Click ' navigatore
If Setting.xchiave1 = "empty" OR Setting.xchiave1 = Null OR Setting.xchiave1 = "" Then
Setting.FileSettingApp.SetString("chiave0","1")
StartActivity(Main)
Else
Dim s As String
s = Setting.xchiave1
Setting.mappa(s)
ToastMessageShow("Navigazione attiva",False)
End If
End Sub
Sub gpsActive
If GPS1 = Null Then
GPS1.Initialize("GPS")
tl.Initialize
End If
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.", True)
StartActivity(GPS1.LocationSettingsIntent)
Else
If lat > 0 AND lon > 0 Then
GPS1.Start(lat,lon)
End If
End If
End Sub
Sub GPS_LocationChanged (Location1 As Location)
lat = Location1.Latitude
lon = Location1.Longitude
alt = Location1.Altitude
End Sub
Allora, vedo del codice ridondante.In troppi punti verifiche se il gps è attivo.
1)Quando ti interessa sapere se il gps è attivo ?
2)DOve ti va in errore ?
3)Posta il log dell'errore
Ciao
Sub Process_Globals
Dim rv As RemoteViews
Dim GPS1 As GPS
Dim tl As Toggle
Dim lat,lon,alt As Double
lat = 0
lon = 0
alt = 0
End Sub
Sub Service_Create
rv = ConfigureHomeWidget("Main_widget", "rv", 0, "MIMM SOS", True)
End Sub
Sub Service_Start (StartingIntent As Intent)
If rv.HandleWidgetEvents(StartingIntent) Then
Return
End If
End Sub
#Region Service
Sub Service_Destroy
End Sub
Sub rv_RequestUpdate
rv.UpdateWidget
End Sub
Sub rv_Disabled
StopService("")
End Sub
#End Region
#Region GPS
Sub gpsActive(Tim As Long, Dis As Float)
If GPS1.GPSEnabled = False Then <<<<<<<<<<<<< qui va in bomba cazzarola >>>>>>>
ToastMessageShow("GPS disabilitato.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
End If
If GPS1 = Null Then
GPS1.Initialize("GPS")
tl.Initialize
End If
GPS1.Start(Tim,Dis)
End Sub
Sub GPS_LocationChanged (Location1 As Location)
lat = Location1.Latitude
lon = Location1.Longitude
alt = Location1.Altitude
Dim Sms As PhoneSms
Dim numerphone As Phone
Dim s As String
s = lat & "," & lon
s = Setting.mappaLink(s)
Sms.Send(Setting.xchiave3, "Richiesta di aiuto! sono qui " & s)
ToastMessageShow("SMS inviato correttamente...", True)
GPS1.Stop
End Sub
Sub GPS_UserEnabled (Enabled As Boolean)
ToastMessageShow("GPS device enabled = " & Enabled, True)
End Sub
Sub GPS_GpsStatus (Satellites As List)
' lblSatellites.Text = "Satellites:" & CRLF
' For i = 0 To Satellites.Size - 1
' Dim Satellite As GPSSatellite
' Satellite = Satellites.Get(i)
' lblSatellites.Text = lblSatellites.Text & CRLF & Satellite.Prn & _
' " " & Satellite.Snr & " " & Satellite.UsedInFix & " " & Satellite.Azimuth _
' & " " & Satellite.Elevation
' Next
End Sub
#End Region
#Region event click
Sub ImageView1_Click
StartActivity(Main)
End Sub
Sub Panel1_Click
StartActivity(Main)
End Sub
Sub ImageView6_Click ' ICE
Setting.FileSettingApp.SetString("chiave0","5")
StartActivity(Main)
End Sub
Sub ImageView5_Click ' 118
If Setting.xchiave4 = "empty" OR Setting.xchiave4 = Null OR Setting.xchiave4 = "" Then
ToastMessageShow("key not valid", False)
Setting.FileSettingApp.SetString("chiave0","4")
StartActivity(Main)
Return
End If
Dim p As PhoneCalls
StartActivity(p.Call(Setting.xchiave4))
End Sub
Sub ImageView4_Click ' Sms
If Setting.xchiave3 = "empty" OR Setting.xchiave3 = Null OR Setting.xchiave3 = "" Then
ToastMessageShow("key not valid", False)
Setting.FileSettingApp.SetString("chiave0","3")
StartActivity(Main)
Return
End If
gpsActive(0, 0)
ToastMessageShow("SMS in fase di localizzazione", True)
End Sub
Sub ImageView3_Click ' chiama
If Setting.xchiave2 = "empty" OR Setting.xchiave2 = Null OR Setting.xchiave2 = "" Then
ToastMessageShow("key not valid", False)
Setting.FileSettingApp.SetString("chiave0","2")
StartActivity(Main)
Return
End If
Dim p As PhoneCalls
StartActivity(p.Call(Setting.xchiave2))
End Sub
Sub ImageView2_Click ' navigatore
If Setting.xchiave1 = "empty" OR Setting.xchiave1 = Null OR Setting.xchiave1 = "" Then
ToastMessageShow("key not valid", False)
Setting.FileSettingApp.SetString("chiave0","1")
StartActivity(Main)
Return
End If
Dim s As String
s = Setting.xchiave1
Setting.mappa(s)
End Sub
#End Region
If GPS1.GPSEnabled = False Then <<<<<<<<<<<<< qui va in bomba cazzarola >>>>>>>
ToastMessageShow("GPS disabilitato.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
End If
Sub gpsActive(Tim As Long, Dis As Float)
If GPS1.GPSEnabled = False Then
ToastMessageShow("GPS disabilitato.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
End If
If GPS1 = Null Then
GPS1.Initialize("GPS")
tl.Initialize
End If
GPS1.Start(Tim,Dis)
End Sub
If GPS1.GPSEnabled = False Then
ToastMessageShow("GPS disabilitato.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
End If
GPS1.Start(Tim,Dis)
le bombe avvengono qui Codice completo
B4X:Sub gpsActive(Tim As Long, Dis As Float) If GPS1.GPSEnabled = False Then ToastMessageShow("GPS disabilitato.", True) StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen. End If If GPS1 = Null Then GPS1.Initialize("GPS") tl.Initialize End If GPS1.Start(Tim,Dis) End Sub
Primo errore
B4X:If GPS1.GPSEnabled = False Then ToastMessageShow("GPS disabilitato.", True) StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen. End If
secondo errore
B4X:GPS1.Start(Tim,Dis)
Errore
- Tim=0 ( long )
- Dis=0.0 ( float )
- LastException java.lang.NullPointerException
Cazzarola dove sbaglio :BangHead:
Sub gpsActive(Tim As Long, Dis As Float)
If GPS1 = Null Then
GPS1.Initialize("GPS")
tl.Initialize
else
If GPS1.GPSEnabled = False Then
ToastMessageShow("GPS disabilitato.", True)
StartActivity(GPS1.LocationSettingsIntent)
GPS1.Start(Tim,Dis)
End If
end sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?