Android - How to check if Developer option is enabled - android

How can I check if the user has developer option enabled on its device?
(not with adb comunication active, or debug USB active, I need to know only if Developer Option are enabled).
I've tried this solution:
How to check programmatically whether app is running in debug mode or not?
but it doesn't work for me.
Thanks in advance

try this:
int adb = Settings.Secure.getInt(this.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0);

You should use
getInt or another in Settings.Global
with
DEVELOPMENT_SETTINGS_ENABLED
Edit :
Below API 17, it is the same but with Settings.Secure

Here's a method that returns true if developer mode is enabled for all devices at Android 4.1 or above (API 16), returns false if developer mode is not enabled on such devices, and returns false on all earlier Android devices down to 1.0.
#android.annotation.TargetApi(17) 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;
}

Kotlin solution:
#RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
fun isDevMode(context: Context): Boolean {
return when {
Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN -> {
Settings.Secure.getInt(context.contentResolver,
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0
}
Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN -> {
#Suppress("DEPRECATION")
Settings.Secure.getInt(context.contentResolver,
Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0
}
else -> false
}
}

It's Simple to Find -- Developer Mode is On or Not!!!
Java solution:
if (PreferenceHelper.isDevMode(context)) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("Please Turn Off Developer Option \n" +
" \n" +
" Go to Settings > Search developer options and toggle them off.");
builder.setCancelable(false);
builder.setNegativeButton(" Ok ", (dialog, which) -> {
dialog.dismiss();
finish();
});
builder.setPositiveButton(" Turn Off ", (dialog, which) -> {
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
alertDialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE).setTextColor(Color.parseColor("#37367C"));
return;
}

Cordova or Ionic solution :
https://github.com/Secullum/cordova-plugin-devoptionschecker
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
cordova.plugins.devoptionschecker.check(successCallback, errorCallback);
}
function successCallback(result) {
// json object which returns devOptionsEnabled: true - enabled, false - disabled
console.log(result);
}
function errorCallback(error) {
console.log(error);
}

I had search for so many methods finally i got the method and its is working fine in android studio also in app
it is mentioned below
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));

Related

detect wireless debugging option active or not in developer mode in android programmatically

