Category Archives: General

This section have articles on general topics on IT and other IT related events and stuffs.

Pokemon Go – Start of the Next Generation Gaming

Within past 2 weeks you may have somehow came across a name, topic, Game saying ‘PokemonGo’. It is Niantic’s first ever client Project. If you have no Idea on who is Niantic, its a company that has spun out of Google in October 2015, and they are already popular among many for creating Ingress a real world map based augmented reality game.

If you are already into PokemoGo, you may have already come across some people who were trying to say, PokemonGo players must thank the Ingress Community, but no one ever care about that guy.

13710455_10207066020269213_5072986070562172765_o

The truth is Niantic made Ingress as their Portfolio Game to prove the world and the Gaming community that the Next Generation Gaming should be close to reality. So made this Game Niantic, the time they created the Game they have no data on Portals/PokeStops(in PokemonGo), then they tried to find some individuals in each country and encouraged them to play the game and submit Portals. This may look easy but if you are an Ingress Player Playing it for 3 years, you may see it as how tiresome and how much distance people have walked to make it to the number it has now. We can also say that Niantic has tricked the People in collecting data for them to use for it’s own other Products like PokemonGo in future.

Ok so this Game PokemonGo makes people stand up go out side and play?  Yes it does, you cant stay inside your house and expect a Pokemon to come in, You have to go near lakes sea to catch water Pokemon near mountains and rocky areas to catch Rock Pokemon, you some times have to chase after rare Pokemon that goes in front of your eyes. People who are fans of Pokemon Cartoons and Console Games know how exciting is to really go out and catch your Own Pikachu, the Pokemon’s Idol. But some people say how convincing is this game or is there a future to games like this.

Yes you may remember once upon a time there came a game called Farm Villa, first of it’s type game. No if you open the App Store it is filled thousands of Similar Game. In Farm Villa it only uses real time and people are really excited to see their plants grow in certain hours. But here it is real time, environment, people will really get excited, but again people always gets bored. So for now Pokemon Go will still arise high despite it’s battery draining issues and bugs. Its already so popular and not launched in Asia yet, when they launch it world wide its going to be Crazy.

In the economical ankle, PokemonGo has send up the stock prices of Nintendo by a a Great leap. Can get more info on that news at Forbes

20160718_Pokemon_Effect_Forbes-1

Based on the current popularity and the regular server downs. You can have an idea on how many people are playing this game at the Moment.  Niantic has also revealed the plan to use Pokestops as a paid Ad spot so that the Business’s can have a great visibility. So it also going to work as the next Generation marketing tool.  You can check out the following Graph on how it is penetrating in to the user base

Pokémon-Go-Likely-to-Overtake-Google-Maps-Snapchat

Some people worry about incidents like accidents and kidnaps that involves Pokemon. Yes its true and it’s a Dangerous fact. But the world is growing fast technology is advancing we cannot stick to the same old thing. People have to learn to adopt to this new behavior. And some people are trying to force in the fact that this is stupid. But if you can think a bit into the future, your kids or their kids are going to live in more advanced era than us, so its a fact that they will play these kinds of Games, they may get into the same trouble. So without staying a step behind from technologies like Real World Gaming, why don’t you try it at least to understand the idea behind it, how it works and  the possible problems that can arise. So that you can be prepared for any trouble when it happens.

The world is changing fast, you wanted a Augmented reality world like you see in Iron man, here it is, its there now in front of your eyes, don’t stay away from it. Get into it and learn to adopt it. And be happy for the fact that your children in future will not always be glued to the Console Games and PC like they did till 2 weeks before.

Advertisements

New Permission Model in Android

Hi Folks, today we will be seeing the new permission model in action and how to handle it. You know that we define the system permissions that we need to run the app like Camera and “READ_EXTERNAL_STORAGE” and “WRITE_EXTERNAL_STORAGE” permissions in the manifest file. But this is not enough for the from the API level 23 , Android 6.0, the new model is introduced that is getting the permission from the user on the run time.

So we will see how we can do it. For this I am using the latest Build Tools 23.0.2
And the Compiled SDK Version is API 23

