Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright 2016 IPCO 2012 Limited
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import android.net.Uri;

import android.support.annotation.NonNull;

import android.text.TextUtils;

public class Main {
    /**
     * Constant for Pay by Bank app (Zapp) custom scheme.
     */
    private static final String ZAPP_SCHEME = "zapp";
    /**
     * Zapp specific URI format string.
     */
    @SuppressWarnings("HardcodedFileSeparator")
    private static final String ZAPP_URI_FORMAT_STRING = "%s://%s";

    /**
     * Open banking App for given context and secure token. Use this method if you do not use the Pay by Bank app Popup API (which takes care of the banking app
     * opening).
     *
     * @param context     The (activity or application) context to start the banking App.
     * @param secureToken The secure token of the payment for which the banking App is to be started.
     * @see #isCFIAppAvailable(Context)
     * @see #showPBBAPopup(FragmentActivity, String, String, PBBAPopupCallback)
     * @see #showPBBAErrorPopup(FragmentActivity, String, String, String, PBBAPopupCallback)
     */
    public static void openBankingApp(@NonNull Context context, @NonNull final String secureToken) {

        //noinspection ConstantConditions
        if (context == null) {
            throw new IllegalArgumentException("context == null");
        }

        if (TextUtils.isEmpty(secureToken)) {
            throw new IllegalArgumentException("secureToken is required");
        }

        final Uri zappUri = Uri.parse(String.format(ZAPP_URI_FORMAT_STRING, ZAPP_SCHEME, secureToken));
        final Intent bankingAppStartIntent = new Intent(Intent.ACTION_VIEW, zappUri);
        @SuppressWarnings("BooleanVariableAlwaysNegated")
        final boolean isActivityContext = context instanceof Activity;
        if (!isActivityContext) {
            bankingAppStartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(bankingAppStartIntent);
    }
}