天道酬勤,学无止境

android-settings

How to know whether Notifications are enabled or not for an application in android?

Question I've a ListView which has the list of installed applications and for each application, I need to know whether the notifications are enabled or not. Currently I'm using below code to know if the notifications are enabled: appOpsClass = Class.forName(AppOpsManager.class.getName()); Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class); Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION); int value = (int)opPostNotificationValue.get(Integer.class); return ((int)checkOpNoThrowMethod.invoke(mAppOps

2021-11-30 19:46:46    分类:技术分享    android   android-notifications   android-settings

How Do I Disable AIRPLANE MODE tablet supports 4.4.2

Question I have to disable AIRPLANE MODE and DATE TIME SETTINGS in my app, for that i used these intent filters but none of them works for me <uses-permission android:name="android.permission.WRITE_SETTINGS" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.settings.AIRPLANE_MODE_SETTINGS" /> <category android:name="android.intent

2021-11-28 17:37:51    分类:技术分享    android   android-manifest   intentfilter   airplane   android-settings

How to Enable Android Download Manager

Question I'm using Android Download Manager to download list of files. Lately I came across a crash report saying Unknown java.lang.IllegalArgumentException: Unknown URL content://downloads/my_downloads Then later, I figured it out that the reason is because user disabled Android Download Manager. I check if the Download Manager is disabled by checking it's package name with the code below. int state = this.getPackageManager().getApplicationEnabledSetting("com.android.providers.downloads"); And now, I need to find a way to enable the Download Manager if it is disabled. I tried setting it's

2021-11-28 00:59:09    分类:技术分享    android   android-package-managers   android-download-manager   android-settings

Disabling an app or activity zoom if Setting -> Display -> Display size changed to Large or small

Question In my app, I don't want to allow it to resize as its creating design issues. I have tried with android:resizeableActivity="false" in the application tag and the launcher activity tag but it didn't help. Answer1 I have found a solution for it. If system text size changed or Display size set to Large (Above Android Oreo), Your app will behave as normal (No big text and and zoomed views) with below code: Configuration configuration = getResources().getConfiguration(); configuration.fontScale = (float) 1; //0.85 small size, 1 normal size, 1,15 big etc DisplayMetrics metrics = new

2021-10-22 23:57:16    分类:技术分享    android   android-manifest   android-settings

How to open and check whether Play Protect is enabled or disabled

Question minSdkVersion 18 targetSdkVersion 27 Using below code, I can able to open the Google Settings page. private static final String GOOGLE_SETTINGS_COMPONENT = "com.google.android.gms"; private static final String GOOGLE_SETTINGS_ACTIVITY = ".app.settings.GoogleSettingsActivity"; Intent i = new Intent(); i.setClassName(GOOGLE_SETTINGS_COMPONENT,GOOGLE_SETTINGS_COMPONENT + GOOGLE_SETTINGS_ACTIVITY); try { startActivity(i); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(getApplicationContext(), "Activity Not Found", Toast.LENGTH_LONG).show(); } Is it possible to

2021-10-20 11:29:06    分类:技术分享    android   android-intent   google-play   android-settings   google-settings

Get Device mac adress in Android Nougat and O programmatically

Question I have an application, which required device mac address. I'm getting mac address in Marshmallow and below easily but problem with android nougat and O. So how to find mac. Answer1 Changed since 6.0 and later: https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-hardware-id To provide users with greater data protection, starting in this release, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The WifiInfo.getMacAddress() and the BluetoothAdapter.getAddress() methods now

2021-10-10 11:25:22    分类:技术分享    android   android-7.0-nougat   android-settings   android-8.0-oreo

How to detect/identify if device Lock Screen setting is set to None?

Question I need to check before enabling my application if the device has no security defined on setting. Can't have set: Pattern, PIN, Password and even Swipe. Does anyone know a way to check if the lock screen setting is not enabled? Alternately, can we check which of the above lock screen settings is enabled? Thanks! Answer1 You can use KeyguardManager - it's isSecureMethod() should return false in Your case. http://developer.android.com/reference/android/app/KeyguardManager.html

2021-10-07 07:57:25    分类:技术分享    android   android-settings   android-security

vibrate_when_ringing on Android Marshmallow (6.0)

Question In my code I have: Settings.System.putInt(this.getContentResolver(), "vibrate_when_ringing", isVibrateWhenRinging ? 1 :0); Using the following permission: <uses-permission android:name="android.permission.WRITE_SETTINGS" /> This was working fine from Jelly Bean (API 16) till Lollipop (API 22). In Android M, I know that for using that permission I need to prompt the user to Settings.ACTION_MANAGE_WRITE_SETTINGS. However, even with that permission turned on, I see the following error: E/AndroidRuntime: java.lang.IllegalArgumentException: You cannot change private secure settings. E

2021-09-29 12:17:04    分类:技术分享    android   android-6.0-marshmallow   android-vibration   android-settings

How to pop up Enable Bluetooth prompt from Google Play Services?

Question Application I'm working on uses both Locations and BLE and if location or bluetooth are disabled I have to ask user to enable them. Latest Google Play Services provides a standard way to do that using LocationSettingsRequest which checks requirements and raises standard popup if changes to settings are required. It works like a charm for location alone but once I add SetNeedBle (true) to LocationSettingsRequest I get a status SETTINGS_CHANGE_UNAVAILABLE. The only my guess was I need to add AddApi (FitnessClass.BLE_API) call to a GoogleApiClientBuilder as it might be vital for BLE

2021-09-29 03:51:44    分类:技术分享    android   bluetooth   google-play-services   android-settings

Devices without “Apps using Usage Data” or android.settings.USAGE_ACCESS_SETTINGS intent

Question Background: Android 5 introduced a new UsageStats API that can be used to query time spent with different apps. This API is used in several apps for detecting the current foreground app (as discussed in several questions, like this), but: This API requires the permission android.permission.PACKAGE_USAGE_STATS, which is a system-level permission and will not be granted to third-party apps. However, declaring the permission implies intention to use the API and the user of the device can grant permission through the Settings application. As the permission is not presented to the user

2021-09-28 23:53:30    分类:技术分享    android   android-intent   android-permissions   android-settings