Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.List;

import android.content.Context;

import android.content.Intent;

import android.content.pm.PackageManager;

import android.content.pm.ResolveInfo;

import android.net.Uri;
import android.widget.Toast;

public class Main {
    public static void getMoreApps(Context context, String publisherName) {
        Intent intent = new Intent(Intent.ACTION_VIEW, getMoreAppsUri(publisherName));

        if (isIntentAvailable(context, intent)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        } else {
            Toast.makeText(context, "Network Error", Toast.LENGTH_LONG).show();
        }
    }

    private static Uri getMoreAppsUri(String publisherName) {
        return Uri.parse("market://search?q=pub:" + publisherName);
    }

    public static boolean isIntentAvailable(Context ctx, Intent in) {
        PackageManager packageManager = ctx.getPackageManager();
        List<ResolveInfo> activities = packageManager.queryIntentActivities(in, 0);
        return (activities == null) ? false : (activities.size() > 0);
    }
}