NAV

Overview

MegoUser is one of the modules of MegoGrid. So here I am explaining what MegoUser is and how it works for an Android App Developer.

Now a days , Mobile Technology is becoming too vast for the ease of the world, keeping the KISS principle (Keep It Short and Simple). Developers are doing their best to make the world Techno Freak. As their time is too precious, Frameworks are being developed to save time. So, every developer needs the details of their application users, by which they could keep the record of each and every brief detail of their user, which he/she could use accordingly.

Now I am sure, everybody have some questions in their mind, so let's start knowing all the What, Why and How about MegoUser.

MegoUser Demo is an app which apply photo effects on camera images and gallery images. This app is available in Google Play and its source code is avalable on Github.You can take all the reference of source code and see how we integrate a power platform of Mego User for authentication and backup syncing.In this I represent I will guide you how we can integrate Mego User to an App and how this power framework makes authentication mechanism so simple whether it is login from mechanism from Facebook, Google Plus, email and all this finally integrated with our powerfull MegoGrid server.

This tutorial is divided into several parts, each focusing on a different aspect of our Mego Grid Demo App. Feel free to read them in any order, but we recommend that you download the source code and refer to it while reading. Some parts of the code were omitted or changed in this tutorial in order to keep it clear and concise, so you may find it useful to keep the full version close at hand.

MegoGrid demo architecture

MeGoUser contains five main activities: SplashActivity Handles the intializing of the logo wherein it delays around 5 seconds,SMainActivity shows the effects category option whether it is from camera or Gallery, PhotoActivityThis activity applies different effects on the images whether it is captured from the Camera or from the gallery, while Help is where it shows the basic help content of the app. help content of app

Aside from the basic functionality, we had integrated our MeGoGrid API in different section of the application.

Getting Started

Authorization

To use the MeUser SDK, first of all you need to authenticate your application/device with our server. To authenticate your application/device use the Authentication-Layer SDK and call the below mentioned code in your app launcher activity.

Integrating Authorization SDK in your Android app

Inside the onCreate() method of your SplashActivity configure MegoAuthorizer SDK .

MegoAuthorizer megoAuthorizer = new MegoAuthorizer(SplashActivity.this);
megoAuthorizer.intializeSDK();

MegoUser

The MegoGrid Demo app represents here the uses of MegoUser SDK. MegoUser use the two way mechanism for the user to register his/her device/application on our server. These are as described below:

Here the second part (Email) is further divided into three sub parts which are cited as follows:

Integrating MegoUser SDK in your Android app

Before integrating MegoUser SDK you have to configure the required details on our MegoGrid CMS Panel provided to you by us. Here you can provide the options a user of your app will have for registration of their devices/application. For example you can provide all the three email option or either one of them to register via your app.

For this Demo app we have already configured all the details (dummy configuration) so that you can download and check how this unique system works or you can check if it suits your development needs.

Below are the step by step guide how we have integrated this SDK into our Demo app inside onCreate() method of our MainActivity

Call the below code inside the onCreate() method of your app MainActivity if you only want to give the custom ID registration option to your app user. So user will only be prompted with the custom registration/sign p option.

 new MegoUserConfig.ConfigBuilder(MainActivity.this)
                .build();

However, if you have provided the Google+ registration/Sign Up to the app user then you must have to pass the YOUR_GOOGLE_ID (provided to you at the time of creating Google project on Google Console for Google+ sign in).Then just call one additional method setGoolgeKey() before calling the build() method. Below is the code snippet that shows how to do this.

private static String YOUR_GOOGLE_ID = “ 720282980579-smn98g7o513htrhf6nnapth4t6bfgklu.apps.googleusercontent.com”;
new MegoUserConfig.ConfigBuilder(MainActivity.this)
                .setGoogleKey(YOUR_GOOGLE_ID).build();

Moreover, if you want some more customization to your registration process like providing your own theme background for all types of registration option at the time of prompt appear to the screen then just call the setAppBackground() method along with other config methods before calling build().

 new MegoUserConfig.ConfigBuilder(MainActivity.this)
                .setAppBackground(R.drawable.background).build();

Similarly, if you want to provide your own app icon beneath the registration prompt along with the background you set previously just call the setAppIcon() method before calling the build().

new MegoUserConfig.ConfigBuilder(MainActivity.this)
                .setAppIcon(R.drawable.ic_launcher).build();

