Tuesday 25 February 2014

How does AirDroid works?

How AirDroid Works? 


I was very curious to know how the AirDroid works, though I was knowing that the data is being passed to HTML page from Android Native and also vice versa.

Actually this works based on hosting a own server on Android device.

Hosting server on your device is possible.

The hosting server is known as PAW server

What is PAW server?

PAW Server is a Web Server for Android devices.
With the PAW webserver you can use the functionality of your phone from a web browser, serve your own web pages or develop phone enabled web applications.


Where can I get It? 

You can get it here


Where can I get more information. 

You  can get it here

Wanna give a try? 

Click here


More about paw server will be coming soon. 

Wednesday 12 February 2014

Android DateTime receiver without using Broadcast Receiver

We usually use Date and Time listener to update Date & Time in our application. This can also be achieved using Runnable and Handler. Which is efficient and very accurate. It just requires the calculation of System Time and Current Time.

Below Snippet is used to update time based on Seconds.

Runnable runnable = new Runnable() {

    @Override
    public void run() {

        long date = System.currentTimeMillis(); 

        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");

        TextView txt = (TextView)findViewById(R.id.txt);
        txt.setText(sdf.format(date));

        handler.postDelayed(runnable, DateUtils.SECOND_IN_MILLIS - System.currentTimeMillis() % DateUtils.SECOND_IN_MILLIS);
    }
};

Similarly on Minute based

Runnable runnable = new Runnable() {

    @Override
    public void run() {

        long date = System.currentTimeMillis(); 

        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");

        TextView txt = (TextView)findViewById(R.id.txt);
        txt.setText(sdf.format(date));

        handler.postDelayed(runnable, DateUtils.MINUTE_IN_MILLIS - System.currentTimeMillis() % DateUtils.MINUTE_IN_MILLIS);
    }
};

 Similarly on Hourly Basis

Runnable runnable = new Runnable() {

    @Override
    public void run() {

        long date = System.currentTimeMillis(); 

        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");

        TextView txt = (TextView)findViewById(R.id.txt);
        txt.setText(sdf.format(date));

        handler.postDelayed(runnable, DateUtils.HOUR_IN_MILLIS - System.currentTimeMillis() % DateUtils.HOUR_IN_MILLIS);
    }
};


Similarly on Daily Basis, which is actually nobody uses. ROFL :D :D but still


Runnable runnable = new Runnable() {

    @Override
    public void run() {

        long date = System.currentTimeMillis(); 

        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");

        TextView txt = (TextView)findViewById(R.id.txt);
        txt.setText(sdf.format(date));

        handler.postDelayed(runnable, DateUtils.DAY_IN_MILLIS - System.currentTimeMillis() % DateUtils.DAY_IN_MILLIS);
    }
};

And so on. Enjoy coding.

Sunday 26 January 2014

Android emulator Internet Speed configuration

These days almost all apps need internet connect, its essential to test our application behavior on various internet connection speed. This is possible through Android emulator. Which gives an option to select internet speed.

The common internet speed provided by Android Emulator are
1. Full
2. GSM
3. HSCSD
4. GPRS
5. EDGE
6. UTMS
7. HSPDA

How to configure Emulator Internet Speed?

Eclipse then Run tab then Run Configurations



then select Target tab as shown in image. 


Scroll down you will see the emulators that you created and Network Speed and Network Latency combo box . 

Select any internet speed and say apply. 

Now your emulator is ready to run with configured internet speed. 

Enjoy testing your app. 


Tuesday 21 January 2014

Dropbox file upload

Dropbox API integration Android 


Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily. 

You can integrate Dropbox in your app & upload file directly into Dropbox

Its helpful for those who doesn't have server or web space. The free upload data is 2GB from Dropbox

To start with DropBox API

  • Create your account in Dropbox
  • Generate App Key & Secrete Key 
  • Download the SDK from Dropbox
  • Change App Key & Secrete Key 


Create your account in Dropbox

Go to www.dropbox.com/, then create an account, Initially Dropbox provides you 2GB of space free!
Click on Developers Tab

Click on App Console, Now you will be able to see this screen 



Generate App Key & Secrete Key 


Click on Dropbox API app & select Files & Datastores

Can your app be limited to its own, private folder? 
Say Yes

Now click on Create App

Now you done with app creation. Now you will be able to see this screen



Download the SDK from Dropbox

Download the SDK from here
Extract & import into your workspace



Change App Key & Secrete Key 

Change both the keys which are present in DBRoulette.java class

Which are defined like this

 final static private String APP_KEY = "Change_here";

 final static private String APP_SECRET = "Change_here";

Now make changes in AndroidManifest.xml as well

 <data android:scheme="db-Change_here" /> 
In the above tag pug App_Key

Now your app is ready to upload file to Dropbox.



Click on Link With Dropbox, it will redirect do Dropbox page ask your permission to access the folder. 



Customize your code as per you want. 

Monday 20 January 2014

Android SQLite data to CSV format

SQLite to CSV

Its easy to export your current SQLite data into Excel or CSV format.

This can be achieved by simple code, which includes csv text file format, which we need to write through code.

CSV format works on the basis of comma and new line.

The below code includes.
1. File creation
2. Writing data to file
3. Fetching data from SQLite & writing in csv format.

You can modify your format however you want, keeping in your mind about commas.

Call this method & pass your file & directory path.



private Boolean backupDatabaseCSV(String outFileName) {
    MyLog.d(TAG, "backupDatabaseCSV");
    Boolean returnCode = false;
    int i = 0;
    String csvHeader = "";
    String csvValues = "";
    for (i = 0; i < GC.CURCOND_COLUMN_NAMES.length; i++) {
        if (csvHeader.length() > 0) {
            csvHeader += ",";
        }
        csvHeader += "\"" + GC.CURCOND_COLUMN_NAMES[i] + "\"";
    }

    csvHeader += "\n";
    MyLog.d(TAG, "header=" + csvHeader);
    dbAdapter.open();
    try {
        File outFile = new File(outFileName);
        FileWriter fileWriter = new FileWriter(outFile);
        BufferedWriter out = new BufferedWriter(fileWriter);
        Cursor cursor = dbAdapter.getAllRows();
        if (cursor != null) {
            out.write(csvHeader);
            while (cursor.moveToNext()) {
                csvValues = Long.toString(cursor.getLong(0)) + ",";
                csvValues += Double.toString(cursor.getDouble(1))
                        + ",";
                csvValues += Double.toString(cursor.getDouble(2))
                        + ",";
                csvValues += "\"" + cursor.getString(3) + "\",";
                csvValues += Double.toString(cursor.getDouble(4))
                        + ",";
                csvValues += Double.toString(cursor.getDouble(5))
                        + ",";
                csvValues += "\"" + cursor.getString(6) + "\",";
                csvValues += Double.toString(cursor.getDouble(7))
                        + ",";
                csvValues += Double.toString(cursor.getDouble(8))
                        + ",";
                csvValues += Double.toString(cursor.getDouble(9))
                        + "\n";
                out.write(csvValues);
            }
            cursor.close();
        }
        out.close();
        returnCode = true;
    } catch (IOException e) {
        returnCode = false;
        MyLog.d(TAG, "IOException: " + e.getMessage());
    }
    dbAdapter.close();
    return returnCode;
}

Enjoy converting SQLite to CSV.