@Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   AndroidActivityManager aam =
       (AndroidActivityManager)
           AndroidServiceLocator.GetInstance()
               .GetService(AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
   if (aam != null) {
     aam.publishActivityResult(requestCode, resultCode, data);
   }
 }
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    AndroidSystem system =
        (AndroidSystem)
            AndroidServiceLocator.GetInstance()
                .GetService(AndroidServiceLocator.SERVICE_TYPE_SYSTEM);
    boolean locked = system.IsOrientationLocked();
    if (locked) {
      int configOrientation;
      DisplayOrientation lockedOrientation = system.GetLockedOrientation();
      if (DisplayOrientation.Portrait.equals(lockedOrientation)) {
        configOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
      } else if (DisplayOrientation.Landscape.equals(lockedOrientation)) {
        configOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
      } else {
        // Portrait as default orientation
        configOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
      }
      if (newConfig.orientation != configOrientation) {
        LOG.Log(
            Module.GUI,
            "Main Activity onConfigurationChanged setting requested orientation: "
                + configOrientation);

        setRequestedOrientation(configOrientation);
      }
    } else {
      activityManager.layoutSplashscreen();
      appView.requestLayout();
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LOG.Log(Module.GUI, "onCreate");

    // GUI initialization code
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    disableThumbnails = checkUnityProperty("Unity_DisableThumbnails");

    // security reasons; don't allow screen shots while this window is displayed
    /* not valid for builds under level 14 */
    if (disableThumbnails && Build.VERSION.SDK_INT >= 14) {
      getWindow()
          .setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    }

    appView = new WebView(this);
    appView.enablePlatformNotifications();
    setGlobalProxy();

    appView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    appView.setId(APPVIEW_ID);
    appView.setWebViewClient(new UnityWebViewClient());
    appView.getSettings().setJavaScriptEnabled(true);
    appView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    appView.getSettings().setAllowFileAccess(true);
    appView.getSettings().setSupportZoom(false);
    appView.getSettings().setAppCacheEnabled(false);
    appView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    appView.getSettings().setAppCacheMaxSize(0);
    appView.getSettings().setSavePassword(false);
    appView.getSettings().setSaveFormData(false);
    appView.getSettings().setDefaultTextEncodingName("UTF-8");
    appView.getSettings().setGeolocationEnabled(true);
    appView.getSettings().setLightTouchEnabled(true);
    appView.getSettings().setRenderPriority(RenderPriority.HIGH);
    appView.getSettings().setDomStorageEnabled(true); // [MOBPLAT-129] enable HTML5 local storage

    appView.setVerticalScrollBarEnabled(false);

    // Required settings to enable HTML5 database storage
    appView.getSettings().setDatabaseEnabled(true);
    String databasePath =
        this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    appView.getSettings().setDatabasePath(databasePath);

    webChromeClient =
        new WebChromeClient() {

          // Required settings to enable HTML5 database storage
          @Override
          public void onExceededDatabaseQuota(
              String url,
              String databaseIdentifier,
              long currentQuota,
              long estimatedSize,
              long totalUsedQuota,
              WebStorage.QuotaUpdater quotaUpdater) {
            quotaUpdater.updateQuota(estimatedSize * 2);
          };

          @Override
          public void onReachedMaxAppCacheSize(
              long spaceNeeded,
              long totalUsedQuota,
              android.webkit.WebStorage.QuotaUpdater quotaUpdater) {
            quotaUpdater.updateQuota(0);
          };

          @Override
          public boolean onConsoleMessage(ConsoleMessage cm) {
            LOG.Log(
                Module.GUI,
                cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
            return true;
          }
        };

    appView.setWebChromeClient(webChromeClient);

    // create the application logger
    LogManager.setDelegate(new AndroidLoggerDelegate());

    // save the context for further access
    AndroidServiceLocator.setContext(this);

    // initialize the service locator
    activityManager = new AndroidActivityManager(this, appView);

    // killing previous background processes from the same package
    activityManager.killBackgroundProcesses();

    AndroidServiceLocator serviceLocator =
        (AndroidServiceLocator) AndroidServiceLocator.GetInstance();
    serviceLocator.RegisterService(
        this.getAssets(), AndroidServiceLocator.SERVICE_ANDROID_ASSET_MANAGER);
    serviceLocator.RegisterService(
        activityManager, AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
    startServer();

    /* THIS COULD NOT BE CHECKED ON API LEVEL < 11; NO suchmethodexception
    boolean hwAccelerated = appView.isHardwareAccelerated();
    if(hwAccelerated)
    	LOG.Log(Module.GUI,"Application View is HARDWARE ACCELERATED");
    else
    	LOG.Log(Module.GUI,"Application View is NOT hardware accelerated");
    */

    final IntentFilter actionFilter = new IntentFilter();
    actionFilter.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION);
    // actionFilter.addAction("android.intent.action.SERVICE_STATE");
    registerReceiver(new AndroidNetworkReceiver(appView), actionFilter);

    final Activity currentContext = this;
    new Thread(
            new Runnable() {
              public void run() {
                currentContext.runOnUiThread(
                    new Runnable() {
                      public void run() {
                        appView.loadUrl(WEBVIEW_MAIN_URL);
                      }
                    });
              }
            })
        .start();

    holdSplashScreenOnStartup = checkUnityProperty("Unity_HoldSplashScreenOnStartup");
    hasSplash = activityManager.showSplashScreen(appView);
    RemoteNotificationIntentService.loadNotificationOptions(getResources(), appView, this);
    LocalNotificationReceiver.initialize(appView, this);
  }
  /**
   * @see android.content.BroadcastReceiver#onReceive(android.content.Context,
   *     android.content.Intent)
   */
  @Override
  public void onReceive(Context context, Intent intent) {

    LOGGER.logDebug("onReceive", "******* Local Notification Received " + intent.getAction());

    // Getting notification manager
    final NotificationManager notificationMgr = NotificationUtils.getNotificationManager(context);

    // Getting notification details from the Intent EXTRAS
    final Bundle bundle = intent.getExtras();
    final String ticker = bundle.getString(TICKER);
    final String title = bundle.getString(TITLE);
    final String body = bundle.getString(BODY);
    final String notificationSound = bundle.getString(SOUND);
    final String customJsonData = bundle.getString(CUSTOM_JSON_DATA);
    int notificationId = 0;

    try {
      notificationId = Integer.parseInt(bundle.getString(NOTIFICATION_ID));
    } catch (Exception e) {
      LOGGER.logError(
          "onReceive",
          "Unable to process local notification with id: " + bundle.getString(NOTIFICATION_ID));
    }

    int iIconId =
        context
            .getResources()
            .getIdentifier(
                NotificationUtils.DEFAULT_ICON_NAME,
                NotificationUtils.DRAWABLE_TYPE,
                NotificationUtils.PACKAGE_NAME);

    // Creates the notification to display
    Notification notif = null;
    NotificationData notificationData = new NotificationData();
    notificationData.setAlertMessage(body);
    notificationData.setSound(notificationSound);
    notificationData.setCustomDataJsonString(customJsonData);

    Notification.Builder mBuilder =
        new Notification.Builder(context)
            .setDefaults(0)
            .setContentIntent(
                NotificationUtils.getMainActivityAsPendingIntent(
                    context,
                    NotificationUtils.NOTIFICATION_TYPE_LOCAL,
                    "" + notificationId,
                    notificationData))
            .setSmallIcon(iIconId)
            // TODO
            // .setLights(Integer.parseInt(NOTIFICATION_STRUCTURE.get(RemoteNotificationFields.RN_LED_COLOR_ARGB.toString())), 100, 100)
            .setTicker(ticker)
            .setContentText(body)
            .setContentTitle(title);

    /**
     * TODO Bitmap largeIconBMP = null;
     *
     * <p>if(NOTIFICATION_STRUCTURE.containsKey(RemoteNotificationFields.RN_LARGE_ICON.toString())){
     * int iLargeIconId =
     * APP_RESOURCES.getIdentifier(NOTIFICATION_STRUCTURE.get(RemoteNotificationFields.RN_LARGE_ICON.toString()),
     * NotificationUtils.DRAWABLE_TYPE, PACKAGE_NAME); largeIconBMP =
     * BitmapFactory.decodeResource(APP_RESOURCES, iLargeIconId); } if(largeIconBMP!=null){
     * mBuilder.setLargeIcon(largeIconBMP); }
     */
    if (notificationSound != null
        && !notificationSound.isEmpty()
        && !notificationSound.equals("default")) {
      mBuilder.setSound(Uri.parse(notificationSound));
    } else {
      // set default sound
      mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    }
    notif = mBuilder.getNotification();

    // check if vibration should be enabled
    // notification.vibrate = new long[] { 0, 100, 200, 300 };

    /*
     * In order to stack all reminders in the notification bar, a random ID should be generated.
     * To replace an existing notification, ID should match in the notification intent.
     */
    notificationMgr.notify(notificationId, notif);

    // remove notification from stored shared preferences, as it has been already processed by the
    // notification manager
    NotificationUtils.removeLocalNotificationFromSharedPrefereces(context, "" + notificationId);

    final NotificationData notifData = notificationData;

    // TESTING MARGA
    if (appActivity != null && activityManager != null) {
      activityManager.loadUrlIntoWebView(
          "javascript:try{Unity.OnLocalNotificationReceived("
              + JSONSerializer.serialize(notifData)
              + ")}catch(e){}");
      LOGGER.logDebug("onReceive", "Invoking rNotification on UI thread... ");
    }
  }