Note: You must have to provided the fb_id into your app Manifest.xml file if you have provided the Facebook registration option to the user.

User Management

User Management is a way through which various mobile apps are managing their users and keep track of shopping behaviour, health tracking, finance tracking, etc. MeUser SDK provides a powerful way through this kind of management wherein it becomes easy for the user. This SDK integrates your android app by adding logic for authentication such as login, sign up and logout. Aside from this powerful SDK, it provides various other mechanism like backup creation and back restore of user’s crucial data. In this demo, we introduced a way on how you can bind this mechanism in just few steps as described below:

Sign up / Login

Once you configured all the required things for MegoUser SDK as described above in MegoUser section, you can call the below code inside the onCreate() method of your Main Activity. After calling this method, it will first check if configuration details are already fetched from the server. If configuration is not fetched then it will resend the config request to our server and then show the respective prompt that has been configured on the CMS Panel by you as previously described above.

So after checking the configuration details from the server, it will decide which type of prompts will appear on the user mobile screen, like if you are going to be a first time user then it will prompt for registration page. If user is already registered, then sign in prompt will appear. Moreover, if the CMS panel is set on optional registration, then after launching the app for the first time, it will not prompt the registration page but will prompt further while using the application.

Apart from the above cases if there is any reason for the failed registration process then you will be notified by MegoUserException that will be thrown in such cases so that you can check where the loop hole is and can handle such condtion accordingly.

 MegoUser   MegoUser = MegoUser.getInstance(MainActivity.this);

Calling initiateRegistration method will handle all of your Sign up / Login prompts according to your configuration which is set at our MegoGrid CMS panel. Pass your interface for receiving Sign up / Login callbacks.

 MegoUser.initiateRegistration(new RegistrationHandler.IResponseHandler() {
            @Override
            public void onRegisterCallBack(MegoUserException e) {
                System.out.println(“MainActivity.onRegisterCallBack  ” + e);
            }

            @Override
            public void onLoginCallBack(MegoUserException e) {

            }

            @Override
            public void onRegisterPromptInvocation(MegoUserException e) {


            }
        });


Method initiateRegistration() takes one parameter i.e IResponseHandler as explained below:
Parameter : callback listener which will be called after the registration/login process take place.

It has three methods :
-onRegisterCallBack(MegoUserException exception) will be called when registration process is done, In case of both success and failed registration.

-onLoginCallBack(MegoUserException exception) will be called when login process is done, In case of both success and failed registration..

-onRegisterPromptInvocation(MegoUserException exception) will be called when registration or login prompt invoked

Logout

When you have alreadylogged in to work, you probably want to have the option to logout. All you have to do is to call the below method onClick in any event producing view. Here’s an example of a logout menu in the MainActivity class.

In our Demo app we use TextView widgets that are defined in the activity_main.xml layout to perform logout functionality and is accessible via the options menu in MainActivity, but you can use any of the android widgets. We find the widgets in the onCreate() method of MainActivity to begin our Logout flow setup :

 logout = (TextView) findViewById(R.id.logout);

We then add the logout logic to the button’s OnClickListener handler in the onCreate method:

logout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                onLogoutClick();
            }
        });

In the code above, an OnClickListener handler is attached to the logout textview that’s identified by the logout resource. This in turn calls the private onLogoutClick method where we call the logout API function of MegoUser:

private void onLogoutClick(){
        try {
            boolean status = MegoUser.logout(MainActivity.this);
            if (status)
                Toast.makeText(MainActivity.this“Successfully Logged out”, Toast.LENGTH_LONG).show();
        } catch (MegoUserException e) {
            e.printStackTrace();
            Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
        }
    }

Backup

The backup service of MeUser allows you to copy your persistent application data to a remote cloud storage. This allows you to restore the application data and settings in case the user switches android devices, re-installs the application or performs a factory reset. This feature also helps you to retrieve your data back in case of any mishappening like loss of data, device got stolen, damage, etc.

The persistent data that you want to backup is in either of the two forms. Either it could be in shared preferences or it could be in File. MeUser supports both types of backup in the respective backup types and Data backup respectively.

Create App Backup

Create App Backup will help you in backing up all the information related to the specific app. It aims at reducing the efforts of repeatedly filling the same info to use the app in desired manner.

As part of the Creating App Backup process, we use TextView widgets that are defined in the activity_main.xml layout to create app data backup and is accessible via the options menu in MainActivity, but you can use any of the android widgets. We find the widgets in the onCreate() method of MainActivity to begin our App Backup flow setup:

