Android Dev Tools

Here's casual list for Android developer tools that could be really useful when developing complex applications:

  • StrictMode: A tool for identifying long running operations on Main UI Thread.
  • @UiThread/@WorkerThread : Useful support annotations for static analysis for catching Threading bugs.

Android Fragments using RxJava and Dagger

This is really cool introduction on Android Fragments using RxJava and Dagger dependency injection framework.

How to keep github fork repo in sync with main repo

This is how I keep my forked repo in sync with their main repos:

Create fork of the main repo.

Clone forked repo to your local machine:
git clone https://github.com/<username>/somerepo.git

Add main repo as another remote:

git remote add mainrepo https://github.com/<someurl>/somerepo.git

Fetch all the branches from mainrepo :
 git fetch mainrepo

Make sure that you're on your master (origin/master) :
git checkout master

Rebase your copy of master with main repo's master like this:
git rebase mainrepo/master

How to fix "Plugin with id 'com.android.library' not found." issue with Android Libraries

Normal structure of build.gradle for an Android library looks like this:
apply plugin: 'com.android.library'
android {
    compileSdkVersion 23 
    buildToolsVersion '23.0.0'
    defaultConfig {
        minSdkVersion 11 
       targetSdkVersion 23 
       versionCode 1 
       versionName "1.0" 
    }
    buildTypes {
        release {
            /runProguard false 
           proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }
    }
}

You might encounter dreaded "Plugin with id 'com.android.library' not found." error while importing this library project as an independent project in Android Studio.

After researching for a while around the web, I figured out what was missing. Actually, a way to tell your library project's gradle file to source to get the plug-in. Pretty straight forward, but may not occur when needed.

So, don't forget to add these lines at the beginning of the build.gradle for your Android library:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'    }
}

apply plugin: 'com.android.library'
....

 

Finding tech work online ?

Are you interested in taking up projects online and work from wherever you like to ?  Your home...Your favorite coffee shop or may be your beautiful patio ! Yes ??? Read on ...


I've compiled few websites that you may want to look at:

  • Topcoder : You can take up a challenge and work thru it in order to get paid ! Perfect for hobbyists !
  • Upwork : An upcoming company coming up to connect talent with companies. Its a freelancers paradise.
  • ....More are coming up!




Developing Hybrid mobile applications for iOS and Android

Today I found out a promising open source project or better say a SDK to build hybrid apps for iOS and Android. Its called Ionic.

I'm looking forward to play around with it a little bit and will be posting my findings on this very blog. Stay Tuned !

When/Why to use Android DownloadManager to download remote files

DownloadManager should be used when your app is not dependent on downloaded data to show as a first thing. It queues requested download in device wide download queue, and download data in background. You may not get your data downloaded immediately to display in your app.

If the dependency of your app on remote data is synchronous, then you may want to download data using AsyncTask, and possibly using code like this in it:

InputStream inputStream = new URL(url).openStream();
//Copy input stream to to output stream now. 

But if you don't care about the timing of data download, then you should use DownloadManager like this:

String url = "http://url_to_your_remote-data";
DownloadManager  dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Request request = new Request(Uri.parse(url));
request.setDestinationInExternalFilesDir(getApplicationContext(),
        Environment.DIRECTORY_DOWNLOADS, "downloaded_data_filename");
enqueue = dm.enqueue(request);

And don't forget to register broadcast receiver in onCreate() method. That's where you'll receive callback once download is finished. Example:

BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
            long downloadId = intent.getLongExtra(
                    DownloadManager.EXTRA_DOWNLOAD_ID, 0);

            Uri localUri = dm.getUriForDownloadedFile(enqueue);
            //Do something with your download here...OR query useful params like below. 

            Query query = new Query();
            query.setFilterById(enqueue);
            Cursor c = dm.query(query);
            if (c.moveToFirst()) {
                int columnIndex = c
                        .getColumnIndex(DownloadManager.COLUMN_STATUS);
                if (DownloadManager.STATUS_SUCCESSFUL == c
                        .getInt(columnIndex)) {

                    String uriString = c
                            .getString(c
                                    .getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                    Log.d("TAG", uriString);
                    
                }
            }
        }
    }
};

registerReceiver(receiver, new IntentFilter(
        DownloadManager.ACTION_DOWNLOAD_COMPLETE));



Scheduling Repeating Local Notifications using Alarm Manager

Learn about Scheduling Repeating Local Notifications using Alarm Manager in this post .