0

i have implemented a Custom URL Span to open link with the chrome custom tab instead of default browser. The on click method of it is started, but I dont know how to launch the chrome custom launcher.

it looks this way:

public class CustomTabsURLSpan extends URLSpan {

Context context;
public CustomTabsURLSpan(String url) {

    super(url);
    Log.d("SensibleUrlSpan", "1");
}

public CustomTabsURLSpan(Parcel src) {
    super(src);
    Log.d("SensibleUrlSpan", "2");
}

@Override
public void onClick(View widget) {
    Log.d("SensibleUrlSpan", "3");
    String url = getURL();

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    CustomTabsIntent customTabsIntent = builder.build();
    customTabsIntent.launchUrl(context, Uri.parse(url));


}

}

I get a null reference error when calling this, I think its a problem with the context.

4

1 回答 1

0

你没有初始化context任何东西,所以它总是null.

于 2018-03-09T00:20:51.477 回答