Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.content.Intent;

import android.net.Uri;

public class Main {
    private static Context sCurrentContext;

    /**
     * <pre>
     * Open other app to view URL of an app (typically browser or Google Play)
     * </pre>
     * @param downloadUrl
     */
    public static void openDownloadPage(String downloadUrl) {
        Context context = getCurrentContext();
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse(downloadUrl));
        context.startActivity(intent);
    }

    /**
     * <pre>
     * Get current context of the app. This method resolves the inconvenience of Android which requires context for most of its API.
     * If no activity is resumed, this method returns application context. Otherwise, this method returns last resumed activity.
     * </pre>
     */
    public static Context getCurrentContext() {
        return sCurrentContext;
    }
}