IT EXPLORIDA

Something To know

Showing posts with label Dev Corner. Show all posts
Showing posts with label Dev Corner. Show all posts

Friday, 6 June 2014

Check Battery level in android

You can check the battery level, which could reduce or even stop the frequency of your updates when the battery is almost exhausted.

Retreive the Battery charging state :

For this, you need to call registerReceiver() without registering a BroadcastReceiver because the instance of the BatteryManager broadcasts all battery details in a sticky intent :
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, intentFilter);

The following code describe how to retreive the current charging status and, if the device is being charged :
// Is the battery charging / charged?
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
status == BatteryManager.BATTERY_STATUS_FULL;
// How the battery is charging?
int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean isChargingViaUSB= chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
boolean isChargingViaAC = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
Log.d(TAG, "status : " + status);
Log.d(TAG, "battery is Charging : " + isCharging);
Log.d(TAG, "charging via USB : " + isChargingViaUSB);
Log.d(TAG, "charging via AC : " + isChargingViaUSB);

Retreive the current battery level :
As we explained above, the intent broadcasted bye the BatteryManagercontains all details about battery details(status,charge ..etc) :
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
float batteryPct = level / (float) scale;
Log.d(TAG, "level : " + level + "% , batteryPct : "+ batteryPct);

 

 

Monday, 2 June 2014

Info: .HTACCESS AND ROBOTS.TXT How Valuable these two files are?

Tiny little files have huge contribution towards your website existence. The more tiny they are in size the more powerful features they have.

But one should now play with these files without experience; especially when it comes to RegEx. these files can expose your server to the security threats, can restrict the Search engine Bots. even can impact the accessibility of website to the surfers.

When ever you make a change to these files. Test it again and again at different times and clearing your browser cache. Do NOT trust other people experience shared on the net.

Think Smart, Be Professional.
Awesome Inc. theme. Powered by Blogger.