Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class Main {
    public static final String BERRYMOTES_NAME = "com.trellmor.berrymotes";

    /**
     * Check if BerryMotes app is installed 
     * 
     * @param context Android context
     * @return true if BerryMotes is installed
     */
    public static boolean isBerryMotesInstalled(Context context) {
        PackageManager pm = context.getPackageManager();
        try {
            pm.getPackageInfo(BERRYMOTES_NAME, PackageManager.GET_ACTIVITIES);
            return true;
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }

    /**
     * Check if BerryMotes app is installed 
     * 
     * @param context Android context
     * @param version BerryMotes version
     * @return true if BerryMotes is installed
     */
    public static boolean isBerryMotesInstalled(Context context, int version) {
        PackageManager pm = context.getPackageManager();
        try {
            PackageInfo pi = pm.getPackageInfo(BERRYMOTES_NAME, PackageManager.GET_ACTIVITIES);
            return pi.versionCode >= version;
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }
}