Saturday, 20 February 2016

Unity | Unity Read SMS Plugin | Unity Pluging : Read all incoming sms

Hello Friends,
              I read a lot that people facing problem in register and un-register the incoming
sms broadcast from Unity. Also reading incoming sms in Unity app .


              So, today I am going to share my first blog on Unity. This post helps you
to read all android incoming sms in your unity app.  Also you can easily register
and un-register the broadcast base on need.

In this tutorial I am going provide you a Unity Plugin(i.e:smsreader.jar) which
communicate b/w your unity app and android native callbacks. Below are the
steps to use it in your unity app :

1. Note: The package name which you have to use to access the plugin method is

    Permission:  Add below permission inside your unity app manifest.xml file.
         <uses-permission android:name="android.permission.RECEIVE_SMS"/>
         <uses-permission android:name="android.permission.READ_SMS" />

2.  The plugin contains to static method which will be call from unity app :
          A. registerBroadcastReceiver() :  When your unity app launch we first need to
              call this method for registering the broadcast receiver. Below is code snapshot.
              These two methods and class are there in plugin we just need to add that
               plugin as a jar and call it.
  * This method register the Broadcast receiver
  * @param view
 public static void registerBroadcastReceiver() {
    if (broadCastReceiver == null) {
  broadCastReceiver = new IncomingSms();
  new IntentFilter("android.provider.Telephony.SMS_RECEIVED"));

          B. unregisterBroadcastReceiver() : Whenever you want to stop reading incoming
               sms call this method or when your unity app goes in background.
  * This method un-register the Broadcast receiver
  * @param view
 public static void unregisterBroadcastReceiver() {

  if (broadCastReceiver != null) {
   broadCastReceiver = null;

package com.affle.smsreader;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.util.Log;

import com.unity3d.player.UnityPlayer;

public class IncomingSms extends BroadcastReceiver {

 final SmsManager sms = SmsManager.getDefault();

 public void onReceive(Context context, Intent intent) {

  // Retrieves a map of extended data from the intent.
  final Bundle bundle = intent.getExtras();

  try {

   if (bundle != null) {

    final Object[] pdusObj = (Object[]) bundle.get("pdus");

    for (int i = 0; i < pdusObj.length; i++) {

     SmsMessage currentMessage = SmsMessage
       .createFromPdu((byte[]) pdusObj[i]);
     String phoneNumber = currentMessage

     String message = currentMessage.getDisplayMessageBody();

     if (UnityPlayer.currentActivity != null) {
        "OnMessageReceived", "" + message);
    } // end for loop
   } // bundle is null

  } catch (Exception e) {
   Log.e("SmsReceiver", "Exception smsReceiver" + e);



Download the plugin from here : SmsReader.jar
Hope this will help some one.
Happy Coding ... :)

Wednesday, 17 February 2016

Android 3 Easy Steps to generate SHA1 and MD5 fingerprint| SHA-1 fingerprint of keystore certificate | Using Android Studio generate SHA-1 fingerprint

Hello Friends,
      Today, I am sharing few easy steps to generate SHA1 and MD5 fingerprint using
android studio.No need of terminal command, we can generate it in Android Studio
same as we did in Eclipse-->window---> preferences--->Android---->Build .

Here Are Steps with screen shot:

Easiest way :
  1. Open Android Studio
  2. Open Your Project
  3. Click on Gradle (From Right Side Panel, you will see Gradle Option)
  4. Click on Refresh (Click on Refresh from Gradle, you will see List Gradle scripts of your Project)
  5. Click on Your Project (Your Project Name form List (root))
  6. Click on Tasks
  7. Click on android
  8. Double Click on signingReport (You will get SHA1 and MD5 in Run Bar)

Screen 1.

Screen 2.

Screen 3.

All Done.

Hope this will help some one.
Enjoy Coding.....
Cheers :)


Copyright @ 2013 Android Developers Blog.