Thursday, 23 June 2011

How can we get hidden things from log..........

Hi all,

Each developer has tendency that he  wants to access to all services or content of OS.By being an android developer we need to know many hidden information like deviceId,call detection ,call disconnect cause and many more.
Some of the information are provided by android but some are hidden.we can get such king of information Logcat.
each application in android OS have some logcat comment to be print,by parsing them we can easily get such kind of information.

as example following is the source code for detecting the cause of call disconnect or call drop. it is the one of the most important information which is not provided by any direct api or class.


Source code:


try {
            Runtime.getRuntime().exec(LOGCAT_CMD_CLR);
            logprocess = Runtime.getRuntime().exec(LOGCAT_CMD);
        } catch (IOException e) {
            e.printStackTrace();

            isRunning = false;
        }

 


Above code is responsible for executing the logcat.
Where
LOGCAT_CMD :                  logcat
(LOGCAT_CMD_CLR:        logcat -c

try  {
            reader = new BufferedReader(new InputStreamReader(logprocess
                    .getInputStream()), BUFFER_SIZE);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();


            isRunning = false;
        }

Above code is for retrieving log cat input stream in to reader object by doing so we can get entire logcat data in to our own reader object


line = new String[1];


        try {
            boolean check = true;
            while (isRunning) {
                line[0] = reader.readLine();
                String type = line[0].substring(0, 1);
                String reason = null;
                String line1 = line[0].substring(2);


                if (type.equalsIgnoreCase("D"))


                {
                    String linetag = line1.substring(0, 12);


                    if (linetag.equalsIgnoreCase("CallNotifier")) {
                        if (line1.contains("cause")) {
                            reason = line1.split(" ")[7].split(",")[0];
                            IMPInComingPhoneStateListener.mCause = reason;
                            Log.v("call", "" + reason);


                            isRunning = false;


                        } else {
                            IMPInComingPhoneStateListener.mCause = "unknown";


                        }


                    }


                }


            }


            if (check) {
                Log.v("-------------", "normal");
            } else {
                Log.v("-------------", "abnormal");
            }


        } catch (IOException e) {
            e.printStackTrace();


            isRunning = false;
        }

Above code is for parsing the log from reader object and extract the cause of call disconnction.

Here you can see that there is name CallNotifier , it is a class in android os which gives the reason of call drop. we can not use directly that class in to our project



Monday, 16 May 2011

Toast Customization

Hi all

As we know that customization is a great feature of android widgets. we can customize Text view ,Buttons and other view .Like all of these we can also customize "Toast".
Toast is a very tiny  but important tool of android.In our  application,we use this tool for providing instant information to user like "Battery Low" signal or "Location provider enable /disable " information.
But sometime  these toast doesn't match with our application theme for example In red theme, the toast always display in black.
I have customize the toast  not only for color or back ground  but orientation also. By default toast displays in center but we can also customize their orientation means center ,left ,right.

The idea behind customizing the toast is that when we write

Toast.makeText(this,"Text....",Toast.LENGTH_SHORT).show();

Then in directly we are setting the text on text view
So i have extracting the Text View from toast and performing customization over it.
My code is as follows 


protected void myToast( CharSequence text, int ToastPos )
    {
    Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);
    View textView = toast.getView();
    switch ( ToastPos )
    {
    case TOAST_LEFT:
    toast.setGravity( android.view.Gravity.BOTTOM | android.view.Gravity.LEFT, 00, 0);
    break;
    case TOAST_CENTER:
    toast.setGravity( android.view.Gravity.BOTTOM | android.view.Gravity.CENTER, 00, 0);
    break;
    case TOAST_RIGHT:
    toast.setGravity( android.view.Gravity.BOTTOM | android.view.Gravity.RIGHT, 00, 0);
    break;
    }
    textView.setBackgroundResource(R.drawable.icon);
    toast.show();
    }

Where TOAST_LEFT_POS,TOAST_CENTER_POS,TOAST_RIGHT_POS are three Constant
    private final int TOAST_LEFT=3;//android.view.Gravity.LEFT;
    private final int TOAST_CENTER=17;//android.view.Gravity.CENTER;
    private final int TOAST_RIGHT_POS=5;//android.view.Gravity.RIGHT;

so now instead of calling  
Toast.makeText(this,"",),show();
we need to call  
myToast("",orientation);

You can do some more customization over it like text size ,text style background and other.
I hope this tutorial is helpful for you.















How to make money through android app

Hi all

 From the last few day i am in confusion that which is the best way for making money by android application and i have got the ways which i want to share with others.
and it's look like selection  of any particular option is depend upon the requirement and app importance both.

Chances are, you want to make an app so you can make some money. I know I want to. Moving development from a hobby to a business is an exciting prospect, and it’s getting easier and easier on Android. I have developed many app for several organization but my first app is still in development so I won’t be able to point to my own experiences – instead I’ll present the results of my research into the matter.

Monetisation options

The three main ways of monetising your app or game is through selling it, the new in-app billing (more on that below), or with selling advertising space in your app

Free or paid? (Quick answer: both)

The first decision to make is whether you should offer your app for free or for money. Android is special in that many, many more users will install your app if it’s free. This seems obvious, but the difference in downloads is staggering. Take the android game Winds of Steel. The free version has been downloaded somewhere between 20x – 50x as much as the paid version, going by the reported downloads on the Android Market website.
Now, the fact that you can monetise your free version very successfully means you aren’t losing out by offering a free version. But perhaps more importantly, your free app will drive users to your paid app – think of it as marketing. If a user enjoys your app and wants more (more features, more levels, more content) many will jump at the chance to give you a little cash.

In-app billing

For those unfamiliar with the term, in-app billing means you can sell something (anything) from within your app. For a game this could be more levels, the next chapter, items, anything you like. This is an excellent way to get some money for your efforts. For example, Angry Birds has used this method to great success by offering an item called the “Mighty Eagle” which allows a user to skip a level they get stuck on. In-app billing requires setting up your items on the Android developer website, and adding the code to your app. It is very important that you secure any purchased downloaded content.
Interestingly, in-app billing can mean there’s no reason to have a paid version of your app. Any benefit offered with your paid version can be offered instead with your paid downloadable content. Additionally, this means your amount of downloads won’t be split between two versions of your app or game.

Android ad networks

There’s loads of ad networks for Android. For the uninitiated, these are companies that pay you to show small advertisements in your app. The largest of these is probably AdMob, now owned by Google. Here’s a big list. Look for the developer link.
I have tried Admob and mobclix both and personally feels that Admob is much better then other.
so guys use it and share it.



Happy Earning....:)