Android Question how to check programmaticallay wheater app is running in develope mode or not?

luqmanhaidar

Member
Licensed User
Longtime User
please help friend, how to check programmaticallay wheater app is running in debug mode or not?l
how i check if ther user has developer option enabled in device?
thanks in advance
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
please help friend, how to check programmaticallay wheater app is running in debug mode or not?l
how i check if ther user has developer option enabled in device?
tanks in advance
@luqmanhaidar.... You appear to have asked two questions there. Erel has answered the one about #DEBUG but the second question is not a code related answer. You MUST have developer mode enabled to use many of the facilities provided by B4A. If Developer mode is enabled it will appear as an option in Settings > Developer options. If Developer mode is not enabled it will not appear.

More info: Enable Developer Mode
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You MUST have developer mode enabled to use many of the facilities provided by B4A
It is not 100% correct.

A device do NOT need to have Developer Settings enabled at all when the app is installed over PlayStore.
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
I did not say that. I did not mention the app store releases at all.

Facilities provided by B4A, for example debugging and access to logs over USB require selections to be made in developer mode.
 
Upvote 0

luqmanhaidar

Member
Licensed User
Longtime User
Why does it matter?


B4X:
Sub IsDebug As Boolean
#If DEBUG
   Return True
#Else
   Return False
#End If
End Sub

so I want to know whether android is in developer mode off or on,

I want the application not run if android in the developoer mode on because i want to block mock mode GPS
 
Upvote 0

luqmanhaidar

Member
Licensed User
Longtime User
I have a need to check the condition of Android in developer off mode
It is not 100% correct.

A device do NOT need to have Developer Settings enabled at all when the app is installed over PlayStore.


I have a need to check the condition of Android in developer off mode , not for upload over playstore, need to desable mock mode gps not run


I want to anticipate the GPS Mock or location used in my GPS program, because the GPS Mock runs in developer mode on
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I have a need to check the condition of Android in developer off mode
Add a bit of InlineJava

B4X:
#If Java
public boolean isDevMode() {
  if(Integer.valueOf(android.os.Build.VERSION.SDK) == 16) {
    return android.provider.Settings.Secure.getInt(getApplicationContext().getContentResolver(), android.provider.Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED , 0) != 0;
  } else if (Integer.valueOf(android.os.Build.VERSION.SDK) >= 17) {
    return android.provider.Settings.Secure.getInt(getApplicationContext().getContentResolver(), android.provider.Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0) != 0;
  } else return false;
}
#End If

B4X:
Sub Process_Globals
    Private NativeMe As JavaObject
End Sub
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        NativeMe.InitializeContext
    End If
    Dim s As Boolean= NativeMe.RunMethod("isDevMode", Null)
    Log($"DevelopeMode enabled: ${s}"$) 'will print true or false
end sub
 
Upvote 0

luqmanhaidar

Member
Licensed User
Longtime User
Add a bit of InlineJava

B4X:
#If Java
public boolean isDevMode() {
  if(Integer.valueOf(android.os.Build.VERSION.SDK) == 16) {
    return android.provider.Settings.Secure.getInt(getApplicationContext().getContentResolver(), android.provider.Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED , 0) != 0;
  } else if (Integer.valueOf(android.os.Build.VERSION.SDK) >= 17) {
    return android.provider.Settings.Secure.getInt(getApplicationContext().getContentResolver(), android.provider.Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0) != 0;
  } else return false;
}
#End If

B4X:
Sub Process_Globals
    Private NativeMe As JavaObject
End Sub
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        NativeMe.InitializeContext
    End If
    Dim s As Boolean= NativeMe.RunMethod("isDevMode", Null)
    Log($"DevelopeMode enabled: ${s}"$) 'will print true or false
end sub
thanks mr donmafred

but The log does not appear why?
 

Attachments

  • intent.zip
    8.3 KB · Views: 131
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
i ran your project on my Device.
This is the Logoutput

Logger connected to: 988ad036525346515630
--------- beginning of crash
--------- beginning of main
** Activity (main) Create, isFirst = true **
DevelopeMode enabled: true
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
--------- beginning of system
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
If you want to run in class:
B4X:
public boolean isDevMode(BA ba) {
  if(Integer.valueOf(android.os.Build.VERSION.SDK) == 16) {
    return android.provider.Settings.Secure.getInt(ba.context.getContentResolver(), android.provider.Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED , 0) != 0;
  } else if (Integer.valueOf(android.os.Build.VERSION.SDK) >= 17) {
    return android.provider.Settings.Secure.getInt(ba.context.getContentResolver(), android.provider.Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0) != 0;
  } else return false;
}
 
Last edited:
Upvote 0
Top