package com.ibm.mobilefirstplatform.clientsdk.android.ui;

import android.Manifest;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;


import java.util.logging.Level;
import java.util.logging.Logger;

import static android.content.pm.PackageManager.GET_META_DATA;

public class UIActivity extends AppCompatActivity {


    private final int MY_PERMISSIONS_REQUEST_LOCATION=11;
    private static final Logger logger =Logger.getLogger(UIActivity.class.getName());
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if(ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
        {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION},
                    MY_PERMISSIONS_REQUEST_LOCATION);
        }
        else
        {
            launchMainActivity();
        }



    }

    private void launchMainActivity()
    {
        ApplicationInfo ai = null;
        try {
            System.out.println("&&&&"+this.getPackageName()+" "+getApplication().getPackageName());
            ai = getPackageManager().getApplicationInfo(this.getPackageName(),   PackageManager.GET_META_DATA);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        Bundle bundle = ai.metaData;
        String mainActivity = bundle.getString("main_activity");

        System.out.println("mainActivity "+mainActivity);
        Intent launchMain = null;
        try {
            launchMain = new Intent(this, Class.forName(mainActivity));
        } catch (ClassNotFoundException e) {

            logger.log(Level.SEVERE, "MainActivity name provided is not correct");
        }
        startActivity(launchMain);
        finish();
    }

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        switch (requestCode) {
            case MY_PERMISSIONS_REQUEST_LOCATION: {

                System.out.println("Inside Case");

                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                    Toast.makeText(this,"Location Logging APi is activated ",Toast.LENGTH_LONG);

                } else {

                    Toast.makeText(this,"Location Logging APi is deactivated ",Toast.LENGTH_LONG);
                }

               launchMainActivity();

                break;
            }
            
            default:    
                

        }
    }



}

@@ -243,57 +243,8 @@
 at;%0A
-import android.support.v4.content.ContextCompat;%0A
 impo
@@ -415,71 +415,8 @@
 r;%0A%0A
-import static android.content.pm.PackageManager.GET_META_DATA;%0A
 %0Apub

Remove Unused imports