當前位置: 首頁>>代碼示例>>Java>>正文


Java Browser類代碼示例

本文整理匯總了Java中android.provider.Browser的典型用法代碼示例。如果您正苦於以下問題:Java Browser類的具體用法?Java Browser怎麽用?Java Browser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Browser類屬於android.provider包,在下文中一共展示了Browser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startActivity

import android.provider.Browser; //導入依賴的package包/類
@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();
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:14,代碼來源:ConversationActivity.java

示例2: getClickableSpan

import android.provider.Browser; //導入依賴的package包/類
/**
     * 獲取超鏈接字段
     * @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;
    }
 
開發者ID:mainh,項目名稱:MainCalendar,代碼行數:27,代碼來源:AboutActivity.java

示例3: onClick

import android.provider.Browser; //導入依賴的package包/類
@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);
        }
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:27,代碼來源:ConnectionInfoPopup.java

示例4: openUrl

import android.provider.Browser; //導入依賴的package包/類
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);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:19,代碼來源:BookmarkUtils.java

示例5: sendIntent

import android.provider.Browser; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:20,代碼來源:ContextualSearchQuickActionControl.java

示例6: createBringTabToFrontIntent

import android.provider.Browser; //導入依賴的package包/類
/**
 * @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;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:26,代碼來源:Tab.java

示例7: getExtraHeadersFromIntent

import android.provider.Browser; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:24,代碼來源:IntentHandler.java

示例8: openExternal

import android.provider.Browser; //導入依賴的package包/類
/**
 * 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();
    }
}
 
開發者ID:archriss,項目名稱:inappbrowser-android,代碼行數:27,代碼來源:ThemeableBrowser.java

示例9: openExternal

import android.provider.Browser; //導入依賴的package包/類
/**
 * 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();
    }
}
 
開發者ID:smukov,項目名稱:AvI,代碼行數:27,代碼來源:InAppBrowser.java

示例10: onClick

import android.provider.Browser; //導入依賴的package包/類
@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) {

    }
}
 
開發者ID:bvblogic,項目名稱:Mediator_Android,代碼行數:24,代碼來源:SafeURLSpan.java

示例11: onReceive

import android.provider.Browser; //導入依賴的package包/類
@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();
    }
  }
}
 
開發者ID:Aptoide,項目名稱:aptoide-client-v8,代碼行數:26,代碼來源:CustomTabNativeReceiver.java

示例12: openExternal

import android.provider.Browser; //導入依賴的package包/類
/**
  * 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();
     }
 }
 
開發者ID:GeoThings,項目名稱:Clickers,代碼行數:28,代碼來源:InAppBrowser.java

示例13: onClick

import android.provider.Browser; //導入依賴的package包/類
@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());
    }
}
 
開發者ID:zzhoujay,項目名稱:RichEditor,代碼行數:17,代碼來源:LinkSpan.java

示例14: getClickableSpan

import android.provider.Browser; //導入依賴的package包/類
/**
 * 設置鏈接跳轉與高亮樣式
 *
 * @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);
        }
    };
}
 
開發者ID:woniukeji,項目名稱:jianguo,代碼行數:26,代碼來源:UrlUtils.java

示例15: updateIntent

import android.provider.Browser; //導入依賴的package包/類
/**
 * 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);
        }
    }
}
 
開發者ID:Smalinuxer,項目名稱:Vafrinn,代碼行數:33,代碼來源:TabRedirectHandler.java


注:本文中的android.provider.Browser類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。