Java 类android.provider.Browser 实例源码

项目:PeSanKita-android    文件:ConversationActivity.java   
@Override
public void startActivity(Intent intent) {
  if (intent.getStringExtra(Browser.EXTRA_APPLICATION_ID) != null) {
    intent.removeExtra(Browser.EXTRA_APPLICATION_ID);
  }

  try {
    super.startActivity(intent);
  } catch (ActivityNotFoundException e) {
    Log.w(TAG, e);
    Toast.makeText(this, R.string.ConversationActivity_there_is_no_app_available_to_handle_this_link_on_your_device, Toast.LENGTH_LONG).show();
  }
}
项目:MainCalendar    文件:AboutActivity.java   
/**
     * 获取超链接字段
     * @return 超链接字符串
     */
    private SpannableString getClickableSpan(String aStr) {
        int startIndex = aStr.indexOf(mAuthorName);
        int endIndex = startIndex + mAuthorName.length();
        SpannableString spannableString = new SpannableString(aStr);
        //设置下划线文字
//        spannableString.setSpan(new UnderlineSpan(), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        //设置文字的单击事件
        spannableString.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                Uri uri = Uri.parse(mExtLink);
                Context context = widget.getContext();
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
                context.startActivity(intent);
            }
        }, startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        //设置文字的前景色
        spannableString.setSpan(new ForegroundColorSpan(ThemeStyle.Accent), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        return spannableString;
    }
项目:chromium-for-android-56-debug-video    文件:ConnectionInfoPopup.java   
@Override
public void onClick(View v) {
    if (mResetCertDecisionsButton == v) {
        nativeResetCertDecisions(mNativeConnectionInfoPopup, mWebContents);
        mDialog.dismiss();
    } else if (mCertificateViewer == v) {
        byte[][] certChain = nativeGetCertificateChain(mWebContents);
        if (certChain == null) {
            // The WebContents may have been destroyed/invalidated. If so,
            // ignore this request.
            return;
        }
        CertificateViewer.showCertificateChain(mContext, certChain);
    } else if (mMoreInfoLink == v) {
        mDialog.dismiss();
        try {
            Intent i = Intent.parseUri(mLinkUrl, Intent.URI_INTENT_SCHEME);
            i.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
            i.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName());
            mContext.startActivity(i);
        } catch (Exception ex) {
            // Do nothing intentionally.
            Log.w(TAG, "Bad URI %s", mLinkUrl, ex);
        }
    }
}
项目:chromium-for-android-56-debug-video    文件:BookmarkUtils.java   
private static void openUrl(Activity activity, String url, ComponentName componentName) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID,
            activity.getApplicationContext().getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK);

    if (componentName != null) {
        intent.setComponent(componentName);
    } else {
        // If the bookmark manager is shown in a tab on a phone (rather than in a separate
        // activity) the component name may be null. Send the intent through
        // ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
        intent.setClass(activity, ChromeLauncherActivity.class);
    }

    IntentHandler.startActivityForTrustedIntent(intent, activity);
}
项目:chromium-for-android-56-debug-video    文件:ContextualSearchQuickActionControl.java   
/**
 * Sends the intent associated with the quick action if one is available.
 */
public void sendIntent() {
    if (mIntent == null) return;
    mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Set the Browser application ID to us in case the user chooses Chrome
    // as the app from the intent picker.
    Context context = getContext();
    mIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    mIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    if (context instanceof ChromeTabbedActivity2) {
        // Set the window ID so the new tab opens in the correct window.
        mIntent.putExtra(IntentHandler.EXTRA_WINDOW_ID, 2);
    }

    IntentUtils.safeStartActivity(mContext, mIntent);
}
项目:chromium-for-android-56-debug-video    文件:Tab.java   
/**
 * @return Intent that tells Chrome to bring an Activity for a particular Tab back to the
 *         foreground, or null if this isn't possible.
 */
