Sunday, 18 August 2013

Displaying Battery Status in Android

Hi,

      Lets have some fun in android!
  

Have you ever thought of displaying battery status in % when ever the battery status changes?

 Displaying Alert when battery level reaches below certain level?



      Yes!!! Lets do it in this post right now ;)

      The approach for doing this is,  Yes using BroadcastReceiver Register it to ask android to notify
     you for every %  of battery changes.

     Use this function to accomplish it.


     private void batteryLevel() {
        BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() {

            public void onReceive(Context context, Intent intent) {
                context.unregisterReceiver(this);
                int rawlevel = intent.getIntExtra("level", -1);
                int scale = intent.getIntExtra("scale", -1);
                int level = -1;
                if (rawlevel >= 0 && scale > 0) {
                    level = (rawlevel * 100) / scale;
                }
                batterLevel.setText("Battery Level Remaining: " + level + "%");
                if(level<30)
                    Toast.makeText(getBaseContext(), "your battery is very low",
                    Toast.LENGTH_LONG).show();
                else
                    Toast.makeText(getBaseContext(), "your battery is fine", Toast.LENGTH_LONG).show();
               
            }
        };
        IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
       registerReceiver(batteryLevelReceiver, batteryLevelFilter);
    }

Call this function and it will register receiver and it will be triggered when every battery level changes.

When battery level changes this receiver will be called and onRecieve() is the default method that gets executed and this function must be overridden.

We unregistered Broadcastreceiver to make sure the function is not interrupted while executing and then
at end of the function we register it again.

I have displayed low when battery level reaches below 30% and fine when it is above that.

Probably you can implement it in your custom way.

It doesn't require any changes in Manifest file.

The output will be like this


 Have a doubt please comment.

You can download complete source code from here
        

Wednesday, 14 August 2013

C program to print INDIA MAP

Happy independence day !!!!!!!!!!!

C program to print INDIA MAP

#include<stdio.h>
void main()
{
int a,b,c;
for (b=c=10;a="- FIGURE?, UMKC,XYZHello Folks,\
TFy!QJu ROo TNn(ROo)SLq SLq ULo+\
UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
Hq!WFs XDt!" [b+++21]; ) {
for(; a-- > 64 ; )
{
putchar ( ++c=='Z' ? c = c/ 9:33^b&1);
}
}
}

Here is the output of the above program


Monday, 5 August 2013

Creating CAPTCHA using PHP

What is CAPTCHA?

CAPTCHA stands for Computer Automated Public Turing test to tell Computers and Humans apart

They are used for providing security  in various applications like login forms , registration , password recovery etc .



Now lets Create our own captcha application .


Here goes the html code for the application .
The file is named as Captcha.html



Here goes the  PHP code for image creation.
The file is named as captcha_validation.php.



Here goes the  PHP for image creation.
The file is named as image_creation.php.


Here is the output screen


Just download the files from here and enjoy :-)

All the best :-)

Leave your doubts and suggestions in the comments section :-)