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));



Sharing Code in Android Studio using "AAR"

Believe it or not, but Android Studio was launched with absolute no support to share code across several projects. You would need to keep a separate copy of "shared library" with in each project that uses it ! I was sarcastically impressed (or rather depressed) by Google's product owner for Android Studio who dared to give out that kinda IDE to developers.

Finally, they gave out some way to share code through "AAR" files. Thank you !

However, adding ".aar" files is not recommended locally as per this article. AAR files should be referenced from maven repos. You can always publish them to local maven repos for development purposes.

Other easy way is to put the ".aar" files in "libs" or any other newly created folder of your choice and refer it from build.gradle like this:

repositories {
    flatDir {
        dirs 'libs'    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile (name:'yourAwesomeAndroidLibraryName', ext:'aar')
}

VideoView vs MediaPlayer vs YouTube player API

I was looking into streaming videos in one of my app.

VideoView is nothing but a wrapper around MediaPlayer. VideoView adds control buttons around MediaPlayer. If you want to do more customization, the MediaPlayer is way to go. VideoView is a quicker way to get started with streaming videos. VideoView and MediaPlayer needs a video url or path ending with mp4, mp3 etc extensions. They can't play videos from Youtube Urls (at least when I tried playing them the way I did for videos with mp4 extension)

YouTube API is useful when you want to play videos based on YouTube urls.  You can embed a Youtube video in your app. But this could be little tricky when positioning it in your app. Also, it comes with API calls quota limits. There is only a certain amount of calls can be made for free by your app, and have to pay going forward.

Conclusion: Its better to use VideoView for offline videos which don't have piracy issues associated with them. I would NOT recommend downloading Youtube videos and bundling with your apps.

Online tool to generate mocked HTTP responses

Mocky is a wonderful tool to generate mocked HTTP Response on the fly. You don't have to spin a full server just to generate that very first mocked data. Its very helpful for client end development to quickly test the different data formats.

2015 Android Latest features


  1. Android Lollipop 5.0
  2. Gradle
  3. Android Studio
  4. NFC
  5. Android Wear
  6. ViewGroup, WebView, TextView, RecyclerView
  7. Material Design
  8. Memory Management
  9. Battery Consumption
  10. Android Runtime (ART)
  11. Concurrency and Android Thread Communications
  12. Animation
  13. Android Security
  14. Testing and Debugging (Tools)
  15. Enterprise Android Apps
  16. Bluetooth LE
  17. Android TV
  18. Automative Android
  19. Push Messaging
  20. Notifications
  21. Camera 2 APIs
  22. High-Performance Android Apps
  23. HTML Hybrid Apps
  24. Android Emulator
  25. Deep Linking
  26. Google Cast
  27. Retrofit
  28. App Indexing
  29. Location Services for Android
  30. App Search Optimization
  31. Project Ara
  32. Host Card Emulation (HCE)
  33. Cloud-Powered Android Apps
  34. Brillo 
  35. Weave

Android Networking library

I found a very nice article about using Android networking library Volley along with OkHttp and Gson here.

OkHttp deals with connection pooling, caching and gzipping etc, while Volley is a networking library manages network requests in an app and makes sure that networking calls are executed in background most efficiently.

Sample source code is on Github.

RecyclerView Animations !

I've come across this wonderful post about what RecyclerView widget is and how it works. A must read for someone who is looking for to add more flexibility which are not easy to implement in ListView widgets.

Scheduling Repeating Local Notifications using Alarm Manager

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