请帮助我,我已经开发了一个webview应用程序,其中我添加了Instagram链接但我无法打开该(+)标志以在其他网站上添加图像,因此我无法打开任何网站。
import android.Manifest;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class WebviewActivity extends AppCompatActivity {
ConnectionDetector cd;
static InterstitialAd mInterstitialAd;
AdView adView;
Spinner spUrls;
WebView webView;
ProgressBar pb;
TextView tvGo;
long time=0;
String[] urls;
String url="https://facebook.com/";
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
getSupportActionBar().hide();
cd=new ConnectionDetector(this);
spUrls=(Spinner)findViewById(R.id.spUrls);
webView=(WebView)findViewById(R.id.webView);
tvGo=(TextView)findViewById(R.id.tvGo);
pb=(ProgressBar)findViewById(R.id.msw_progress);
urls=getResources().getStringArray(R.array.urls);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAllowFileAccessFromFileURLs(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webView.getSettings().setAppCacheEnabled(false);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
if(cd.isConnectingToInternet()) {
webView.loadUrl(url);
}else{
Toast.makeText(this,"PLEASE CHECK YOUR INTERNET CONNECTION",Toast.LENGTH_LONG).show();
}
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
pb.setProgress(progress);
if(progress==0)
pb.setProgress(0);
//Make the bar disappear after URL is loaded, and changes string to Loading...
/*setTitle("Loading...");
setProgress(progress * 100); //Make the bar disappear after URL is loaded
// Return the app name after finish loading
if(progress == 100)
setTitle(R.string.app_name);*/
}
});
WebView wv=new WebView(this);
wv.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
//Required functionality here
return super.onJsAlert(view, url, message, result);
}
});
adView=(AdView)findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-*******"); // Seems like you may be exposing your ad unit id to the public, may be better to keep this a secret or use the testing id found in the admob docs
mInterstitialAd.loadAd(new AdRequest.Builder().build());
tvGo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
url=urls[spUrls.getSelectedItemPosition()];
if(cd.isConnectingToInternet()) {
webView.loadUrl(url);
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}else{
Toast.makeText(WebviewActivity.this,"PLEASE CHECK YOUR INTERNET CONNECTION",Toast.LENGTH_LONG).show();
}
}
});
}
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
if((System.currentTimeMillis()-time)<2000){
super.onBackPressed();
}else{
Toast.makeText(this, "PRESS AGAIN TO EXIT", Toast.LENGTH_SHORT).show();
}
time=System.currentTimeMillis();
}
}
@Override
protected void onResume() {
super.onResume();
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
}
在这里你可以看到我所有的webview代码,请尽快告诉我解决方案
答案 0 :(得分:0)
也许可以尝试查看有关在webview中显示弹出窗口的This Stack Overflow帖子。
我认为你的关键是该帖子中的以下代码:
WebView newWebView = new WebView(WebpageActivity.this);
newWebView.getSettings().setJavaScriptEnabled(true);
newWebView.getSettings().setSupportZoom(true);
newWebView.getSettings().setBuiltInZoomControls(true);
newWebView.getSettings().setPluginState(PluginState.ON);
newWebView.getSettings().setSupportMultipleWindows(true);
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
newWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
希望这有帮助。