Always make sure you are using the latest build tools as Google always improve the backward compatibility through it.

Ok the the first thing you have to understand is, we will be checking this permission availability exactly before the place where we access the permission related operation. Adding this code will have no special effect on the phones that are running versions less than Android 6.0

And we have to add the regular permission as usual in the Manifest too. Else again the app will crash.

We will be doing a sample on getting a screen shot and saving it to the SD Card so here we need the “WRITE_EXTERNAL_STORAGE” permission

Step 1
At the place where we have to invoke the screenshot function we check if the permission is already available. If the permission is already available we proceed with the taking screen shot, else we call another methods which will invoke the  new permission request procedure.

if(PackageManager.PERMISSION_GRANTED== ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)){
    shareScreenShot();
}else{
    requestWritePermission(MainActivity.this);
}

Step 2
the method requestWritePermission(context) will check if the permission is already requested and if already requested and rejected it shows another Custom Dialog which explains why the permission is needed and when the Allow button is click it shows the Permission request again. Meanwhile if this is the first time the request permission procedure will automatically fired.
While we invoke the ‘ActivityCompat.requestPermissions’ method we pass a request code, in our case it is “REQUEST_WRITE_EXTERNAL_STORAGE” so that we can track back the result on the onRequestPermissionResult() override method and respond to it appropriately.

private static void requestWritePermission(final Context context){
    if(ActivityCompat.shouldShowRequestPermissionRationale((Activity)context,Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        new AlertDialog.Builder(context)
                .setMessage("This app needs permission to write data to the phone so that the Screenshot can be saved")
                .setPositiveButton("Allow", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},REQUEST_WRITE_EXTERNAL_STORAGE);
                    }
                }).show();

    }else {
        ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_EXTERNAL_STORAGE);
    }
}

Step 3
In the onRequestPermissionResult() we catch the reult from the permission dialog and decide whether to go for the screenshot procedure or not

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    switch (requestCode) {

        case REQUEST_WRITE_EXTERNAL_STORAGE: {
            if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                shareScreenShot();
            } else {
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
            }
            return;
        }
    }
}

So here is the order in it work, these are taken from one of my other app, and its done for reading from the SD card
step1    Step 2   Step 3

So that’s it guys hope you guys understood and will implement in your own application
Sample app can be found at the GitHub gitHub-download-button

You can get more info from the official documentation here :  http://developer.android.com/training/permissions/requesting.html

Will Write our Own App to Trigger Mi Band

10371404_10206191040355262_3352352559338119016_n
Xiaomi Mi Band is the world’s cheapest and branded fitness tracker. So why don’t we do some experiments so that we can make the Mi Band do what we say for a change?

I’ll be doing this code session for Android using Android Studio, hope others can understand the basics

Step 1
Firs of all we start a new empty project. And add 4 buttons. This is to test 4 basic functions of the Mi Band. Then initialize the buttons and ready the the setOnclick listners.

Step 2
Add Bluetooth Permissions in the Manifestfile, else you wont be able to connect to the band 😀

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /

Step 3
Add the Xiaomi Mi Band dependencyto the gradle and sync it

compile 'com.zhaoxiaodan.miband:miband-sdk:1.1.2'

Step 4

In the oncreate you have to create and initialize an instance of the MiBand Class

private MiBand miband;
miband = new MiBand(this);

Step 5

I have not done the pairing part in the code, but I assume the Mi band of yours is already paired to the device. If you have paired more than one device you can populate all the paired devices and allow the user to select one. But for the demonstration purpose I have only paired with my Mi Band so it is the one and only device returns to me

Object[] devices = BluetoothAdapter.getDefaultAdapter().getBondedDevices().toArray();
final BluetoothDevice device = (BluetoothDevice) devices[0];

So I am getting my paired device from the available devices, as I only got my Mi band paired I get the 0th device. hope you people got that part 😀

Step 6
No you have to connect to the paired device

