Monday, January 26, 2015

Features Available in Crittercism That we use less

Loggin Transactions

Transactions allows companies to track key interactions or user flows in their app such as login, account registration and in app purchase. By default, the SDK will automatically track application load time as a transaction. A developer can specify additional transactions by adding a few more lines of code to the application. 

Developers must add code to specify where a transaction starts and where it ends. Below is an example of tracking transactions 

[Crittercism beginTransaction:@“Login”];
BOOL didLogin = [self runMyLoginCode];
if(didLogin)
{
[Crittercism endTransaction:@“Login”];
}
else 
{
[Crittercism failTransaction:@“Login”];
}

Transaction can be nested. But transaction with the same group cannot be multiple. A transaction group is identified by the name given in the beginTransaction method. 

to end the transaction, code can use the endTransaction API. To modify the value of transaction, one can use setValue:forTransaction valueForTransaction 

Logging Breadcrumbs
Developers can use leaveBreadcrumb method to write to a chronological log that is reported with the crashes and handled exceptions 

A breadcrumb is a developer-defined text string upto 140 characters that allows developers to capture app runtime information. 

[Crittercism leaveBreadcrubmb:@“User reached login screen”]; 

by default the breadcrumbs are written on to the file immediately. in order to force the breadcrumbs to use the background thread, below method can be called 

[Crittercism setAsyncBreadcrumbMode:YES]

Handled Exceptions
Application can use logHandledException method to track NSException that do not cause a crash. An example is like below 

@try 
{
[NSException raise:NSINvalidArgumentException format:@“foo must not be nil”];
}
@catch (NSException *exception)
{
[Crittercism logHandledException:exception];
}

Logging Errors 
for logging errors, use logError method. Error may be used for tracking NSError errors returned by the Apple and 3rd party library errors. 

Handling Offline Crashes
library caches upto 3 crashes on the device when offline. But this value can be altered using the setMaxOfflineCrashReports method. 

Detecting that a Crash occurred
CrittercismDelegate protocol gives a method, below method can be overridden 

- (void) crittercismDidCrashOnLastLoad
{
}


 References:
http://docs.crittercism.com/ios/ios.html

Sunday, January 25, 2015

Setting up Google Play Services


To develop an app using the Google Play Services APIs, one need to setup the projects with the Google Play services SDK. 

In order to add the Google Play services SDK package, below steps can be followed. 

Open SDK Manager, Open the Extras directory and select the Google Play Services and Google Repository. Google Play services are not available on every device, but available on all devices with Google Play Store.  An Android devices that run on 2.3 OS or later, Or Android emulator with an AVD that runs Google APIs platform based on Android 4.2.2 or higher will have the Google Play services available. 

Next Step is to add Play Services to The Project
1. Open the build.gradle file in the Application module directory 
2. Add a new build rule under dependancies for the version of play-services.

For e.g. 
apply plugin ‘com.android.application’

dependancies{
compile : ‘com.google.android.gms:play-services:6.5.87’
}

We need to be sure to update this version number everytime Google Play service is updated. 

3. Save the changes and Click Sync Project with Gradle files in the tool bar 
4. Open the app’s manifest file and add the following tag as child for application element 

android:value=“@integer/google_play_services_version”/>

Now one can begin developing with Google Play services! 


References:

Friday, January 23, 2015

What is Big Data




Big data is a popular terms used to describe exponential growth and availability of data, both structured and unstructured. And big data may be as important to business - and society - as the internet has become. Why? More data may lead to more accurate analysis. 

More accurate analysis leads to more confident decision making. And better decisions can mean greater operational efficiencies, cost reductions and reduced risk.

The three Vs of big data are: 

Volume: Volume denotes the data volume. There are many sources for data, transaction - based data stored for many years, unstructured data from social media networks, data collected from sensors. Recently, the data storage costs have been reduced and storing large amount of data can be done now with less cost. Even though decreasing the storage cost, the other issue emerging is how to make out meaningful information from these data. 

Velocity :data is streaming in an unprecedented speed and must be dealt with in timely manner. RFID tags, sensors and smart metering are driving the need to deal with torrents of data in near real time.  Reacting quickly enough to deal with the data velocity is a challenge for many organisations. 

Variety: Data today comes in all types of formats. Structured numeric data in traditional databases. Info created from line of business apps. Unstructured text documents such as email video, audio, stock ticker data and financial transactions. Managing, merging and governing different varieties of data is something many organisations still grapple with.  

What is matters with the Big Data? 
The real issue is not about collecting the data, it is about how to interpret the data. For instance: by combining big data and high powered analytics, it is possible to 

1. Determine root causes of failures, issues and defects in near-real time, potentially saving millions of dollars annually. 

