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 {
    /**
     * Method to get more apps
     * 
     * @param context
     * @param publisherName
     */
    public static void getMoreApps(Context context, String publisherName) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:" + publisherName));
        if (isIntentAvailable(context, intent)) {
            context.startActivity(intent);
        } else {
            Toast.makeText(context, "Network Error", Toast.LENGTH_LONG).show();
        }
    }

    /**
     * Method to get weather the intent is available in system to perform
     * specified operation
     * 
     * @param ctx
     * @param in
     * @return
     */
    private 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);
    }
}