miband.connect(device, new ActionCallback() {
    @Override
    public void onSuccess(Object data) {
        pd.dismiss();
        Log.d(TAG, "Success !!!");
        miband.setDisconnectedListener(new NotifyListener() {
            @Override
            public void onNotify(byte[] data) {
                Log.d(TAG, "Disconnected!!!");
            }
        });
    }
    @Override
    public void onFail(int errorCode, String msg) {
        pd.dismiss();
        Log.d(TAG, "connect fail, code:" + errorCode + ",mgs:" + msg);
    }
});

Step 7

So if you have successfully connected to the device. You can start invoking functions of the MiBand in the button clicks
For example : You can make it Vibrate using this code snippet

miband.startVibration(VibrationMode.VIBRATION_WITH_LED);

You can check out some more commands in the sample code available in Git HubgitHub-download-button

A Myth comes true with Google Cloud Vision API

Cloud Vision API by Google Cloud is the latest addition for the Google Cloud platform. Last week it has been made a beta release and been allowed for the developers around the world to try and experience it. 2 month of free usage is offered by the Google at the moment as a promotion.

This API is already being used in the Google Photo app. You may have already experienced it’s power. Analyzing objects in a photo, face detection, geographical location detection and fast search are some of their features.

Features

So I was able to register for it lat week and was already able to build an app. But as it was still in the beta. Faced some problem(Can be found with solution in Stack overflow) on creating the API key for Android. But was able to find a quick fix as many people are facing the issue.

But when I was going through the API and I found many awesome feature that just a myth till today. Still there is no proper documentation but you can find some of the popular features and getting started docs listed here.

Here are the High Lighted APIs listed down
vision

You can also try Google Cloud Vision API here

Pricing is also seems reasonable compared to the amount of processing that they have promised to do. It will be a big break through in the history of the image processing technology.

You can check out the Android app I have developed using the ‘FACE_DETECTION’ API, if you love selfie you will Love it. Download the Selfie Mood app here
selfie mood

Application of Locke’s Goal Setting Theory in Agile Methodology

A theory I came across recently looked to adhere to some concepts of the Agile methodology. And I felt it seems to fill some kind of a black hole in the Agile methodology. The theory is called be Locke’s Goal Setting Theory.

Locke’s Goal setting theory is about setting up goals in a way, that when they are achieved they will also turn into a great motivator to the person/team who follows it accordingly.

In my working place we follow Agile methodology to develop software. I know some of the basic Agile process. So the basic concept of Agile according to my understanding is a recursive process of software development which goes under many changes and iterations to provide what the clients really wants. Also the process is transparent to the client so the client is always updated. This methodology is developed to create a better understanding between the client and the developers so that they will come up with the exact product that the client wants, including the changes through up to the final product release.

When you try to compare the 5 key factors of the Locke’s Goal Setting Theory with Agile process, you will see that some are very much similar to each other.

Will see how much are they related to each other

Setting Goals and trying to achieving them, does not always works well for everyone. Some people achieve it and some people get stressed out or stuck and instead of getting motivated they get demotivated due to many reasons. In Agile we can consider it to the user stories created by clients , which we add into sprints as tasks and try to implement them withing that sprint time.

The 5 Factors that are need to affect the motivations according to Locke’s Goal setting theory are

Clear and Specific Goals

Challenging Goals

Handling Complex Problems

Commitment

Feedback

1 – The Goal has to be clear and specific, so in Agile we meet the client and their work environment and understand it and then we gather user stories which are then explained by the client to the developing team. This ensure that the requirement we have gathered are clear and specific.

2 – The next one is Challenge, we create sprints with user stories provided by the client, which we think we can achieve within the next sprint and we define our self a deadline. Easy challenges won’t be motivating, because they won’t feel important. So we select a set of challenging stories to achieve within the sprint. Achieving them gives us(developers) a big motivation.

3 – Handling complex problems, often there is chances of estimations made by the developers go wrong. So some times developers tend to get stuck on a problem that blocks the whole process, which leads to stress and the developers get demotivated. At times like this in Agile we split the complex task in to many sub tasks to visualize the problem in a better way so that we can handle them individually and solve them.

