Gaurav Chandra Gaurav Chandra   June 15, 2016

Create persistent notification on Android using NativeScript

I was experimenting with some background tasks in nativescript for android and I found that one way to ensure that your android app will always run even when it is in background is to use a persistent notification. So, I was able to create this using the following code:

NativeScript Code:

main.js

var APP = require('application');
var utils = require("utils/utils");
var application = APP.android;

exports.navigatingTo =  function (args) {
    var page = args.object;

    var randomCode = new java.util.Random().nextInt();//to be used later to associate the 2 things
        var intent = new android.content.Intent(application.foregroundActivity, com.tns.NativeScriptActivity.class);
    var pendingIntent = android.app.PendingIntent.getActivity(application.foregroundActivity, randomCode, intent, android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK);
    var builder = new android.app.Notification.Builder(application.foregroundActivity);
    builder.setDefaults(0);
    builder.setContentTitle("NativeScript Running");
    builder.setContentText("This notification cannot be cleared");
    builder.setContentIntent(pendingIntent);
    builder.setTicker("Persistent Notification");
    builder.setSmallIcon(application.nativeApp.getApplicationInfo().icon);
    builder.setPriority(android.app.Notification.PRIORITY_HIGH);
    builder.setOngoing(true);//this tells the OS that the notification is persistant
    var notification = builder.build();
    var notificationManger = utils.ad.getApplicationContext().getSystemService(android.content.Context.NOTIFICATION_SERVICE);
    notificationManger.notify(randomCode, notification);
};

and voila, you have persistant notification. Ofcourse this can be better managed but now you know how to create a persistent notification. Enjoy.

Gaurav Chandra Gaurav Chandra   June 1, 2016

Why I hate developing for iOS?

[UPDATE:] Since writing of this post, my subequent app update was approved within 24 hours by apple!

I am a mobile app developer and since I code for both iOS and Android, I have figured that Android wins every single time as far as appstore availablility is concerned.

Recently a small bug went into the iOS phonegap app I made. The bug was in one of the plugins which has not been updated for a long time and it is the only plugin available which does the work. It was crashing the iOS app when used but Android was absolutely fine.

I released the app with the bug and now my client is after my life as he has to start with the marketing of the app. And he wants to market android and ios both. So, he is calling me everyday to know about the status and everyday I say, "It is waiting for review". The app is in waiting for review since last 3 days and there is no way I can even request apple to expedite it without putting in a formal request, which I don't want to do as the slots are limited.

Now, why the hell does it take so much time, apple? Why is it that your OS is so advanced but you have to manually review the apps? Why oh why? Why can't you spend some parts of your $169 billion cash on AI and Automation?

This is the exact reason I have moved to native android development and not native ios development as apple as a company is snooty and don't give a damn for their developers even after they charge $99 for development every year.

Just by making speeches, the developer community will not be appeased. Act on those commitments.

Gaurav Chandra Gaurav Chandra   March 25, 2016

Freelancers are their own worst enemy

Recently I had a telephonic chat with a prospect and he was a non technical guy who does not know anything as to how a mobile application or a web application works or gets developed. He told me that he wants to meet but will not share anything much about the idea as he is fearful I might steal it. I was perplexed and kind of offended but then he told me his reason:

He had 2 ideas stolen by 2 different freelancers and 1 freelancer never got back

I was zapped. What? And even after he had got an NDA signed by them? Yes, even after an NDA.

So, what happened.

  1. Freelancer 1 met him and got the full gist of the idea. He said no to the prospective client as it was not possible, the reason he gave. My prospective client got to know after 6 months that the an app in the app store is available which does exactly the same thing which he thought of and after some detective work, he got to know that Freelancer 1 is behind that.
  2. Freelancer 2 met, discussed but said that it is not possible as there are many government permissions needed to build that app and what not. My prospect finds that after 1 year there is a same service in the market which he thought of.
  3. Freelancer 3 met, discussed and never got back. He continued to follow up or call Freelancer 3 but he never picked the prospective cliet's call or reply to emails.

This is bad. This experince burnt his fingers and he swears he will never ever share the ideas with anyone till he is convinced that the person is genuinly not out to steal his idea.

I told him that I need to know something to suggest him what needs to be done but he remained skeptical. I have decided to meet him and lets see what comes out of that meeting.

But to make something clear about my self:

I have not and never will share your idea with someone else or steal your idea from you as I am not that person. I don't plan short term, I plan long term. I am not greedy like that person who would kill a golden goose. I want my clients to trust me and keep coming back to me for long time.

But the point is no matter how much I say that I am a good person or I won't do anything bad to my client or prospect, I do get weighed on the same balance. I do get bad looks as I am a freelancer and other freelancers have tainted this term with their bad reputation.

Freelancers, please stop it. Have some work ethic. Give good returns to your clients. Don't break their trust. Give good returns to even the prospective clients so that they come back to you to get more work done.

Gaurav Chandra Gaurav Chandra   March 11, 2016

Health Bank: It is in Google Play Store

Hooray! My another app is in app store. Health Bank. Go grab it here: https://play.google.com/store/apps/details?id=com.healthbank.app

It is a report storage app where you can click and save your reports in your account and share it with other people or even your doctor. Then the shared report can have comments or tags or permission based views.

It is a very good app which will help lot of people, specially doctors and labs to manage the reports of their patients.

Gaurav Chandra Gaurav Chandra   March 4, 2016

Get IMEI number of device on Android using NativeScript

There was a small project I did which required the IMEI number to be read. I used the following code to read the IMEI number on Android using NativeScript.

AndroidManifest.xml

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

NativeScript code

function getIMEI(){
    var context = utils.ad.getApplicationContext();
    var tm = context.getSystemService(android.content.Context.TELEPHONY_SERVICE);
    return tm.getDeviceId()
}

Then call getIMEI() where there is a need. Simple.

Gaurav Chandra
Gaurav Chandra

Gaurav Chandra

I am available for work

Contact me now