prefbackup = (TextView) findViewById(R.id.prefbackup);

We then add the creating backup logic to the prefBackup’s OnClickListener handler in the onCreate method:

prefBackup.setOnClickListener(new OnClickListener() {
                                          @Override
                                          public void onClick(View view) {
                                              onPrefBackupClick();
                                          }
                                      }
        );

In the code above, an OnClickListener handler is attached to the prefBackup TextView that’s identified by the prefBackup resource. This in turn calls the private onPrefBackupClick method where we call the backupPreference API function of MegoUser:

private void onPrefBackupClick() {
        long version = 1;

        editor.putString(“json”, detail.toString());
        editor.commit();
        System.out.println(“Preference is : ” + preferences);
        MegoUser.getInstance(MainActivity.this).backupPreference(version, preferences);
    }

Restore App Backup

Restore App Backup will help you in restoring all the information that is backed up using the “Backup Preference”

As part of the Restore App Backup process, we use TextView widgets that are defined in the activity_main.xml layout to restore app data backup and is accessible via the options menu in MainActivity, but you can use any of the android widgets. We find the widgets in the onCreate() method of MainActivity to begin our Restore App Backup flow setup:

prefRestore = (TextView) findViewById(R.id.Prefrestore);

We then add the restoring logic to the button’s OnClickListener handler in the onCreate method:

prefRestore.setOnClickListener(new OnClickListener() {
                                           @Override
                                           public void onClick(View view) {
                                             onPrefRestoreClick();
                                           }
                                       }

        );

In the code above, an OnClickListener handler is attached to the prefRestore button that’s identified by the PrefRestore resource. This in turn calls the private onPrefRestoreClick method where we call the restorePreference API function of MegoUser:

