<commit_before>package com.jdroid.android.utils;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import com.jdroid.android.AbstractApplication;

public class ExternalAppsUtils {
	
	public static final String TWITTER_PACKAGE_NAME = "com.twitter.android";
	public static final String FACEBOOK_PACKAGE_NAME = "com.facebook.katana";
	public static final String WHATSAPP_PACKAGE_NAME = "com.whatsapp";
	public static final String TELEGRAM_PACKAGE_NAME = "org.telegram.messenger";
	public static final String HANGOUTS_PACKAGE_NAME = "com.google.android.talk";
	public static final String GOOGLE_PLUS_PACKAGE_NAME = "com.google.android.apps.plus";
	
	public static boolean isAppInstalled(Context context, String packageName) {
		PackageManager pm = context.getPackageManager();
		boolean installed = false;
		try {
			pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
			installed = true;
		} catch (PackageManager.NameNotFoundException e) {
			installed = false;
		}
		return installed;
	}
	
	/**
	 * Launch packageName app or open Google Play to download.
	 * 
	 * @param context
	 * @param packageName
	 * @return true if app is installed, false otherwise.
	 */
	public static boolean launchOrDownloadApp(Context context, String packageName) {
		boolean isAppInstalled = isAppInstalled(context, packageName);
		if (isAppInstalled) {
			launchExternalApp(context, packageName);
		} else {
			GooglePlayUtils.launchAppDetails(context, packageName);
		}
		return isAppInstalled;
	}
	
	public static void launchExternalApp(Context context, String packageName) {
		Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
		context.startActivity(launchIntent);
	}
	
	public static void startSkypeCall(String username) {
		Intent skypeIntent = new Intent(Intent.ACTION_VIEW);
		skypeIntent.setData(Uri.parse("skype:" + username + "?call"));<commit_msg>Fixed "package manager has died" error<commit_after>package com.jdroid.android.utils;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import com.jdroid.android.AbstractApplication;

public class ExternalAppsUtils {
	
	public static final String TWITTER_PACKAGE_NAME = "com.twitter.android";
	public static final String FACEBOOK_PACKAGE_NAME = "com.facebook.katana";
	public static final String WHATSAPP_PACKAGE_NAME = "com.whatsapp";
	public static final String TELEGRAM_PACKAGE_NAME = "org.telegram.messenger";
	public static final String HANGOUTS_PACKAGE_NAME = "com.google.android.talk";
	public static final String GOOGLE_PLUS_PACKAGE_NAME = "com.google.android.apps.plus";
	
	public static boolean isAppInstalled(Context context, String packageName) {
		PackageManager pm = context.getPackageManager();
		boolean installed = false;
		try {
			pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
			installed = true;
		} catch (PackageManager.NameNotFoundException e) {
			installed = false;
		} catch (RuntimeException e) {
			if (e.getMessage().equals("Package manager has died")) {
				AbstractApplication.get().getExceptionHandler().logWarningException(
					"Runtime error while loading package info", e);
			} else {
				throw e;
			}
		}
		return installed;
	}
	
	/**
	 * Launch packageName app or open Google Play to download.
	 * 
	 * @param context
	 * @param packageName
	 * @return true if app is installed, false otherwise.
	 */
	public static boolean launchOrDownloadApp(Context context, String packageName) {
		boolean isAppInstalled = isAppInstalled(context, packageName);
		if (isAppInstalled) {
			launchExternalApp(context, packageName);
		} else {
			GooglePlayUtils.launchAppDetails(context, packageName);
		}
		return isAppInstalled;
	}
	
	public static void launchExternalApp(Context context, String packageName) {
		Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
		context.startActivity(launchIntent);
	}
	
	public static void startSkypeCall(String username) {
		Intent skypeIntent = new Intent(Intent.ACTION_VIEW);
		skypeIntent.setData(Uri.parse("skype:" + username + "?call"));
{'fraction_non_alphanumeric': 0.09078590785907859, 'fraction_numerical': 0.0, 'mean_word_length': 5.4002890173410405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5219907', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1240, 'n_words': 311}