4 – Commitment is next, it is really important when it comes to team, we have to work together to achieve the goals. Software modules normally will be developed by different developers, which will at the end works together to provide a solution. So being committed to the goals that’s assigned to you will pave way to the ultimate team goal. Commitment is also affected by various kinds of internal and external causes. But keeping the developers committed is something that has to be handled by  the management or the team lead.

5 – Feedback is an important element. As a team lead, it’s important to give feed backs on the goals achieved by the team members and in which area they can improve. Not only the Team Lead, the client must be also trained in a way so that they give positive feedback about  the developers when they are present in a meeting or a scrum. This will enable the team members to work more efficiently and happily in future. Developers often consider positive feedback as another hidden goal. So it is the responsibility of the leads not to spoil it for the developers.

Even though the companies following Agile methodology these days does motivate the employees/developers by giving the team a lunch out or a pay increase/bonus. The motivation part is not mentioned theoretically any where. So I think if we can apply the Locke’s Goal setting theory into the Agile, we can get a better performance from the developer team with Good customer satisfaction.

My Experience with Xamarin Android

Hi folks, I have been working on Xamarin Android for the last 6 months. I normally don’t go for a third party development tools to make Android or iOS apps(I am not talking about Xamarin Mono but Xamarin Android). But the project requirement was to develop in Xamarin. The reason client said was that we can have the service layer for both Android and iOS as same. Ok that’s cool most of the service calls are handled by the service layer which is developed by our back end developer.

Some people had this mind set when it comes to Xamarin, where they compare it with other hybrid platforms like Phonegap. But the reality is Xamarin is a framework designed specially for the people who knows C#, so that they can write the Android code in C# and not have to worry about Java.  And the out put is not a web based solution, it is a native app that Xamarin out puts so it is faster like all native apps. Many C# developer I know have tried to develop apps using Xamarin and ended up complaining that, ‘Hey man its the same android code that we have to write but in C# so whats the point in it’ . So here what I am trying to say is, even though it looks or give a comfortable feel, for the C# people when they start developing they will come to understand that they need at least some basic knowledge on Android.

I tried to give an overview of what people think and what I think of Xamarin. Lets see how it feels when you try to develop and publish and app. So for C# developer its good if they knew some basic Android. Else you can still follow the Xamarin tutorials and figure out things. For Android developers if they have some basic knowledge on C# language it would be enough.

When you create an android project. It creates the file structure exactly like in Eclipse or Android Studio giving you a good first impression. Then you can add Activities and Layouts as usual. Here the layout xmls come with the extension axml. The xml we create as resources are normal xmls. When you start developing you will start to see the differences.
For examples the edit text component has a method called setText

editText.setText("String to Show")

but in Xamarin android, its not a method but a property in that class, so you simply set the value like

editText.Text =  "String to Show";

These kind of changes, you will see a lot. And when it comes to libraries. You have to Go for the Xamarin Components. Where there is only a handful of components to choose from. Most of the very popular ones are being added by the Xamarin people and popular companies. But still, at some times you have to create a component project by looking into a java library project available for normal android. But you have lots of other NuGets to use  for other simple things you find hard to handle in Android.

And one of the important think on updates are, that Google go on updating it’s v4, v7  libraries and Xamarin is slow on updating their system to support it. So When you are using libraries or components, you have to have a good knowledge on the component and their dependencies to manage all of the features you want from them. So in some cases you have to use old versions of components.

I have no problems in building and running a debug apk, but when I had to release a release build I had to face a lot of problems. One of them is the problem with the dependency versions which I have explained above. On one occasion I have to remove all the Google Play Services components and have to find an alternative way to handle Google play services which I manages to do with some http get/post requests.

So what I will always recommend is, if you are an Android developer unless it is a must don’t go for the Xamarin. Else if you are a C# developer, you will get used to the Xamarin and hopefully Microsoft will acquire it and will make it more wonderful in future.

How to Generate a PDF in Xamarin Android

It may sound simple, but when it comes to Xamarin, all the problems starts to emerge. So basically Xamarin does not provide any special class for PDF generation.

