Just an example, I can get the Display Timeout setting like this:
int timeout = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT);
I can set the Display Timeout setting like this:
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 10000);
How can I programmatically get and set the Fast Charging and the Super Fast Charging settings?
Edit: Thanks to Veniamin for helping me get the correct variable names, here's what worked for me:
try {
int isSuperFastChargingEnabled = Settings.System.getInt(getContentResolver(), "super_fast_charging");
if ( isSuperFastChargingEnabled == 0) {
Settings.System.putInt(getContentResolver(), "super_fast_charging", 1);
Settings.System.putInt(getContentResolver(), "adaptive_fast_charging", 1);
Toast.makeText(this, "Fast charge is set to 1",Toast.LENGTH_LONG).show();
} else if ( isSuperFastChargingEnabled == 1) {
Settings.System.putInt(getContentResolver(), "super_fast_charging", 0);
Settings.System.putInt(getContentResolver(), "adaptive_fast_charging", 0);
Toast.makeText(this, "Fast charge is set to 0",Toast.LENGTH_LONG).show();
}
} catch (Settings.SettingNotFoundException e) {
Toast.makeText(this,"Failed to get fast charge setting",Toast.LENGTH_LONG).show();
}
You can read and update these settings in the Device Care Samsung system application, so I reverse engineered it.
Here is how you can read Fast Charging, Super Fast Charging, and Fast Wireless Charging settings in your application:
val isSuperFastChargingEnabled = Settings.System.getInt(context.contentResolver, "super_fast_charging", 0) == 1
val isFastChargingEnabled = Settings.System.getInt(context.contentResolver, "adaptive_fast_charging", 0) == 1
val isFastWirelessChargingEnabled = Settings.System.getInt(context.contentResolver, "wireless_fast_charging", 0) == 1
Unfortunately, to update these settings programmatically, you need the android.permission.WRITE_SETTINGS permission is only granted to the system applications.
So, if you are not developing a system app, the only way to enable these settings is to ask users to enable them manually. To simplify workflow, you can route users directly to the system Fast Charging Settings Activity, like so:
val intent = Intent()
intent.component = ComponentName(
"com.samsung.android.lool",
"com.samsung.android.sm.battery.ui.BatteryAdvancedMenuActivity"
)
// Activity class name may be updated in future versions, so
// the safest way to handle Activity class name updates is to wrap this
// call in the try/catch and add a custom error handling if the activity wasn't found.
try {
startActivity(intent)
} catch (e: Exception) {
// Custom error handling
}
Since these settings are vendor-specific, checking the vendor id before reading them is recommended.
I tested it and confirm that it works on the Samsung Galaxy S20 (SM-G980F/DS); Android 12; One UI 4.1.
Related
I installed the app after build on different devices (Android) the app opens up fine but when sending network request only one of the device is able to send successfully the others remain unresponsive.
Am using the Rest.post() to send that particular request.
Using codename one 6.0 but updated it this morning so I will be using the recent version.
Note: the situation happened before the update. i added a bunch of things while trying to locate the problem.
Here is the code:
//...Login button ActionListner
gui_Button_login.addActionListener((ae)->{
gui_Infinite_Progress.setVisible(true);
gui_Infinite_Progress.setEnabled(true);
gui_Button_login.setEnabled(false);
gui_Text_Field_username.setEnabled(false);
gui_Text_Field_Password.setEnabled(false);
if(doLogin()){
Handle.UserFeed = new UserFeedForm();
Handle.UserFeed.show();
}else{
gui_Button_login.setEnabled(true);
gui_Text_Field_username.setEnabled(true);
gui_Text_Field_Password.setEnabled(true);
gui_Infinite_Progress.setVisible(false);
gui_Infinite_Progress.setEnabled(false);
}
});
//...Do login function
private boolean doLogin(){
String usr_username = gui_Text_Field_username.getText();
String usr_password = gui_Text_Field_Password.getText();
Map<String, Object> signInData = new HashMap<>();
signInData.put("usr_username", usr_username);
signInData.put("usr_password", usr_password);
String signInDataJSON = JSONParser.mapToJson(signInData);
gui_Span_Label_Debug.setText(gui_Span_Label_Debug.getText() +"\nData:\n"+ signInDataJSON);
gui_Span_Label_Debug.setText(gui_Span_Label_Debug.getText() +"\nSending...");
Response<Map> response = Rest.post(Data.API_SIGNIN_URL)
.jsonContent()
.body(signInDataJSON)
.acceptJson()
.onErrorCodeJSON(err->{
ToastBar.showErrorMessage(err.getResponseErrorMessage(), Data.MESSAGE_ERROR_TIMEOUT);
//gui_Span_Label_Debug.setText(gui_Span_Label_Debug.getText() +"\nError:\n"+ err.getResponseErrorMessage());
}).getAsJsonMap();
Map<String, Object> responseData = response.getResponseData();
if(response.getResponseCode() == 0){
ToastBar.showErrorMessage("Please check your internet!", Data.MESSAGE_ERROR_TIMEOUT);
}
gui_Span_Label_Debug.setText(gui_Span_Label_Debug.getText() +"\nResponse Code:\n"+ response.getResponseCode());
gui_Span_Label_Debug.setText(gui_Span_Label_Debug.getText() +"\nResponse Error Msg:\n"+ response.getResponseErrorMessage());
if(responseData == null){
return false;
}
if(((String)responseData.get("status")).equalsIgnoreCase("error")){
ToastBar.showErrorMessage((String)responseData.get("msg"), Data.MESSAGE_ERROR_TIMEOUT);
return false;
}
if(((String)responseData.get("status")).equalsIgnoreCase("success")){
ToastBar.showMessage((String)responseData.get("msg"), FontImage.MATERIAL_CHECK_CIRCLE, Data.MESSAGE_SUCCESS_TIMEOUT);
Handle.LoggedInUserData = (Map<String, Object>) responseData.get("data");
Handle.Authority = (String)Handle.LoggedInUserData.get("jwt");
return true;
}
return false;
}
//...
Data.API_SIGNIN_URL is a string containing address accessible via internet e.g. http://94.543.23.4/
I'm guessing you are trying to connect via an IP to a specific machine and it isn't working. This machine is probably visible only within your internal network and the other devices aren't connected to the internal network or choose a route via cell towers.
well i added the build hint android.xpermissions and set the value to android.permission.INTERNET\=true,android.permission.WRITE_EXTERNAL_STORAGE\=true,android.permission.READ_EXTERNAL_STORAGE\=true.
Its working but seems redundant to me since according to codenameone docs Internet permission is inserted by default. i added the storage just to avert possible similar situation
I've got a game app and it requires repeated tapping. Some players are complaining that it doesn't work when they have the "triple tap to zoom" accessibility gesture enabled on their device.
Web search showed me that it can't be disabled within my game, but can it be detected? At least then I can explain to users how to turn it off while playing.
I'm not sure which android API I could use to check this setting. I'm not a native android developer, I work in Unity and Google isn't turning up anything.
Thanks to zcui93, I was able to test for this setting using the following Java:
Settings.Secure.getInt( context.getContentResolver(), "accessibility_display_magnification_enabled" );
...just check the return value: 1 = enabled, 0 = disabled
Here's the code to do it in a Unity C# Script:
public static bool CheckForSystemZoomEnabled()
{
#if UNITY_ANDROID
try {
using(AndroidJavaClass clsUnity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
AndroidJavaObject objActivity = clsUnity.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject objResolver = objActivity.Call<AndroidJavaObject>("getContentResolver");
using(AndroidJavaClass clsSecure = new AndroidJavaClass("android.provider.Settings$Secure"))
{
int val = clsSecure.CallStatic<int>("getInt", objResolver, "accessibility_display_magnification_enabled");
return val != 0;
}
}
} catch(System.Exception) { }
#endif
return false;
}
I am trying to get local/scheduled notifications working. With push messages (using Parse) working fine I though local would be easy, but even though the registration seems to go fine (didRegisterUserNotificationSettings is fired) and the scheduling seems to work too, the notification does not show up. I have tested on iOS 7 (iphone 4) and iOS 9 (iphone simulator). What am I missing?
here is my code:
#Override
public boolean didFinishLaunching(UIApplication application,UIApplicationLaunchOptions launchOptions)
{
boolean retval = super.didFinishLaunching(application, launchOptions);
//some other stuff happens here regarding parse push. But since this works I have cut it out
registerForPush();
return retval;
}
public void registerForPush()
{
if (IOSLauncher.getOSMajorVersion() >= 8)
{
UIUserNotificationType userNotificationTypes = UIUserNotificationType.with(UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound);
UIUserNotificationSettings settings = new UIUserNotificationSettings(userNotificationTypes, null);
application.registerUserNotificationSettings(settings);
application.registerForRemoteNotifications();
}
else
{
UIRemoteNotificationType type = UIRemoteNotificationType.with(UIRemoteNotificationType.Alert, UIRemoteNotificationType.Badge, UIRemoteNotificationType.Sound);
application.registerForRemoteNotificationTypes(type);
}
}
public void scheduleNotification(String title, String text, Date date, int ID)
{
UILocalNotification notification = new UILocalNotification();
if(getOSMajorVersion() >= 8 && getOSMinorVersion() >= 2)
notification.setAlertTitle(title);
notification.setAlertBody(text);
notification.setFireDate(new NSDate(date));
NSMutableDictionary<NSObject, NSObject> dict = new NSMutableDictionary<>();
dict.put("id",NSNumber.valueOf(ID));
notification.setUserInfo(dict);
UIApplication.getSharedApplication().scheduleLocalNotification(notification);
}
Edit:
After settting the notification it is present in the array returned by:
UIApplication.getSharedApplication.getScheduledLocalNotifications();
The problem was resolved after Adding:
notification.setTimeZone(NSTimeZone.getLocalTimeZone());
and setting the expire time of my test timer from 1 minute to 5 minutes
I'm not sure which is the actual solution, but the problem is gone, so I'm happy!
EDIT:
UILocalNotification notification = new UILocalNotification();
notification.setAlertTitle("title");
notification.setAlertBody("text");
NSMutableDictionary<NSObject, NSObject> dict = new NSMutableDictionary<>();
//add any customer stuff to your dictionary here
notification.setUserInfo(dict);
notification.setFireDate(new NSDate(date)); //date is some date in the future. Make sure it is in the correct TZ. If it does not work, try to make it at least 5 minutes in the future. I remember this helping my situation
notification.setTimeZone(NSTimeZone.getLocalTimeZone());
UIApplication.getSharedApplication().scheduleLocalNotification(notification);
I've created an address book app, and am trying to add some features to it. What I'm trying to do right now is add the ability to longclick a phone number, and then either call/text/mms the number. This all works fine with phones, but I was wondering how to do this on tablets, since they will not have that same ability. The device I'm debugging on is a tablet, and I use HeyWire for texting. I know there are apps out there for calling via WiFi as well. Here's what I have so far for the texting section of my switch statement:
case 1: //SMS
if(CanCallAndText)
{
CustomSMSDialog SendSMSDialog = new CustomSMSDialog(BrowseListActivity.this, ParsedPhoneNum);
SendSMSDialog.setTitle("Sending text to " + PhoneNum);
SendSMSDialog.setCancelable(false);
SendSMSDialog.show();
}
else
{
try
{
Intent WiFiSMS = new Intent(Intent.ACTION_VIEW);
WiFiSMS.setData(Uri.parse("sms:" + PhoneNum));
WiFiSMS.setType("vnd.android-dir/mms-sms");
startActivityForResult(Intent.createChooser(WiFiSMS, ""), 0);
}//endtry
catch(Exception e)
{
Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}//endcatch
}//endelse
break;
I don't know if I'm doing the create chooser incorrectly or not, but it simply tells me that no apps can handle it. Thank you!
EDIT: Ooh, spotted a slight error that I should fix tomorrow. The URI should include ParsedPhoneNum, instead of PhoneNum. Anything other than a number, like a -, would be included in PhoneNum.
I'm working on the recurring serial number topic to provide a unique id.
I try this :
String serial = null;
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
serial = (String) get.invoke(c, "ro.serialno");
} catch (Exception ignored) {
}
and
StringBuilder sb = new StringBuilder();
sb.append("SERIAL ").append(android.os.Build.SERIAL).append("\n");
textReportAdmin.setText(
sb.toString());
Both gives the same value : C4F12FDD949F22F
On the box and on the sticker of my tab, the serial number is : RF2C202WYME
I work on a tab, no way to use
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imei = telephonyManager.getDeviceId();
IMEI is empty in my case.
SERIAL is what I need, but I need it in clear version as displayed on the sticker upon the barcode behind the tab.
I guess it is possible as, When going in the system app, and looking at the state of the device, it is displayed in clear...
How to convert the value returned by android.os.Build.SERIAL to the human visible one ?
EDITION : I also looked in :
sb.append("PRODUCT ").append(android.os.Build.PRODUCT).append("\n");
sb.append("BOARD ").append(android.os.Build.BOARD).append("\n");
sb.append("BOOTLOADER ").append(android.os.Build.BOOTLOADER).append("\n");
sb.append("BRAND ").append(android.os.Build.BRAND).append("\n");
sb.append("CPU_ABI ").append(android.os.Build.CPU_ABI).append("\n");
sb.append("CPU_ABI2 ").append(android.os.Build.CPU_ABI2).append("\n");
sb.append("DEVICE ").append(android.os.Build.DEVICE).append("\n");
sb.append("DISPLAY ").append(android.os.Build.DISPLAY).append("\n");
sb.append("FINGERPRINT ").append(android.os.Build.FINGERPRINT).append("\n");
sb.append("HARDWARE ").append(android.os.Build.HARDWARE).append("\n");
sb.append("HOST ").append(android.os.Build.HOST).append("\n");
sb.append("ID ").append(android.os.Build.ID).append("\n");
sb.append("MANUFACTURER ").append(android.os.Build.MANUFACTURER).append("\n");
sb.append("MODEL ").append(android.os.Build.MODEL).append("\n");
sb.append("PRODUCT ").append(android.os.Build.PRODUCT).append("\n");
sb.append("RADIO ").append(android.os.Build.RADIO).append("\n");
sb.append("SERIAL ").append(android.os.Build.SERIAL).append("\n");
sb.append("TAGS ").append(android.os.Build.TAGS).append("\n");
sb.append("TIME ").append(android.os.Build.TIME).append("\n");
sb.append("TYPE ").append(android.os.Build.TYPE).append("\n");
sb.append("USER ").append(android.os.Build.USER).append("\n");
nowhere, I get the serialnumber as on the sticker, while it can be possible to be found as ,the system itself is able to display it in "Parameters", "About", "State" (I don't know the words in english, I have a french tab, and it is "Paramètres", "A propos de", "Etat" and then "Serial Number", the clear version, as on the sticker.
Have you tried this?
String serial = null;
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
serial = (String) get.invoke(c, "ril.serialnumber");
} catch (Exception ignored) {
}
If you want to get the serial number as shown on the back of the device and if you are using the Samsung Galaxy Tab then why not use the 'ril.serialnumber' property
Items changed to what your device should show:
$ adb shell getprop | grep serial
[ril.serialnumber]: [RF2C202WYME]
[ro.boot.serialno]: [c4f12fdd949f22f]
[ro.serialno]: [c4f12fdd949f22f]
Pre-jellybean 'ro.boot.serialno' didn't exist
On many devices there is information displayed in the Settings --> About activity that is non-standard and is not available from any standard Android API. For example, the FCC ID is sometimes displayed there but is not available to apps.
Also, there is no requirement that the serial number available through the API's be the product's 'real' serial number (i.e. the one on the package). Just that it be unique.
So, I think there is no way to do what you want (read the serial number that is on the box and in the about activity) other then look through that product's source code (if available) and see if there is a way to get that info for that particular product or manufacturer.
you should use
sys.serialnumber ,some devices have ril.serialnumber and some have sys.serialnumber ,so you should try sys one