Italian Widget e main.Sub

ivanomonti

Expert
Licensed User
Longtime User
Ciao a tutti, spero di scrivere bene la richiesta, ho bisogno di avviare una sup pubblica da widget a main.


esempio activity main

public sub msg
bla bla
end sub

service widget

button_click
main.msg <<<<< non viene vista la sub
end sub

Non riesco a fare partire il codice in Main dal widget cazzarola, esiste un modo o non e possibile.
 

arenaluigi

Well-Known Member
Licensed User
Longtime User
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
 

ivanomonti

Expert
Licensed User
Longtime User
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

Per il modulo non e un problema, e lanciare delle sub che stanno in main (activity) che non riesco, quindi sto facendo del codice nei modulo e poi lo richiamo dal WidGet
 

ivanomonti

Expert
Licensed User
Longtime User
Scoperta del giorno

nel service non sono accettati ( quanto ho scoperto per il mio caso )

  1. return
  2. mesgbo
  3. dialobox
  4. 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.
 
Last edited:

arenaluigi

Well-Known Member
Licensed User
Longtime User
Scoperta del giorno

nel service non sono accettati ( quanto ho scoperto per il mio caso )

  1. return
  2. mesgbo
  3. dialobox
  4. 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:
 

ivanomonti

Expert
Licensed User
Longtime User
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:

In effetti il ToastMessageShow("Attivato",False) lo accetta, ma librerie a se no, ad esempio Dialogs(version 2.80) come anche msgbox("message","alert") non sembra funzionare.

Farò un attento controllo.

B4X:
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
 
Last edited:

ivanomonti

Expert
Licensed User
Longtime User
Che significa? che passi dei parametri alla funzione?

:eek:
per favore non scrivere troppo di fretta


OK cerco di scrivere meglio.

Modulo Setting

B4X:
Sub Process_Globals
   Dim FileSettingApp As PreferenceManager
End Sub

B4X:
Sub startup
        FileSettingApp.SetString("chiave0","0")
End Sub

Activity Main (start activity)

B4X:
If Setting.FileSettingApp.GetString("chiave0") = "1" Then
   Setting.FileSettingApp.SetString("chiave0","0")
   m_setting_Click
End If

WidGet service (chiamata al navigatore)

B4X:
If Setting.xchiave1 = "empty" OR Setting.xchiave1 = Null OR Setting.xchiave1 =  "" Then
   Setting.FileSettingApp.SetString("chiave0","1")
   StartActivity(Main)
End if

In questo modo, controllo la scelta, se tale scelta non ha nulla impostato cioè vuota, setto il parametro diverso da zero e apro activity, che a sua volta controlla il parametro e lancia la sub assegnata.

MIMM Sos e scritta con una sola activity con 3 pannelli che vengono attivati (Visible true/false) a secondo della sezione interessata.

Spero di aver scritto decentemente.
 

arenaluigi

Well-Known Member
Licensed User
Longtime User
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.
 

ivanomonti

Expert
Licensed User
Longtime User
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.

Mio unico problema e verificare se il gps e attivo, se non e attivo lo devo attivare... o meglio segnalare mettendo il bottone in enabled = false, cosa che non ho ancora trovato soluzione.

Ad esempio richiamare un object tipo ImageView per poterlo mettere in stato false o true di enabled.

  1. me.ImageView5.Enable = false <<<< non valido
  2. self.ImageView5.Enable = false <<<< non valido
  3. this.ImageView5.Enable = false <<<< non valido
  4. ImageView5.Enable = false <<<< non valido
  5. Service.ImageView5.Enable = false <<<< non valido

Nulla, insomma come se questi ImageView non esistessero nel widget.
 

arenaluigi

Well-Known Member
Licensed User
Longtime User
Per sapere se il gps è acceso:
B4X:
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
per quanto riguarda l'image:
cosa intendi con "Non valido" ?
Hai creato nel layout del widget l'image ?
Fai così:

Nel service widget, ha un oggetto di tipo "Remote View", devi richiamare gli oggetti che hai nel tuo layout del widget in questo modo:

B4X:
rv.SetImage("image5",LoadBitmap(File.DirAssets,"enable.png")
rv.SetImage("image5",LoadBitmap(File.DirAssets,"disable.png")
Qui l'empio completo:
B4X:
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
Fammi sapere :sign0098:
 

ivanomonti

Expert
Licensed User
Longtime User
Quello che non capisco e dove integrare il codice, quello che ti mi hai scritto lo sto già testando sia a modo mio che a tuo, ma si blocca Android per darmi "mimm sos si e bloccata" e va in chiusura forzata. ti posto il codice del widget.

B4X:
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

in setting

B4X:
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
 

ivanomonti

Expert
Licensed User
Longtime User
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

nessun errore consegnato, si imbomba e basta... ora riguardo il codice.
 

ivanomonti

Expert
Licensed User
Longtime User
Help :)

Ho bisogno di aiuto e di valutazioni, mi sto perdendo come al solito.

2 scenari (widget ) + ( main )

Scenario 1 ( WidGet )

Il widget serve per non perdere visione dell'app ed avere in modo veloce alcune funzioni. Quindi l'ho usato per questo scopo ma ho il problema del gps... cosa voglio raggiungere;

  1. Attivare il gps (se possibile in modo veloce senza fare spunta, in quanto questo servizio serve a persone disabili e deve essere immediato)
  2. Aspettare la connessione
  3. inviare SMS con cordinate GPS tipo: "Ho bisogno di aiuto, sono qui " + ""https://maps.google.it/maps?q=" & luogo & "&hl=it&t=h&z=16"
  4. Chiudere GPS.

La cosa e banale, ma come al solito la trasformo in un immenso lavorone inutile con ridondanze pazzesche.

Pensavo di fare due codici separati, uno per WidGet e Uno Per Main (scenario 2) visto che questo era il secondo punto chi ha voglia di darmi una mano, devo mettere questa aggiornamento entro domani e non so se riesco.

Cordialmente Ivano Monti.

Ecco le prime modifiche (WidGet service)

B4X:
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

Ora compilo e testo e vediamo, se qualcuno + bravo di me mi verifica il codice ne sarei grato.
 
Last edited:

arenaluigi

Well-Known Member
Licensed User
Longtime User
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

Be, GPS1 devi inizializzarlo prima.;)
 

ivanomonti

Expert
Licensed User
Longtime User
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

  1. Tim=0 ( long )
  2. Dis=0.0 ( float )
  3. LastException java.lang.NullPointerException

Cazzarola dove sbaglio :BangHead:
 

arenaluigi

Well-Known Member
Licensed User
Longtime User
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

  1. Tim=0 ( long )
  2. Dis=0.0 ( float )
  3. LastException java.lang.NullPointerException

Cazzarola dove sbaglio :BangHead:

Riscrivo così:
B4X:
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
 
Top