Failed Solution 1
So we were let alone to use the Android PDFDocument class. Which Unlike in the Native Android did not work. Actually it was giving me a White and blank document. When searching for the Xamarin Documentation what I found was the Xamarin documentation having the Android Reference Code which is very disappointing (Link to Documentation)

Here is the Code snippet for it(I may have made a mistake here, let me know if you guys found a solution for using PDFDocument class )

private String sdCardPathforPDF;
private String filePath;
private FileStream stream;

sdCardPathforPDF = Environment.ExternalStorageDirectory.AbsolutePath;
filePath = Path.Combine(sdCardPathforPDF, "MyPDF/test5.pdf");
stream = new FileStream(filePath, FileMode.Create);

tView = new TextView(context);
tView.SetTextColor(Color.ParseColor(resource.GetString(Resource.Color.black)));
tView.Text = "Hello";
tView.SetHeight(50);
tView.SetWidth(50);

var document = new PdfDocument();
var pageInfo = new PdfDocument.PageInfo.Builder(612, 792, 1).Create();

var page = document.StartPage(pageInfo);
tView.Draw(page.Canvas);
document.FinishPage(page);

document.WriteTo(stream);

stream.Close();
document.Close();

Toast.MakeText(context, "PDF Generated", ToastLength.Short).Show();

Failed Solution 2
Then I searched for a plugin or a 3rd party library, ohhh my god, I found some expensive plugins

Capture

Who would love to buy a plugin for 1600 usd??? Apitron and XFINIUM are some of them

Failed Solution 3
I found some Free open source libraries for Android, so I thought of  Java Bind it, but when i tried to Java Bind them, but I ended up getting lots of errors that i cannot fix it unless I am the developer of that library. So I dropped that Idea as well.

Failed Solution 4
Then after the disappointment of JavaBind, I came across an article saying that the iText library has been published for .Net in the name of iTextSharp. But when I added that Nuget Package I came across an error saying that

System.IO.FileNotFoundException: Could not load assembly 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?

so It says there is an assembly called System.Drawing dll is missing. I tried to manually add it but it did not work. When I researched on it, it said that Mono for Android(Xamarin Android Framework) does not include that ‘dll’ I dont know how come a popular ‘dll’ got missed out of their framework.

At last a solution that Worked
So with all of the frustration I had, I did not give up on finding a solution till i came across problem where a guy has used ‘iTextSharp’ in Xamarin Android and its working. But he did not mention or reply my question in that thread. So I thought of giving a final look at the Nuget Manager. This time just like the previous time I searched for ‘iTextSharp’ but this time I went through each and every result the list showed.
And Hoooray I found It the one I am searching for, some one has made a nuget of ‘iTextSharp’ for Xamarin, its called “Xam.iTextSharpLGPL”

XamiTextSharp

And this worked like a Magic. And this library has more functionality than the default PDFDocument.
This library is based on iTextSharp 4.1.6  which means licensed under LGPL. Free to use and it is an Open source library.
Open source project can be found in Bit Bucket : https://bitbucket.org/smarongiu/xam.itextsharplgpl

So this is the Basic code of Writing a Simple PDF Doc

System.IO.FileStream fs = new FileStream(Server.MapPath("pdf") + "\\" + "First PDF document.pdf", FileMode.Create)

// Create an instance of the document class which represents the PDF document itself.
Document document = new Document(PageSize.A4, 25, 25, 30, 30);
// Create an instance to the PDF file by creating an instance of the PDF Writer class, using the document and the filestrem in the constructor.

PdfWriter writer = PdfWriter.GetInstance(document, fs);

Before we can write to the document, we need to open it.

// Open the document to enable you to write to the document

document.Open();

// Add a simple and well known phrase to the document in a flow layout manner

document.Add(new Paragraph("Hello World!"));

// Close the document

document.Close();
// Close the writer instance

writer.Close();
// Always close open file handles explicitly
fs.Close();

I grabbed this quick code snippet from Micke Blomquist

Hope this article will help people like me in future…!
See ya…!