@Nullable
public static Intent createBringTabToFrontIntent(int tabId) {
    // Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a
    // {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded.
    List<WeakReference<Activity>> list = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> ref : list) {
        Activity activity = ref.get();
        if (activity instanceof CustomTabActivity
                && ((CustomTabActivity) activity).getActivityTab() != null
                && tabId == ((CustomTabActivity) activity).getActivityTab().getId()) {
            return null;
        }
    }

    String packageName = ContextUtils.getApplicationContext().getPackageName();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, packageName);
    intent.putExtra(TabOpenType.BRING_TAB_TO_FRONT.name(), tabId);
    intent.setPackage(packageName);
    return intent;
}
项目:chromium-for-android-56-debug-video    文件:IntentHandler.java   
/**
 * Returns a String (or null) containing the extra headers sent by the intent, if any.
 *
 * This methods skips the referrer header.
 *
 * @param intent The intent containing the bundle extra with the HTTP headers.
 */
public static String getExtraHeadersFromIntent(Intent intent) {
    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    StringBuilder extraHeaders = new StringBuilder();
    Iterator<String> keys = bundleExtraHeaders.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US))) continue;
        if (extraHeaders.length() != 0) extraHeaders.append("\n");
        extraHeaders.append(key);
        extraHeaders.append(": ");
        extraHeaders.append(value);
    }
    return extraHeaders.length() == 0 ? null : extraHeaders.toString();
}
项目:Cable-Android    文件:ConversationActivity.java   
@Override
public void startActivity(Intent intent) {
  if (intent.getStringExtra(Browser.EXTRA_APPLICATION_ID) != null) {
    intent.removeExtra(Browser.EXTRA_APPLICATION_ID);
  }

  try {
    super.startActivity(intent);
  } catch (ActivityNotFoundException e) {
    Log.w(TAG, e);
    Toast.makeText(this, R.string.ConversationActivity_there_is_no_app_available_to_handle_this_link_on_your_device, Toast.LENGTH_LONG).show();
  }
}
项目:inappbrowser-android    文件:ThemeableBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url
 * @return
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "ThemeableBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:AvI    文件:InAppBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url the url to load.
 * @return "" if ok, or error message.
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:Mediator_Android    文件:SafeURLSpan.java   
@Override
public void onClick(View widget) {
    try {
        final Uri uri = Uri.parse(getURL());
        final Context context = widget.getContext();
        if (uri.toString().contains("@")) {
            Intent emailIntent = new Intent(Intent.ACTION_SEND);
            emailIntent.putExtra(Intent.EXTRA_EMAIL, uri);
            emailIntent.setType("plain/text");
            context.startActivity(emailIntent);
        } else {
            final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            if (context != null) {
                intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
                context.startActivity(intent);
            }
        }
    } catch (android.content.ActivityNotFoundException ignored) {
        Toast.makeText(widget.getContext(), "No supported email client", Toast.LENGTH_LONG).show();
    } catch (Throwable ex) {

    }
}
项目:HybridAppReduxVsIonic    文件:InAppBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url the url to load.
 * @return "" if ok, or error message.
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:HybridAppReduxVsIonic    文件:InAppBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url the url to load.
 * @return "" if ok, or error message.
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:cordova-plugin-themeablebrowser    文件:ThemeableBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url
 * @return
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "ThemeableBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:medicineReminder    文件:InAppBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url the url to load.
 * @return "" if ok, or error message.
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:medicineReminder    文件:InAppBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url the url to load.
 * @return "" if ok, or error message.
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:cordova-plugin-inappbrowser    文件:InAppBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url the url to load.
 * @return "" if ok, or error message.
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:smart-mirror-app    文件:InAppBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url the url to load.
 * @return "" if ok, or error message.
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:smart-mirror-app    文件:InAppBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url the url to load.
 * @return "" if ok, or error message.
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:aptoide-client-v8    文件:CustomTabNativeReceiver.java   
@Override public void onReceive(Context context, Intent intent) {
  String url = intent.getDataString();

  if (url != null) {
    Set<String> listOfPackagesThatResolveUri = getNativeAppPackage(context, Uri.parse(url));
    String availableNativeAppPackageName = null;
    if (listOfPackagesThatResolveUri.iterator()
        .hasNext()) {
      availableNativeAppPackageName = listOfPackagesThatResolveUri.iterator()
          .next();
    }

    if (availableNativeAppPackageName != null) {
      Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
      Bundle httpHeaders = new Bundle();
      httpHeaders.putString(REFERER_ATTRIBUTE, REFERER_VALUE);
      launchIntent.putExtra(Browser.EXTRA_HEADERS, httpHeaders);
      launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(launchIntent);
    } else {
      Toast.makeText(context, "No application to open.", Toast.LENGTH_SHORT)
          .show();
    }
  }
}
项目:Clickers    文件:InAppBrowser.java   
/**
  * Display a new browser with the specified URL.
  *
  * @param url           The url to load.
  * @param usePhoneGap   Load url in PhoneGap webview
  * @return              "" if ok, or error message.
  */
 public String openExternal(String url) {
     try {
         Intent intent = null;
         intent = new Intent(Intent.ACTION_VIEW);
         // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
         // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
         Uri uri = Uri.parse(url);
         if ("file".equals(uri.getScheme())) {
             intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
         } else {
             intent.setData(uri);
         }
intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
         this.cordova.getActivity().startActivity(intent);
         return "";
     } catch (android.content.ActivityNotFoundException e) {
         Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
         return e.toString();
     }
 }