2. Optimise routes for many thousands of package delivery vehicles while they are on the road. 

3. Analyse millions of SKUs to determine prices that maximise profit and clear inventory. 

4. Generate retain coupons at the point of sale based on customers current and past purchases. 

5. Send tailored recommendations to mobile devices while customers are in the right area to take advantage of offers. 

6. Recalculate entire risk portfolios in minutes

7. Quickly identify customers who matter the most 

8. Use clickstream and data mining to detect the fraudulent behaviour. 

References: 

Wednesday, January 21, 2015

Android Setting Cookie to WebView

In order to set the cookie into the Android WebView, below code can be used.

                        CookieManager.getInstance().setAcceptCookie(true);
                        CookieManager.getInstance().setCookie("myhttp.info","testcookie=cookietest");

                        webView.setWebViewClient(new WebViewClient());
                        webView.loadUrl("http://myhttp.info/");


the web page http://myhttp.info/ is a good tool to know what headers the request is containing.
In the above code, it is trying to pass the cookie as cookietest for the key testcookie. The appearance of this page is something like below



References:
http://myhttp.info/

Tuesday, January 20, 2015

UIWebView cookie setting from hosting app

It is possible to set cookies to the iOS layer so that the UIWebview displayed within the app can pick it up and apply the session value. Below code tries to set a session key to the google.com domain. 

 NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
                [cookieProperties setObject:@"authToken" forKey:NSHTTPCookieName];
                NSString *sessionID = [userdetails.sessionId stringByReplacingOccurrencesOfString:@"Wayfarer=" withString:@""];
                [cookieProperties setObject:sessionID forKey:NSHTTPCookieValue];
                [cookieProperties setObject:@"www.google.com" forKey:NSHTTPCookieDomain];
                [cookieProperties setObject:@"www.google.com" forKey:NSHTTPCookieOriginURL];
                [cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
                [cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];
                [cookieProperties setObject:[[NSDate date] dateByAddingTimeInterval:2629743] forKey:NSHTTPCookieExpires];
                NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
                

                [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];

Even though application sets the cookie information, it is not possible that Safari or other application pick up this value in the request they make. 

Friday, January 16, 2015

Android Managing System UI - Hiding the Navigation Bar

In Android system bars are screen areas dedicated to the display of notifications, communication of device status, and device navigation. These are displayed concurrently with the application. Apps that display immersive content, such as images or movies can temporarily dim the system bar icons for a less distractng experience, or temporarily hide the bars for a fully immersive experience. 

Hiding the Navigation Bar
Navigation bar was introduced in Android System 4.0. Normally, it is better to hide the status bar and the navigation bar together. 

Below code can hide the navigation bar. 

super.onCreate(savedInstanceState);
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
        setContentView(R.layout.activity_main);

Few notes:

- In this approach, touching anywhere on the screen will cause the navigation bar and the status bar to reappear again.  i.e. User interaction makes the elements re-appear again and the already set flags will be cleared. 

- Application can listen to the UI Visibility state changes to listen to the ui activity events and then can decide to make it reappear again, 

- Application needs to call the flags at specific points in the application, OnCreate is one place, onResume is another, onWindowFocusChanged should also be overriden to listen to the system event and then hide the system ui components again 

- The methods have effect only if the calls is from a View that is visible

- Navigating away from the view causes the flag set with the setSystemUiVisibility to be cleared. 

with the below few lines of code, application is able to show a full screen Activity

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
        setContentView(R.layout.activity_main);
        ActionBar ab = getActionBar();
        if(ab != null) {
            ab.hide();
        }
        android.support.v7.app.ActionBar sab = getSupportActionBar();
        if(sab != null) {
            sab.hide();
        }
    }


References:


Thursday, January 8, 2015

GridView with android Hands On

When decided to learn about GridView, thought will look at the Android Sample itself. Found the sample at the link given in Android website very useful.

The code was pretty simple. First had to add the grid view to the layout xml file

The code was like the below

        android:id="@+id/gridview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnWidth="90dp"
        android:numColumns="auto_fit"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:stretchMode="columnWidth"
        android:gravity="center"
        />

Now, in the main activity on create, below code needs to be added

GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));

        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView parent, View v, int position, long id) {
                Toast.makeText(GridViewSampleActivity.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });

Just create the subclass of BaseAdapter and override the getView function

 public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(200, 200));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);
        } else {
            imageView = (ImageView) convertView;
        }

        imageView.setImageResource(mThumbIds[position]);
        return imageView;
    }

I gave the layout param as 200 x 200 gave a good looking grid view, however, on orientation chagne, all the grid items were overlapping without any gap. Need to check this. 

Reference:
http://developer.android.com/guide/topics/ui/layout/gridview.html