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.app.Activity;
import android.content.Context;
import android.content.Intent;

import android.content.pm.PackageManager;

public class Main {
    private static String ANDROID_TV_LIVE_CHANNELS = "com.google.android.tv";
    private static String SONY_LIVE_CHANNELS = "com.sony.dtv.tvplayer";

    public static boolean hasLiveChannels(Activity mActivity) {
        return getLiveChannels(mActivity) != null;
    }

    public static Intent getLiveChannels(Activity mActivity) {
        if (isPackageInstalled(ANDROID_TV_LIVE_CHANNELS, mActivity)) {
            Intent i = mActivity.getPackageManager().getLaunchIntentForPackage(ANDROID_TV_LIVE_CHANNELS);
            return i;
        } else if (isPackageInstalled(SONY_LIVE_CHANNELS, mActivity)) {
            Intent i = mActivity.getPackageManager().getLaunchIntentForPackage(SONY_LIVE_CHANNELS);
            return i;
        }
        return null;
    }

    private static boolean isPackageInstalled(String packagename, Context context) {
        PackageManager pm = context.getPackageManager();
        try {
            pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
            return true;
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }
}