项目:Clickers    文件:InAppBrowser.java   
/**
  * Display a new browser with the specified URL.
  *
  * @param url           The url to load.
  * @param usePhoneGap   Load url in PhoneGap webview
  * @return              "" if ok, or error message.
  */
 public String openExternal(String url) {
     try {
         Intent intent = null;
         intent = new Intent(Intent.ACTION_VIEW);
         // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
         // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
         Uri uri = Uri.parse(url);
         if ("file".equals(uri.getScheme())) {
             intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
         } else {
             intent.setData(uri);
         }
intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
         this.cordova.getActivity().startActivity(intent);
         return "";
     } catch (android.content.ActivityNotFoundException e) {
         Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
         return e.toString();
     }
 }
项目:AndroidChromium    文件:ConnectionInfoPopup.java   
@Override
public void onClick(View v) {
    if (mResetCertDecisionsButton == v) {
        nativeResetCertDecisions(mNativeConnectionInfoPopup, mWebContents);
        mDialog.dismiss();
    } else if (mCertificateViewer == v) {
        byte[][] certChain = nativeGetCertificateChain(mWebContents);
        if (certChain == null) {
            // The WebContents may have been destroyed/invalidated. If so,
            // ignore this request.
            return;
        }
        CertificateViewer.showCertificateChain(mContext, certChain);
    } else if (mMoreInfoLink == v) {
        mDialog.dismiss();
        try {
            Intent i = Intent.parseUri(mLinkUrl, Intent.URI_INTENT_SCHEME);
            i.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
            i.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName());
            mContext.startActivity(i);
        } catch (Exception ex) {
            // Do nothing intentionally.
            Log.w(TAG, "Bad URI %s", mLinkUrl, ex);
        }
    }
}
项目:AndroidChromium    文件:BookmarkUtils.java   
private static void openUrl(Activity activity, String url, ComponentName componentName) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID,
            activity.getApplicationContext().getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK);

    if (componentName != null) {
        intent.setComponent(componentName);
    } else {
        // If the bookmark manager is shown in a tab on a phone (rather than in a separate
        // activity) the component name may be null. Send the intent through
        // ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
        intent.setClass(activity, ChromeLauncherActivity.class);
    }

    IntentHandler.startActivityForTrustedIntent(intent, activity);
}
项目:AndroidChromium    文件:ContextualSearchQuickActionControl.java   
/**
 * Sends the intent associated with the quick action if one is available.
 */
public void sendIntent() {
    if (mIntent == null) return;
    mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Set the Browser application ID to us in case the user chooses Chrome
    // as the app from the intent picker.
    Context context = getContext();
    mIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    mIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    if (context instanceof ChromeTabbedActivity2) {
        // Set the window ID so the new tab opens in the correct window.
        mIntent.putExtra(IntentHandler.EXTRA_WINDOW_ID, 2);
    }

    IntentUtils.safeStartActivity(mContext, mIntent);
}
项目:AndroidChromium    文件:Tab.java   
/**
 * @return Intent that tells Chrome to bring an Activity for a particular Tab back to the
 *         foreground, or null if this isn't possible.
 */
