Android共享内容
我正在尝试读取当前网址并与其他应用程序共享。 如何读取私有意图文件共享()中字符串currentUrl的内容Android共享内容,android,Android,我正在尝试读取当前网址并与其他应用程序共享。 如何读取私有意图文件共享()中字符串currentUrl的内容 private class MyCustomWebViewClient extends WebViewClient { String currentUrl; @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { vi
private class MyCustomWebViewClient extends WebViewClient {
String currentUrl;
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
currentUrl=url;
return true;
}
}
...
private Intent doShare() {
String SMessage1 = "xxx" ;
String SMessage2 = "xxx" ;
String SMessage3 = "xxx" ;
String SMessage5 = "xxx" ;
String SMessage6 = "xxx" ;
String SMessage7 = "xxx" ;
String SMessage8 = "xxx" ;
String SMessage9 = "xxx" ;
String SMessage10 = "xxx" ;
String SMessage11 = "xxx" ;
String SMessage12 = "xxx" ;
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, SMessage1 +"\n"+ SMessage2 +"\n"+ SMessage3 +"\n"+ currentUrl +"\n"+ SMessage5 +"\n"+ SMessage6 +"\n"+ SMessage7 +"\n"+ SMessage8 +"\n"+ SMessage9 +"\n"+ SMessage10 +"\n"+ SMessage11 +"\n"+ SMessage12);
return intent;
}
// Call to update the share intent
private void setShareIntent(Intent shareIntent) {
if (mShareActionProvider != null) {
mShareActionProvider.setShareIntent(shareIntent);
}
}
您没有提供该类的完整代码。我猜
MyCustomWebViewClient
是活动的私有内部类,其中doShare()
是该活动的方法。在这种情况下,将String currentUrl
移动为活动的数据成员,而不是MyCustomWebViewClient
的数据成员MyCustomWebViewClient
仍将能够访问它,但它也将可用于doShare()
方法。您的解决方案工作正常,但现在当我共享currentUrl的内容时,我收到文本“null”,不明白原因。@RuiBranco:确保您没有将currentUrl
重置为null
。请确保您没有多个名为currentUrl
@RuiBranco:那么我就没有办法帮助您了。doShare()
中的currentUrl
为null
,或者您的doShare()
实现中存在一些问题。看起来,当前URL在任何地方都是null。我可以发布整个代码,这样我们就可以确定问题所在了???@RuiBranco:我建议你在发布整个代码的地方问一个单独的堆栈溢出问题。