I have tried developer mode and USB debugging is enabled or not,
using the below code changes. it's working fine.
private fun check_My_Android_Mobile_Developer_Mode_Status() {
// solution 1
val adb: Int = Settings.Secure.getInt(this.contentResolver,
Settings.Global.ADB_ENABLED, 0)
Toast.makeText(this,"USB Debugging Detect: adb mode:"+adb, Toast.LENGTH_LONG).show()
// solution 2
if(Settings.Secure.getInt(this.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1) {
// Developer Mode enabled
Toast.makeText(this,"Developer Mode enabled: Show Alert", Toast.LENGTH_LONG).show()
} else {
//Developer Mode does not enabled
Toast.makeText(this,"Developer does not enabled: Running Safe Mode", Toast.LENGTH_LONG).show()
}
}
But, I want to check wireless debug mode is enabled or not alone(from developer mode On status). I unable to find any solution.
can anyone help on this. Thanks Advance. Referred links below:
how-to-check-usb-debugging-enabled
wireless-adb-android-11
android-detect-when-adb-active-over-usb
Android source code reveals the wifi debugging setting: https://cs.android.com/android/platform/superproject/+/master:packages/apps/Settings/src/com/android/settings/development/WirelessDebuggingEnabler.java;l=73?q=wireless%20debugging
Settings.Global.ADB_WIFI_ENABLED = "adb_wifi_enabled"
fun isWifiAdbEnabled(): Boolean {
// "this" is your activity or context
return Settings.Global.getInt(this.contentResolver, "adb_wifi_enabled", 0) != 0
}
Usage:
Toast.makeText(this, "adb mode: ${isWifiAdbEnabled()}", Toast.LENGTH_LONG).show()

isHardwareAccelerated() always returns false

I am trying to turn on hardware acceleration for my application
but I never seem to get a 'true' result from this function.
I tried all the methods in the Android Developers blog post about the
the tag android:hardwareAccelerated=true to the application
and even called
getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
You should always call isHardwareAccelearted() after the view is attached to the window. I am not sure about your case as I can't see where actually you are calling it.
Also, the support level of various operations across API levels are mentioned here. I hope this helps.
You can also try this method to verify hardwareAcceleration.
public static boolean hasHardwareAcceleration(Activity activity) {
// Has HW acceleration been enabled manually in the current window?
Window window = activity.getWindow();
if (window != null) {
if ((window.getAttributes().flags
& WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0) {
return true;
}
}
// Has HW acceleration been enabled in the manifest?
try {
ActivityInfo info = activity.getPackageManager().getActivityInfo(
activity.getComponentName(), 0);
if ((info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
return true;
}
} catch (PackageManager.NameNotFoundException e) {
Log.e("Chrome", "getActivityInfo(self) should not fail");
}
return false;
}
For checking for View try this.
chat_wv.post(new Runnable() {
#Override
public void run() {
Log.e("isHardwareAccelerated", ""+chat_wv.isHardwareAccelerated());
}
});

How to check if "verify app" is enabled or disabled programmatically

I've a security requirement to alert users if google's "verify app" is disabled on app launch. The problem is that I dont know any way to check whether "verify app" is disabled or not.
I tried to use the code below, but it's always returning 1.
int verifierInt = -1;
if (Build.VERSION.SDK_INT >= 17) {
verifierInt = Settings.Global.getInt(context.getContentResolver(), "package_verifier_enable", -1);
} else if (Build.VERSION.SDK_INT >= 14) {
verifierInt = Settings.Secure.getInt(context.getContentResolver(), "verifier_enable", -1);
} else {
// No package verification option before API Level 14
}
boolean isVerifyAppEnabled = verifierInt == 1;
Also, as a requirement, want user to be navigated to the "verifiy app" settings if this feature is disabled.
You should check like this:
Settings.Global.getInt(context.getContentResolver(), "verifier_verify_adb_installs", -1);
Reading preferences, won't help anymore as android don't update preferences now. So basically reading preferences value for google Verify won't work.
Please use below SaftyNet callbacks to verify google protect.
SafetyNet.getClient(context)
.isVerifyAppsEnabled()
.addOnCompleteListener(new OnCompleteListener<SafetyNetApi.VerifyAppsUserResponse>() {
#Override
public void onComplete(#NonNull Task<SafetyNetApi.VerifyAppsUserResponse> task) {
---
}
});

How to tell if GPS is enabled on Android using Titanium

I am working on an Android 3.2+ app in Titanium. It is crucial that I am able to determine if the device has GPS enabled. According to the Titanium API reference, Ti.Geolocation.locationServicesEnabled will always return true on Android 2.2+, because of a new "passive" location provider. Is there any other way of determining if GPS is truly enabled?
Thanks.
i think this code should work for you:
//check to see if we have GPS capabilities
if(Titanium.Geolocation.isLocationProviderEnabled(Titanium.Geolocation.PROVIDER_GPS, Titanium.Geolocation.ACCURACY_BEST) == false) {
var alertDlg = Titanium.UI.createAlertDialog({
title:'MileTrackGPS',
message:'GPS is OFF. Enable it in Settings.',
buttonNames: ['Cancel', 'Open Settings']
});
alertDlg.cancel = 0;
alertDlg.addEventListener('click', function(e){
if(!e.cancel) {
//open up the settings page
var settingsIntent = Titanium.Android.createIntent({
action: 'android.settings.LOCATION_SOURCE_SETTINGS'
});
activity.startActivity(settingsIntent);
}
else {
//close the window to exit
win.close();
}
});
alertDlg.show();
}
refrence
Alright here is an easy solution I came up with and it works well for me. I have a global variable 'timeStamp' which I initially set to zero.
Titanium.Geolocation.getCurrentPosition(function(e){
//only update fields if timer is still active
if(gpsTimer!=null)
{
//if the provider is not GPS or the timestamp is the same as the last, we do not want the results. We need to alert the user that they need to turn their GPS on.
if(e.provider['name']!="gps" || timeStamp==e.coords.timestamp)
{
//clear timeout
clearTimeout(gpsTimer);
gpsTimer = null;
//close window
get_gps_win.close();
//garbage collection
get_gps_win = null;
gpsLatField = null;
gpsLongField = null;
gpsAccuracyField = null;
timeStamp=0;
//alert user
alert("This feature is not available unless you have GPS turned on. Please turn GPS on and then try again.");
}
else
{
//update fields
gpsLatField.value=ConvertDDToDMSPlain(e.coords.latitude);
gpsLongField.value=ConvertDDToDMSPlain(e.coords.longitude);
gpsAccuracyField.value=e.coords.accuracy+" meters/"+(e.coords.accuracy*3.28084)+" feet";
gpsTimer=setTimeout(function() {
Titanium.Geolocation.fireEvent('location');
}, 1000);
}
timeStamp= e.coords.timestamp;
}
});

android keyboard open issue

How can i know if the keyboard is open or not?
This is available on the Configuration class. You can get the current Configuration via getResources().getConfiguration() from your Activity or other Context.
That way =)
public boolean isKeyboardVisible(){
// Checks whether a hardware keyboard is visible
if (getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
return true;
} else if (getResources().getConfiguration()..hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
return false;
}
}

Categories

Resources