@Nullable
public static Intent createBringTabToFrontIntent(int tabId) {
    // Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a
    // {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded.
    List<WeakReference<Activity>> list = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> ref : list) {
        Activity activity = ref.get();
        if (activity instanceof CustomTabActivity
                && ((CustomTabActivity) activity).getActivityTab() != null
                && tabId == ((CustomTabActivity) activity).getActivityTab().getId()) {
            return null;
        }
    }

    String packageName = ContextUtils.getApplicationContext().getPackageName();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, packageName);
    intent.putExtra(TabOpenType.BRING_TAB_TO_FRONT.name(), tabId);
    intent.setPackage(packageName);
    return intent;
}
项目:AndroidChromium    文件:IntentHandler.java   
/**
 * Returns a String (or null) containing the extra headers sent by the intent, if any.
 *
 * This methods skips the referrer header.
 *
 * @param intent The intent containing the bundle extra with the HTTP headers.
 */
public static String getExtraHeadersFromIntent(Intent intent) {
    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    StringBuilder extraHeaders = new StringBuilder();
    Iterator<String> keys = bundleExtraHeaders.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US))) continue;
        if (extraHeaders.length() != 0) extraHeaders.append("\n");
        extraHeaders.append(key);
        extraHeaders.append(": ");
        extraHeaders.append(value);
    }
    return extraHeaders.length() == 0 ? null : extraHeaders.toString();
}
项目:PhoneChat    文件:InAppBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url the url to load.
 * @return "" if ok, or error message.
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:themeablebrowser    文件:ThemeableBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url
 * @return
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "ThemeableBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:Notepad    文件:InAppBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url the url to load.
 * @return "" if ok, or error message.
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:Notepad    文件:InAppBrowser.java   
/**
 * Display a new browser with the specified URL.
 *
 * @param url the url to load.
 * @return "" if ok, or error message.
 */
public String openExternal(String url) {
    try {
        Intent intent = null;
        intent = new Intent(Intent.ACTION_VIEW);
        // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
        // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
        Uri uri = Uri.parse(url);
        if ("file".equals(uri.getScheme())) {
            intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
        } else {
            intent.setData(uri);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
        this.cordova.getActivity().startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
        return e.toString();
    }
}
项目:RichEditor    文件:LinkSpan.java   
@Override
public void onClick(View widget) {
    String url = getURL();
    if (url.startsWith("www")) {
        url = "http://" + url;
    }
    Uri uri = Uri.parse(url);
    Context context = widget.getContext();
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    try {
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Log.w("LinkSpan", "Activity was not found for intent, " + intent.toString());
    }
}
项目:jianguo    文件:UrlUtils.java   
/**
 * 设置链接跳转与高亮样式
 *
 * @param url
 * @return
 */
private static ClickableSpan getClickableSpan(final String url) {
    return new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            Uri uri = Uri.parse(url);
            Context context = widget.getContext();
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
            context.startActivity(intent);
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setColor(Color.BLUE);
            ds.setUnderlineText(false);
        }
    };
}
项目:jianguo    文件:UrlUtils.java   
/**
 * 设置链接跳转与高亮样式
 *
 * @param url
 * @return
 */
private static ClickableSpan getClickableSpan(final String url) {
    return new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            Uri uri = Uri.parse(url);
            Context context = widget.getContext();
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
            context.startActivity(intent);
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setColor(Color.BLUE);
            ds.setUnderlineText(false);
        }
    };
}
项目:android_chat_UI    文件:UrlUtils.java   
/**
 * 设置链接跳转与高亮样式
 *
 * @param url
 * @return
 */
private static ClickableSpan getClickableSpan(final String url) {
    return new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            Uri uri = Uri.parse(url);
            Context context = widget.getContext();
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
            context.startActivity(intent);
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setColor(Color.BLUE);
            ds.setUnderlineText(false);
        }
    };
}
项目:Vafrinn    文件:TabRedirectHandler.java   
/**
 * Updates |mIntentHistory| and |mLastIntentUpdatedTime|. If |intent| comes from chrome and
 * currently |mIsOnEffectiveIntentRedirectChain| is true, that means |intent| was sent from
 * this tab because only the front tab or a new tab can receive an intent from chrome. In that
 * case, |intent| is added to |mIntentHistory|.
 * Otherwise, |mIntentHistory| and |mPreviousResolvers| are cleared, and then |intent| is put
 * into |mIntentHistory|.
 */
