Java Code Examples for android.support.v4.content.ContextCompat#startActivity()

The following examples show how to use android.support.v4.content.ContextCompat#startActivity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowserActionsIntent.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
/** @hide */
@RestrictTo(LIBRARY_GROUP)
@VisibleForTesting
static void launchIntent(Context context, Intent intent, List<ResolveInfo> handlers) {
    if (handlers == null || handlers.size() == 0) {
        openFallbackBrowserActionsMenu(context, intent);
        return;
    } else if (handlers.size() == 1) {
        intent.setPackage(handlers.get(0).activityInfo.packageName);
    } else {
        Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(TEST_URL));
        PackageManager pm = context.getPackageManager();
        ResolveInfo defaultHandler =
                pm.resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY);
        if (defaultHandler != null) {
            String defaultPackageName = defaultHandler.activityInfo.packageName;
            for (int i = 0; i < handlers.size(); i++) {
                if (defaultPackageName.equals(handlers.get(i).activityInfo.packageName)) {
                    intent.setPackage(defaultPackageName);
                    break;
                }
            }
        }
    }
    ContextCompat.startActivity(context, intent, null);
}
 
Example 2
Source File: AboutFragment.java    From ESeal with Apache License 2.0 5 votes vote down vote up
private void processInstallApk(Context context, String path) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(new File(path)),
            "application/vnd.android.package-archive");
    ContextCompat.startActivity(context, intent, null);
}
 
Example 3
Source File: DownloadService.java    From ESeal with Apache License 2.0 5 votes vote down vote up
private void processInstallApk(Context context, String path) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(new File(path)),
            "application/vnd.android.package-archive");
    ContextCompat.startActivity(context, intent, null);
}
 
Example 4
Source File: AboutFragment.java    From ESeal with Apache License 2.0 5 votes vote down vote up
private void processInstallApk(Context context, String path) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(new File(path)),
            "application/vnd.android.package-archive");
    ContextCompat.startActivity(context, intent, null);
}
 
Example 5
Source File: DownloadService.java    From ESeal with Apache License 2.0 5 votes vote down vote up
private void processInstallApk(Context context, String path) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(new File(path)),
            "application/vnd.android.package-archive");
    ContextCompat.startActivity(context, intent, null);
}
 
Example 6
Source File: TwaLauncher.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
private void launchWhenSplashScreenReady(TrustedWebActivityIntentBuilder builder,
        @Nullable Runnable completionCallback) {
    Log.d(TAG, "Launching Trusted Web Activity.");
    Intent intent = builder.build(mSession);
    ContextCompat.startActivity(mContext, intent, null);
    // Remember who we connect to as the package that is allowed to delegate notifications
    // to us.
    TrustedWebActivityService.setVerifiedProvider(mContext, mProviderPackage);
    if (completionCallback != null) {
        completionCallback.run();
    }
}
 
Example 7
Source File: BrowserActionsIntent.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Open a Browser Actions menu with default settings.
 * It first checks if any Browser Actions provider is available to create a context menu.
 * If not, open a Browser Actions menu locally from support library.
 * @param context The context requesting for a Browser Actions menu.
 * @param uri The url for Browser Actions menu.
 */
public static void openBrowserAction(Context context, Uri uri) {
    if (hasBrowserActionsIntentHandler(context)) {
        BrowserActionsIntent intent = new BrowserActionsIntent.Builder(context, uri).build();
        ContextCompat.startActivity(context, intent.getIntent(), null);
    } else {
        openFallbackBrowserActionsMenu(
                context, uri, URL_TYPE_NONE, new ArrayList<BrowserActionItem>());
    }
}
 
Example 8
Source File: BrowserActionsIntent.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Open a Browser Actions menu with custom items.
 * It first checks if any Browser Actions provider is available to create a context menu.
 * If not, open a Browser Actions menu locally from support library.
 * @param context The context requesting for a Browser Actions menu.
 * @param uri The url for Browser Actions menu.
 * @param type The type of the url for context menu to be opened.
 * @param items List of custom items to be added to Browser Actions menu.
 */
public static void openBrowserAction(
        Context context, Uri uri, int type, ArrayList<BrowserActionItem> items) {
    if (hasBrowserActionsIntentHandler(context)) {
        BrowserActionsIntent intent = new BrowserActionsIntent.Builder(context, uri)
                                                  .setUrlType(type)
                                                  .setCustomItems(items)
                                                  .build();
        ContextCompat.startActivity(context, intent.getIntent(), null);
    } else {
        openFallbackBrowserActionsMenu(context, uri, type, items);
    }
}
 
Example 9
Source File: DownloadService.java    From ESeal with Apache License 2.0 4 votes vote down vote up
private void processUninstallApk(Context context, String packageName) {
    Uri uri = Uri.parse("package:" + packageName);
    Intent intent = new Intent(Intent.ACTION_DELETE, uri);
    ContextCompat.startActivity(context, intent, null);
}
 
Example 10
Source File: DownloadService.java    From ESeal with Apache License 2.0 4 votes vote down vote up
private void processUninstallApk(Context context, String packageName) {
    Uri uri = Uri.parse("package:" + packageName);
    Intent intent = new Intent(Intent.ACTION_DELETE, uri);
    ContextCompat.startActivity(context, intent, null);
}
 
Example 11
Source File: CustomTabsIntent.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Convenience method to launch a Custom Tabs Activity.
 * @param context The source Context.
 * @param url The URL to load in the Custom Tab.
 */
public void launchUrl(Context context, Uri url) {
    intent.setData(url);
    ContextCompat.startActivity(context, intent, startAnimationBundle);
}
 
Example 12
Source File: CustomTabsIntent.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Convenience method to launch a Custom Tabs Activity.
 * @param context The source Context.
 * @param url The URL to load in the Custom Tab.
 */
public void launchUrl(Context context, Uri url) {
    intent.setData(url);
    ContextCompat.startActivity(context, intent, startAnimationBundle);
}
 
Example 13
Source File: CustomTabsIntent.java    From custom-tabs-client with Apache License 2.0 2 votes vote down vote up
/**
 * Convenience method to launch a Custom Tabs Activity.
 * @param context The source Context.
 * @param url The URL to load in the Custom Tab.
 */
public void launchUrl(Context context, Uri url) {
    intent.setData(url);
    ContextCompat.startActivity(context, intent, startAnimationBundle);
}
 
Example 14
Source File: CustomTabsIntent.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Convenience method to launch a Custom Tabs Activity.
 * @param context The source Context.
 * @param url The URL to load in the Custom Tab.
 */
public void launchUrl(Context context, Uri url) {
    intent.setData(url);
    ContextCompat.startActivity(context, intent, startAnimationBundle);
}