Example usage for android.app Activity getPackageManager

List of usage examples for android.app Activity getPackageManager

Introduction

In this page you can find the example usage for android.app Activity getPackageManager.

Prototype

@Override
    public PackageManager getPackageManager() 

Source Link

Usage

From source file:dentex.youtube.downloader.utils.Utils.java

public static int getSigHash(Activity act) {
    int currentHash = 0;
    try {/*from   w  w  w .ja  va 2s. c o  m*/
        Signature[] sigs = act.getPackageManager().getPackageInfo(act.getPackageName(),
                PackageManager.GET_SIGNATURES).signatures;

        for (Signature sig : sigs) {
            currentHash = sig.hashCode();
            logger("d", "getSigHash: App signature " + currentHash, DEBUG_TAG);
        }
    } catch (NameNotFoundException e) {
        Log.e(DEBUG_TAG, "getSigHash: App signature not found; " + e.getMessage());
    }
    return currentHash;
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * View Tumblr profile//from   ww  w . j  a  va2 s . c o  m
 *
 * @param activity context
 * @param userId   tumblr user id
 */
public static void launchTumblrIntent(Activity activity, String userId) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {
        activity.getPackageManager().getPackageInfo("com.tumblr", 0);
        intent.setData(Uri.parse(
                "http://www.tumblr" + ".com/open/app?referrer=mobActivityCompat.postponeEnterTransition(this);"
                        + "ile_banner&app_args=blog%3FblogName%3D" + userId + "%26page%3Dblog"));
    } catch (Exception e) {
        intent.setData(Uri.parse("http://" + userId + ".tumblr.com"));
    }
    activity.startActivity(intent);
}

From source file:info.papdt.blacklight.support.Utility.java

public static void initDarkMode(Activity activity) {
    if (isDarkMode(activity)) {
        int theme = 0;

        try {//from www .  j  a v a 2 s  .  c  o m
            theme = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0).theme;
        } catch (NameNotFoundException e) {
            return;
        }

        // Convert to dark theme
        if (theme == R.style.BL_Theme_Light) {
            theme = R.style.BL_Theme_Dark;
        } else if (theme == R.style.BL_Theme_Light_Translucent) {
            theme = R.style.BL_Theme_Dark_Translucent;
        } else if (theme == R.style.BL_Theme_Light_TranslucentActionBar_NoTranslucent) {
            theme = R.style.BL_Theme_Dark_TranslucentActionBar_NoTranslucent;
        } else if (theme == R.style.BL_Theme_Light_TranslucentActionBar) {
            theme = R.style.BL_Theme_Dark_TranslucentActionBar;
        } else if (theme == R.style.BL_Theme_Light_GradientActionBar) {
            theme = R.style.BL_Theme_Dark_GradientActionBar;
        } else if (theme == R.style.BL_Theme_Light_WithNav) {
            theme = R.style.BL_Theme_Dark_WithNav;
        }

        activity.setTheme(theme);
    }
}

From source file:com.android.browser.DownloadHandler.java

/**
 * Notify the host application a download should be done, or that
 * the data should be streamed if a streaming viewer is available.
 * @param activity Activity requesting the download.
 * @param url The full url to the content that should be downloaded
 * @param userAgent User agent of the downloading application.
 * @param contentDisposition Content-disposition http header, if present.
 * @param mimetype The mimetype of the content reported by the server
 * @param referer The referer associated with the downloaded url
 * @param privateBrowsing If the request is coming from a private browsing tab.
 */// w  w w  .ja  va2s .c  om
public static void onDownloadStart(Activity activity, String url, String userAgent, String contentDisposition,
        String mimetype, String referer, boolean privateBrowsing) {
    // if we're dealing wih A/V content that's not explicitly marked
    //     for download, check if it's streamable.
    if (contentDisposition == null || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) {
        // query the package manager to see if there's a registered handler
        //     that matches.
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.parse(url), mimetype);
        ResolveInfo info = activity.getPackageManager().resolveActivity(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (info != null) {
            ComponentName myName = activity.getComponentName();
            // If we resolved to ourselves, we don't want to attempt to
            // load the url only to try and download it again.
            if (!myName.getPackageName().equals(info.activityInfo.packageName)
                    || !myName.getClassName().equals(info.activityInfo.name)) {
                // someone (other than us) knows how to handle this mime
                // type with this scheme, don't download.
                try {
                    activity.startActivity(intent);
                    return;
                } catch (ActivityNotFoundException ex) {
                    if (LOGD_ENABLED) {
                        Log.d(LOGTAG,
                                "activity not found for " + mimetype + " over " + Uri.parse(url).getScheme(),
                                ex);
                    }
                    // Best behavior is to fall back to a download in this
                    // case
                }
            }
        }
    }
    onDownloadStartNoStream(activity, url, userAgent, contentDisposition, mimetype, referer, privateBrowsing);
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * View Whats App profile/* w w  w  .j a  v a  2  s . co  m*/
 *
 * @param activity context
 * @param address  whats app number
 */
public static void launchWhatsAppIntent(Activity activity, String address) {
    Intent intent = new Intent();
    intent.setPackage("com.whatsapp");
    intent.setData(Uri.parse("smsto:" + address));
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        activity.startActivity(intent);
    }
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * View yo profile/*from   w  ww. ja  v  a2 s .  c  om*/
 *
 * @param activity context
 * @param username yo username
 */
public static void launchYoIntent(Activity activity, String username) {
    Intent intent = new Intent();
    intent.setData(Uri.parse("yo:add:" + username));

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        activity.startActivity(intent);
    }
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * View skype profile/*w ww.  j a  v a2  s.  co m*/
 *
 * @param activity context
 * @param username skype username
 */
public static void launchSkypeIntent(Activity activity, String username) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("skype:" + username));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        activity.startActivity(intent);
    }
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * Launch the Dialer App./*from ww w  .  java  2s .  c  o  m*/
 *
 * @param activity    context
 * @param phoneNumber to dial
 */
public static void launchPhoneIntent(Activity activity, String phoneNumber) {
    Intent intent = new Intent(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel:" + phoneNumber));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        activity.startActivity(intent);
    }
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * Send SMS to phone number.//from  w  w  w .j a va  2 s  .  c om
 *
 * @param activity    context
 * @param phoneNumber to sms
 */
public static void launchSMSIntent(Activity activity, String phoneNumber) {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("smsto:" + phoneNumber));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        activity.startActivity(intent);
    }
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * View facebook help page./*from   w w  w .j a v a2 s  .c om*/
 *
 * @param activity context
 */
public static void launchFacebookHelpIntent(Activity activity) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http:www.facebook.com/help/211813265517027"));

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        activity.startActivity(intent);
    }
}