Android Multipicker Library

Android Multipicker Library
Android Multipicker Library

Similar to image-chooser-library, but has some new features. Re-written from scratch. Android Multipicker Library is an open-source project which has the following objectives.

Makes it easy and simple to integrate “Attach that file” feature into your android apps.
  • Don’t worry about various devices/OS variations.
  • Don’t worry about out-of-memory errors.
  • Don’t worry about creating thumbnails to show a preview.
  • Picking up any file for your app, and it’s details.
  • Picking up audio files.
Code less for capturing images/videos/files
  • Choose images from device or take a photo
  • Choose videos from device or record one
  • Choose files available on your device
  • Choose audio files available on your device
  • Choose a contact from the phonebook
  • Works with almost all content providers
  • Get all metadata about the media that you would probably need
  • Similar code base to implement irrespective of Android version of device.
Media types supported
  • Pick images.
  • Capture a still photo.
  • Pick videos.
  • Record a video.
  • Pick/Record an audio.
  • Pick files.
  • Pick a contact (Display name, phones and emails).
Post Processing
  • Generate metadata of file (Size, MimeType, Extension)
  • Generate metadata of images (Width, Height, Orientation + metadata of files)
  • Generate metadata of videos (Width, Height, Orientation, Duration + metadata of files)
  • Generate metadata of audios (Duration + metadata of files)
  • Generate thumbnails of images (Big and Small)
  • Generate preview image of a video and it’s thumbnails.
Other features
  • Multiple file/image/video selection.
  • Configurable storage location of all files.
  • Easy handling for incoming share intents.

The implementation code is more concise and meaningful. Do give it a try.

Why Android Multipicker Library?

A little bit of background:

Get it on Google Play
Multipicker Library Demo

Picking images/videos on Android is not that straight-forward. It might be easy if you want to pick media from a specific app or the phone’s gallery. But it becomes very tricky when you have to deal with all kinds of apps. ex. Dropbox, Google Drive, various File Manager applications, different types of camera applications and so on. Android Multipicker Library makes it super easy for you to deal with all these scenarios, with a single codebase. So that you don’t have to keep writing code to handle all these scenarios differently.

You can try out this sample app and see how it works. Let us know your feedback or suggestions.

Checkout the Wiki Pages on Github for code snippets.

File Upload from Webview on Android

You have a form on WebView, with input type as “file”, and want to allow the user to upload a file from his device. Prior to Lollipop, this was not very straightforward, and you had to resort to using private APIs, which has always been discouraged. But, you had to do it. With Lollipop, there’s a new public API, which still isn’t very straight-forward to use, but at-least, should be reliable and compatible with newer Android/WebView versions. So, how do you implement File Upload from WebView on Android with the new public API? 

This has been a long pending request, and people have implemented workarounds by using various versions of some private API’s for various older versions of Android.


Steps to Implement (3 steps)

  • Attach WebViewChromeClient, and override method callback for a click event on and input field of type file.
mWebView.setWebChromeClient(new WebChromeClient() {

        @Override
         public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,              FileChooserParams fileChooserParams) {
                 mFilePathCallback = filePathCallback;
                // Launch Intent for picking file
                return true;
         }
});
  • Launch Intent for picking the file
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);
  • Pass the Uri of the selected file to WebView
@Override
protected void onActivityResult(int requestCode, int resultCode,
     Intent intent) {
     if (requestCode == PICKFILE_REQUEST_CODE) {
          Uri result = intent == null || resultCode != RESULT_OK ? null
              : intent.getData();
          Uri[] resultsArray = new Uri[1];
          resultsArray[0] = result;
          mFilePathCallback.onReceiveValue(resultsArray);
     }
}

 

I have created a small sample project with all the required code to achieve a simple input field taking in an image. You can get the source on Github.

Script for compressing images with tinypng API

TinyPng is a nice service which provides you 500 free image compressions a month. And this is nice, since in a typical Android project, you wouldn’t have more than 500 images in any given month :). I have a simple script that scans through all your images, and tries to compress them using the tinypng api. All you need to do is to copy the script, put it in the root folder of your project and run it.

Head over to TinyPng website to checkout how it works.

What does TinyPNG do?

TinyPNG uses smart lossy compression techniques to reduce the file size of your PNG files. By selectively decreasing the number of colors in the image, fewer bytes are required to store the data. The effect is nearly invisible but it makes a very large difference in file size!

Advanced lossy compression for PNG images that preserves full alpha transparency.

Let’s jump into it. This script will search for all the images(pngs) in your Android project, pick each one, call the API, and overwrite the images, with a compressed version. And since this is a lossless compression, you won’t notice any change in quality. The overwriting part is probably a bit dangerous. So, with a little modification, you could change the script so that it creates a copy of the files.

The initial script for tinypng was taken from this gist by rakuishi. Thanks :).

Image Crush Savings Report
  1. The first thing you would need to do is to get an API key here.
  2. Copy this file to the root of your android folder.
  3. Replace your API key in this file on the top.
  4. Run “ruby imgcrush.rb”
  5. View the generated HTML report. (Link to sample report)

That’s it. For an example above, you could see, the script reduced the size to almost half for each image. And the total savings is somewhere about a whooping 53%.

Note: There are other image compression APIs/tools which I haven’t tried yet. Android build system itself has a pngcrusher which tries to optimize all your assets.

PIN Screen Library for Android

Here’s a simple and easy implementation for adding PIN lock support for your Android apps. The library can be themed with your app theme colors. It has smooth animations and vibrate cues when something’s wrong.

 

To use this, you just have to write about 10 lines of code, including layouts and everything. It’s so simple.

Steps to implement

  • Add as dependency

Maven:

<dependency>
<groupId>com.kbeanie</groupId>
<artifactId>pinscreenlibrary</artifactId>
<version>1.0.0</version>
</dependency>

Android Studio:

compile ‘com.kbeanie:pinscreenlibrary:1.0.0@aar’ 

  • Add PinView to your layout file.

<com.kbeanie.pinscreenlibrary.views.PinView
android:id=”@+id/pinView”
android:layout_width=”match_parent”
android:layout_height=”wrap_content” />

  • Initialize PinView in two modes

pinView.setModeSetup(PinEntrySetupListener);
pinView.setModeAuthenticate(PinEntryAuthenticationListener)

And finally, handle the callbacks for all events. The complete source code for this project can be found on Github. Let me know if you have any queries or issues. I would be happy to resolve them.

New Sensors in Android 5.0 (Lollipop)

I found a few non-documented sensors on Lollipop (Android 5.0) on a Nexus 5.

Tried looking for them, but could’t find any documentation on them on. Looks like they are mostly software sensors.

Android app on Google PlayHere’s the list that I have found. I have written a simple app that displays all the sensors and shows there values. Not to mention that, only for the ones that are documented. For the ones not documented, you can only see it’s details.

There are only a few which appear on developer.android.com.
Here’s an excerpt from the announcement.

New types of sensors

In Android 5.0, a new tilt detector sensor helps improve activity recognition on supported devices, and a heart rate sensor reports the heart rate of the person touching the device.
New interaction composite sensors are now available to detect special interactions such as a wake up gesture, a pick upgesture, and a glance gesture.

Since there’s no documentation, for some of them, I don’t really know what they do. The only thing that gives you a clue is the sensor name. And, I don’t know how to work with them as well.

Tilt Detector

AMD Sensor (No idea, whats that)

RMD Sensor (No idea, whats that)

Basic Gestures Sensor

Tap Sensor

Facing Sensor

Tilt Sensor

Pedometer

Pedestrian Activity Monitor

Update: Seems, the documentation is coming soon. XDA picked this up.