Android N7.1 Dev beta is OUT

Hi Guys,

As you were eagerly waiting , Android 7.1 Dev beta version is available for download.You wont get updates automatically from system updates. To get it, you need to enrolled your device for the beta version…its simple to enrol.

  • Go to Google Android beta link. g.co/androidbeta or www.android.com/beta 
  • It will prompt to login to your google account. On successful login, browser will detect for the device model and you can see a Enroll button.
  • Just click it and accept T&C.
  • Go to Systems > About > Software updates….
  • you will be welcomed with Android beta update release…
  • Update size is 1260 MB !!!

Voilla!!… Enjoy and cross check your App using Android 7.1 N

About

Hello World! That’s how I ventured into programming. I still remember my first C program done in my college computer lab and a big bright smile on my face. Never a whiz kid or want to be. Nev…

Source: About

Parcelable Vs Serializable

In Android  as you are aware, we cannot just pass object to activities. Object must be implement either serializable or parcelable Interface for passing objects to activites.

Serializable:

  • Java standard interface
  • Easy to implement
  • uses lot of temporary variable and its uses quite lot of garbage collection.

Parcelable:

  • Android specific. It turns out that the Android team came to the conclusion that the serialization in Java is far too slow to satisfy Android’s interprocess-communication requirements. So the team built the Parcelable solution. The Parcelable approach requires that you explicitly serialize the members of your class, but in the end, you get a much faster serialization of your object.
  • do need to add some custom implementation. so some might feel its hard to implement. We will talk about it later.

I have come across a good article which talks in detail about the parcelable Vs Serializable.

Refer the link: http://www.developerphil.com/parcelable-vs-serializable/

reg the topic of parcelable hard to implement, you can very well use Android parcelable code generator plugin to make your life easy. refer the screenshot below.

 

Happy coding 🙂

Reading fingerprint information from APK

Hi guys,

I came across a Deep link Implementation and to support it from server it need to provide assestlinks.json file info with SHA256 fingerprint information. For someone new, getting this information can be pretty tricky. So I identified two ways of getting the info.

From Android Studio:

Step 1: Refer screenshot. Open the Gradle Project menu

Screen Shot 2016-06-17 at 10.49.38 am

Step 2: Refer screenshot. open the project tree and click for signingReport. Android studio will provide you the Certificate information.

Screen Shot 2016-06-17 at 10.53.14 am

Sample Data:

Variant: DebugAPK
Config: debug
Store: /Android/scripts/deployment/sample.keystore
Alias: mydebug-app
MD5: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
SHA1: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
Valid until: Friday, December 11, 2041

Or

Pack all the apk in a folder and run the below command. ( My preferred one)

find . -name “*.apk” -exec echo “APK: {}” \; -exec sh -c ‘keytool -printcert -jarfile “{}”‘ \;

Sample output:

Certificate fingerprints:
MD5: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
SHA1: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
SHA256: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
Signature algorithm name: SHA256withRSA
Version: 3

Android – javascript Bridge/Interface

Hey friends, Recently come across a requirement for communicating from the Web back to the app. Normally, if app will look for loading URL using shouldOverrideUrlLoading(). so app will perform certain operation specific to the url for example setting a title for particular url loaded in web content. But if the web decides which title string to be shown, then app has to listen to web using javascript interface or simply called as JSbridge.

To create a webview in your activity you need to add the webView widget to the layout.

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

To load a web page in the WebView, use loadUrl(). For example:

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");

Note: Ensure you have added the internet permission in your androidManifest file.

To make the javascript enabled for the webview, enable the JS setting as true.

webSettings.setJavaScriptEnabled(true);

Binding JavaScript code to Android code

To bind a new interface between your JavaScript and Android code, call addJavascriptInterface(), passing it a class instance to bind to your JavaScript and an interface name that your JavaScript can call to access the class.

For example, you can include the following class in your Android application:

public class WebAppInterface {
    Context mContext;

    /** Instantiate the interface and set the context */
    WebAppInterface(Context c) {
        mContext = c;
    }

    /** Show a toast from the web page */
    @JavascriptInterface
    public void showToast(String title) {
        Toast.makeText(mContext, title, Toast.LENGTH_SHORT).show();
    }
}

Caution: If you’ve set your targetSdkVersion to 17 or higher, you must add the @JavascriptInterface annotation to any method that you want available to your JavaScript (the method must also be public). If you do not provide the annotation, the method is not accessible by your web page when running on Android 4.2 or higher.

You can bind this class to the JavaScript that runs in your WebView with addJavascriptInterface() and name the interface Android. For example:

WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");

On the Web side, Android Interface showToast is visible and all you need to call the function in the script tag.

<input type="button" value="Say hello" 
onClick="showAndroidToast('Hello Android!')" />

 type="text/javascript">
    function showAndroidTitle(title) {
        Android.showToast(title);
    }


IMPORTANT: only primitive data types are supported to passed 
across the JS and android app. if you try passing say for example 
JSONObject or Object, it will be null as these datatypes are not 
supported.

But workaround can be achieved by passing all the jsoninfo as strings 
and the app has to parse it to JSONObject.

JsonObject jsonObject = (JsonObject) jsonParser.parse(jsonstring);

All good. App will show the Title string info to be passed. Happy coding 🙂

Roboguice – Best dependancy Injection framework

Instead of creating dependancies on your own, use the third party or framework to do your job.

DI is used to move the responsibility of creating an object outside the main code and  give you back the reference to be used in your code. So very less from your end and DI has to handle it. So how to achieve this in android. we have lot of third party frameworks such as ButterKnife, Dagger 2, Android Annotations, Roboguice. These are popular DI framework libs used by most android developers. I have used Roboguide 3.0 for my project and quite appreciate the use of Roboguice DI framework.

Basically, Ideas being the DI is to avoid your class create objects on its own. instead get the object passed so you avoid tight coupling of your app.

Screen Shot 2016-05-12 at 2.15.16 pm

Voila!!…no need to do findViewByID everytime to load the widget. your code looks clean and neat.

for more info, refer Roboguice Wiki

Happy Coding 🙂

Android studio 2.0 – Instant Run

HI Guys,

Today I have updated my Android studio from 1.5 to 2.0. No surprising issues. everything seems fine. 2.0 seems matured and I love the Instant Run feature. its Cool feature and saves time in your build and deploy. I have tested against simulator and actual device, its pretty fast. It retains the activity and deploys the changes instantly.

Refer Google Link Android Studio Link for more information.

I loved it. Hope you too like it. Happy coding 🙂

Copying Textview text into Clipboard

Hey guys, sometimes you may want to have your textview content to be copied to your clipboard. Don’t ask me why you wanted this feature…but I can show the code snippet which you can use it. Best is to create a utils class and add this code, so that its shared across your project. refer the screenshot. Happy coding 🙂

Screen Shot 2016-05-12 at 2.26.04 pm