[英]Context for .launchUrl in outsourced helper class
我在外包类的方法launchUrl中遇到上下文问题。 我在应用程序中使用了多个类别的Chrome自定义标签,并且我将对所有“自定义标签”意图使用一种方法。
这是我的助手:
public void openCustemTab(String url, Context context) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(context.getResources().getColor(R.color.colorPrimary));
builder.setShowTitle(true);
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(context, Uri.parse(url));
}
这是我的活动/片段中的调用:
Helper helper = new Helper();
helper.openCustemTab("Some URL", getApplicationContext());
我的问题是,.launchUrl方法openCustomTab中的上下文不起作用。 有人对我的问题有想法吗?
这是因为launchUrl参数是Activity(不是Context)和Uri。 如您在这里看到的: void launchUrl(活动上下文,Uri url)
您可以替换:
customTabsIntent.launchUrl(context, Uri.parse(url));
与
customTabsIntent.intent.setData(Uri.parse(url));
context.startActivity(customTabsIntent.intent, customTabsIntent.startAnimationBundle);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.