Java Code Examples for androidx.fragment.app.FragmentActivity#getApplicationContext()

The following examples show how to use androidx.fragment.app.FragmentActivity#getApplicationContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowserSwitchClient.java    From browser-switch-android with MIT License 6 votes vote down vote up
/**
 * Open a browser or <a href="https://developer.chrome.com/multidevice/android/customtabs">Chrome Custom Tab</a>
 * with the given intent from an Android activity.
 *
 * @param requestCode the request code used to differentiate requests from one another.
 * @param intent the intent to use to initiate a browser switch
 * @param activity the activity used to start browser switch
 * @param listener the listener that will receive browser switch callbacks
 */
public void start(
    int requestCode, Intent intent, FragmentActivity activity, BrowserSwitchListener listener) {
    Context appContext = activity.getApplicationContext();
    String errorMessage = assertCanPerformBrowserSwitch(requestCode, appContext, intent);
    if (errorMessage == null) {
        BrowserSwitchRequest request = new BrowserSwitchRequest(
                requestCode, intent.getData(), BrowserSwitchRequest.PENDING);
        persistentStore.putActiveRequest(request, appContext);
        appContext.startActivity(intent);
    } else {
        BrowserSwitchResult result =
            new BrowserSwitchResult(BrowserSwitchResult.STATUS_ERROR, errorMessage);
        listener.onBrowserSwitchResult(requestCode, result, null);
    }
}
 
Example 2
Source File: BrowserSwitchClient.java    From browser-switch-android with MIT License 6 votes vote down vote up
/**
 * Deliver a pending browser switch result to an Android activity that is also a BrowserSwitchListener.
 * We recommend you call this method in onResume to receive a browser switch result once your
 * app has re-entered the foreground.
 *
 * Cancel and Success results will be delivered only once. If there are no pending
 * browser switch results, this method does nothing.
 *
 * @param activity the BrowserSwitchListener that will receive a pending browser switch result
 * @param listener the listener that will receive browser switch callbacks
 */
public void deliverResult(FragmentActivity activity, BrowserSwitchListener listener) {
    Context appContext = activity.getApplicationContext();
    BrowserSwitchRequest request = persistentStore.getActiveRequest(appContext);
    if (request != null) {
        persistentStore.clearActiveRequest(appContext);
        int requestCode = request.getRequestCode();

        Uri uri = null;
        BrowserSwitchResult result;
        if (request.getState().equalsIgnoreCase(BrowserSwitchRequest.SUCCESS)) {
            uri = request.getUri();
            result = new BrowserSwitchResult(BrowserSwitchResult.STATUS_OK);
        } else {
            result = new BrowserSwitchResult(BrowserSwitchResult.STATUS_CANCELED);
        }
        listener.onBrowserSwitchResult(requestCode, result, uri);
    }
}
 
Example 3
Source File: BrowserSwitchClient.java    From browser-switch-android with MIT License 3 votes vote down vote up
/**
 * Open a browser or <a href="https://developer.chrome.com/multidevice/android/customtabs">Chrome Custom Tab</a>
 * with the given url from an Android activity.
 *
 * @param requestCode the request code used to differentiate requests from one another.
 * @param uri the url to open.
 * @param activity the activity used to start browser switch
 * @param listener the listener that will receive browser switch callbacks
 */
public void start(
    int requestCode, Uri uri, FragmentActivity activity, BrowserSwitchListener listener) {
    Context appContext = activity.getApplicationContext();
    Intent intent = config.createIntentToLaunchUriInBrowser(appContext, uri);
    start(requestCode, intent, activity, listener);
}