private void onPrefRestoreClick(){
        editor.putString("json”, detail.toString());
        editor.commit();
        long version = 1;
        MegoUser.getInstance(MainActivity.this).restorePreference(version, preferences);
    }

Create Data Backup

Create Data Backup will help you to store any type of file including - Video, Images, PDF, etc.

As part of the Creating Data Backup process, we use TextView widgets that are defined in the activity_main.xml layout to create data backup and is accessible via the options menu in MainActivity, but you can use any of the android widgets. We find the widgets in the onCreate() method of MainActivity to begin our Data Backup flow setup:

 filebackup = (TextView) findViewById(R.id.filebackup);

We then add the creating data backup logic to the filebackup’s OnClickListener handler in the onCreate method:

  fileBackup.setOnClickListener(new OnClickListener() {
                                          @Override
                                          public void onClick(View view) {
                                              showFileChooser();
                                          }
                                      }

In the code above, an OnClickListener handler is attached to the fileBackUp TextView that’s identified by the filebackup resource. This in turn calls the private showFileChooser method where we call the Chooser intent of Files:

private void showFileChooser() {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType(“*/*”);
        intent.addCategory(Intent.CATEGORY_OPENABLE);

        startActivityForResult(
                Intent.createChooser(intent, “Select a File to Upload”), 3);
    }

We then receive callback of file in onActivityResult of MainActivity. After verifying the requestCode and resultCode we call the private backupFile method where we call the backupFile API function of MegoUser:

private void backupFile(Intent data){
        Uri uri = data.getData();
        try {
            String path = getPath(this, uri);
            long version = 1;
            MegoUser.getInstance(MainActivity.this).backupFile(path, version);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }

Restore Data Backup

Restore Data Backup will help you in restoring all the files that is backed up using the “Data Backup”. All the restored files will be secured.

As part of the Restore Data Backup process, we use TextView widgets that are defined in the activity_main.xml layout to restore app data backup and is accessible via the options menu in MainActivity, but you can use any of the android widgets. We find the widgets in the onCreate() method of MainActivity to begin our Restore Data Backup flow setup:

fileRestore = (TextView) findViewById(R.id.fileRestore);

We then add the restoring logic to the button’s OnClickListener handler in the onCreate method:

fileRestore.setOnClickListener(new OnClickListener() {
                                           long version = 1;

                                           @Override
                                           public void onClick(View view) {
                                               MegoUser.getInstance(MainActivity.this).rle(version);
                                           }
                                       }

In the code above, an OnClickListener handler is attached to the fileRestore button that’s identified by the fileRestore resource. This in turn calls the private onFileRestoreClick method where we call the restoreFile API function of MegoUser:

fileRestore.setOnClickListener(new OnClickListener() {
                                           @Override
                                           public void onClick(View view) {
                                               onFileRestoreClick();
                                           }
                                       }
        );

Profile

Profile management ensures that the user’s personal settings are applied to the user’s devices and applications, regardless of the location and end point device. User can set their profile only if he/she is already registered. If he/she is a first time user of the app then he/she will be prompted with the registration prompt.

Profile management is enabled through a profile optimization service that provides an easy and reliable way for managing these settings in android application to ensure a consistent experience by maintaining a single profile that follows the users preference. It auto-consolidates and optimizes user profiles to minimize management,storage requirements and requires minimal administration, support and infrastructure while providing users with improved login and logout session. In this Demo app we have shown how our profile management system works with the android application.

Profile Setup

Profile Setup will help you in viewing user’s latest profile setup screen. If user is already registered, a profile setup activity will be shown to the user where he/she can manage his/her demographic details and more. But, if he/she is not registered then there will be a registration promptthat will appear.

As part of the Profile Setup process, we use TextView widgets that are defined in the activity_main.xml layout to view user profile details and is accessible via the options menu in MainActivity, but you can use any of the android widgets. We find the widgets in the onCreate() method of MainActivity to begin our Profile setup flow setup:

account = (TextView) findViewById(R.id.account);

We then add the user profile setup logic to the account’s OnClickListener handler in the onCreate method:

account.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                onProfileSetupClick();
            }
        });

In the code above, an OnClickListener handler is attached to the account button that’s identified by the account resource. This in turn calls the private onProfileSetupClick method where we call the showAccount API function of MegoUser:

private void onProfileSetupClick(){
        try {
            MegoUser.getInstance(MainActivity.this).showAccount();
        } catch (MegoUserException e) {
            e.printStackTrace();
        }
    }

Registeration Reminder

You might not force your users to register first and then use your application. But there might be some features in your application where you want your user’s credentials first before allowing access to that feature. So in this case you can use our registration reminder feature of MegoUser SDK. It will prompt the user to register first before exploring inside of such features.

Here we have demonstrated how the registration reminder works. Here we have used the eventID generated automatically from the MegoGrid CMS panel that will be used to remind the user for registration.

Lets say, a boxID provided by CMS panel.

public static final String YOUR_BOX_ID = "KPDFC20UD”;

In our Demo App, We have implemented this feature on feature Picking image from Gallery. In the private displayGallery onClick method for displaying gallery we call showRegisterById API function of MegoUser for registration reminder.

private void displayGallery() {
        try {
            MegoUser.getInstance(MainActivity.this).showRegisterById(YOUR_BOX_ID);
        } catch (MegoUserException e) {
            e.printStackTrace();
        }
        if (Environment.getExternalStorageState().equals(
                Environment.MEDIA_MOUNTED)
                && !Environment.getExternalStorageState().equals(
                Environment.MEDIA_CHECKING)) {
            Intent intent = new Intent();
            intent.setType(“image/jpeg”);
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(intent, Constants.REQUEST_GALLERY);
        } else {
            Toaster.make(getApplicationContext(), R.string.no_media);
        }
    }

Verification Pending

Verification Pending will help you in finding whether your user’s account email is verified or not.

As part of checking user’s email verification process, we use TextView widgets that are defined in the activity_main.xml layout to view user profile details and is accessible via the options menu in MainActivity, but you can use any of the android widgets. We find the widgets in the onCreate() method of MainActivity to begin our Verification process flow setup:

userVerifStatus= (TextView) findViewById(R.id.userVerifStatus);

We then add the user verification pending logic to the userVerifStatus’s OnClickListener handler in the onCreate method:

userVerifStatus.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                onCheckVerificationStatus();
            }
        });

In the code above, an OnClickListener handler is attached to the userVerifStatus TextView that’s identified by the userVerifStatus resource. This in turn calls the private onCheckVerificationStatus method where we call the isEmailVerified API function of MegoUser:

private void onCheckVerificationStatus() {
        try {
            MegoUser.getInstance(this).isEmailVerified();
        } catch (MegoUserException e) {
            e.printStackTrace();
        }
    }




© 2015-2016 Megogrid Inc. / Term of service / Licenses / Privacy Policy 913 N Market Street Suite 200 Wilmington DE 19801 USA