Android Question how to check Automatic date & time on the Changes ?

Cnrez

Member
Licensed User
Longtime User
hi,
is there a way to check whether the Date & Time Setting change from Automatic to manual.
i want to force the user to set "Automatic date and time" and "Automatic time zone" to ON.

thank you.
 

Attachments

  • Screenshot_2016-05-01-06-23-05.png
    Screenshot_2016-05-01-06-23-05.png
    85.7 KB · Views: 368

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Methds that ends with Old are for API 16 and below :
For my device both methods DateTimeAutoOld and DateTimeAuto seem to work

B4X:
    Dim java As JavaObject
    java.InitializeContext
   
    'You can use DateTimeAuto for android API 17 and above
    Dim result As Int =java.RunMethod("DateTimeAutoOld",Null)
    Select result
      
    Case 1
        Log("Automatic")
    Case 0
        Log("Manual")
    End Select

   
Dim result As Int =java.RunMethod("DateTimeAuto",Null)
    Select result
      
    Case 1
        Log("Automatic")
    Case 0
        Log("Manual")
    End Select

Dim result As Int =java.RunMethod("TimeZoneAutoOld",Null)
    Select result
      
    Case 1
        Log("Automatic")
    Case 0
        Log("Manual")
    End Select

Dim result As Int =java.RunMethod("TimeZoneAuto",Null)
    Select result
      
    Case 1
        Log("Automatic")
    Case 0
        Log("Manual")
    End Select
B4X:
#If java
import android.provider.Settings.Global;
import android.provider.Settings.System;
import android.provider.Settings.SettingNotFoundException;
    public int DateTimeAuto(){
        return android.provider.Settings.Global.getInt(getContentResolver(), android.provider.Settings.Global.AUTO_TIME, 0);
    }
  
    //For api 16 and below
    public int DateTimeAutoOld(){
        return android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.AUTO_TIME, 0);
    }  
  
    public int TimeZoneAuto() {
        return android.provider.Settings.Global.getInt(getContentResolver(), android.provider.Settings.Global.AUTO_TIME_ZONE, 0);
  
    }
  
    // For API 16 and below
  
    public int TimeZoneAutoOld() {
        return android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.AUTO_TIME_ZONE, 0);
  
    }  

#end if

Got Auto Date and Time code from here :http://stackoverflow.com/a/23076554
 
Upvote 0

zak

Member
Licensed User
Longtime User
On my android phone (samsung Note4) android version 6.0.1, my app is crashing at startup when I add DateTimeAuto or DateTimeAutoOld..weird
 
Upvote 0
Top