public void updateIntent(Intent intent) {
    clear();

    if (mContext == null || intent == null || !Intent.ACTION_VIEW.equals(intent.getAction())) {
        return;
    }

    String chromePackageName = mContext.getPackageName();
    // If an intent is heading explicitly to Chrome, we should stay in Chrome.
    if (TextUtils.equals(chromePackageName, intent.getPackage())
            || TextUtils.equals(chromePackageName, IntentUtils.safeGetStringExtra(intent,
                    Browser.EXTRA_APPLICATION_ID))) {
        mIsInitialIntentHeadingToChrome = true;
    }

    // Copies minimum information to retrieve resolvers.
    mInitialIntent = new Intent(Intent.ACTION_VIEW);
    mInitialIntent.setData(intent.getData());
    if (intent.getCategories() != null) {
        for (String category : intent.getCategories()) {
            mInitialIntent.addCategory(category);
        }
    }
}
项目:Vafrinn    文件:ConnectionInfoPopup.java   
@Override
public void onClick(View v) {
    if (mResetCertDecisionsButton == v) {
        nativeResetCertDecisions(mNativeConnectionInfoPopup, mWebContents);
        mDialog.dismiss();
    } else if (mCertificateViewer == v) {
        byte[][] certChain = nativeGetCertificateChain(mWebContents);
        if (certChain == null) {
            // The WebContents may have been destroyed/invalidated. If so,
            // ignore this request.
            return;
        }
        CertificateViewer.showCertificateChain(mContext, certChain);
    } else if (mMoreInfoLink == v) {
        mDialog.dismiss();
        try {
            Intent i = Intent.parseUri(mLinkUrl, Intent.URI_INTENT_SCHEME);
            i.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
            i.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName());
            mContext.startActivity(i);
        } catch (Exception ex) {
            // Do nothing intentionally.
            Log.w(TAG, "Bad URI " + mLinkUrl, ex);
        }
    }
}
项目:Vafrinn    文件:IntentHandler.java   
/**
 * Returns a String (or null) containing the extra headers sent by the intent, if any.
 *
 * This methods skips the referrer header.
 *
 * @param intent The intent containing the bundle extra with the HTTP headers.
 */
public static String getExtraHeadersFromIntent(Intent intent) {
    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    StringBuilder extraHeaders = new StringBuilder();
    Iterator<String> keys = bundleExtraHeaders.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US))) continue;
        if (extraHeaders.length() != 0) extraHeaders.append("\n");
        extraHeaders.append(key);
        extraHeaders.append(": ");
        extraHeaders.append(value);
    }
    return extraHeaders.length() == 0 ? null : extraHeaders.toString();
}
项目:multirotorstuff-vtx-calc    文件:InAppBrowser.java   
/**
  * Display a new browser with the specified URL.
  *
  * @param url           The url to load.
  * @param usePhoneGap   Load url in PhoneGap webview
  * @return              "" if ok, or error message.
  */
 public String openExternal(String url) {
     try {
         Intent intent = null;
         intent = new Intent(Intent.ACTION_VIEW);
         // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
         // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
         Uri uri = Uri.parse(url);
         if ("file".equals(uri.getScheme())) {
             intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
         } else {
             intent.setData(uri);
         }
intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
         this.cordova.getActivity().startActivity(intent);
         return "";
     } catch (android.content.ActivityNotFoundException e) {
         Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
         return e.toString();
     }
 }
项目:multirotorstuff-vtx-calc    文件:InAppBrowser.java   
/**
  * Display a new browser with the specified URL.
  *
  * @param url           The url to load.
  * @param usePhoneGap   Load url in PhoneGap webview
  * @return              "" if ok, or error message.
  */
 public String openExternal(String url) {
     try {
         Intent intent = null;
         intent = new Intent(Intent.ACTION_VIEW);
         // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
         // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
         Uri uri = Uri.parse(url);
         if ("file".equals(uri.getScheme())) {
             intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
         } else {
             intent.setData(uri);
         }
intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
         this.cordova.getActivity().startActivity(intent);
         return "";
     } catch (android.content.ActivityNotFoundException e) {
         Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
         return e.toString();
     }
 }