本文整理汇总了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();
}
}
示例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;
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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) {
}
}
示例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();
}
}
}
示例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();
}
}
示例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());
}
}
示例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);
}
};
}
示例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);
}
}
}