简单的问题。我正在使用webview显示我有照片的页面。问题是当我使用我使用的网站意图时,它只显示一个空白页面。我不知道问题出在哪里,因为当我在浏览器上使用这个网站时它会起作用。所以这是我使用的解决方案
@Override
protected void onCreate(Bundle savedInstanceState) {
themeInfo = getSharedPreferences("THEMECONFIG",0);
themeSetting = themeInfo.getString("theme","Základná");
processer = new ProcessFunction();
try {
ConnectivityManager con = (ConnectivityManager) getSystemService(context.CONNECTIVITY_SERVICE);
NetworkInfo net = con.getActiveNetworkInfo();
String web;
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
if (net != null && net.isConnected()) {
if (processer.isOnline()) {
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
@Override
public void onDrawerOpened(View drawerView) {
fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_arrow_left));
}
@Override
public void onDrawerClosed(View drawerView) {
fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_arrow_right));
}
@Override
public void onDrawerStateChanged(int newState) {
}
});
toggle.syncState();
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
processer = new ProcessFunction();
fab = (FloatingActionButton) findViewById(R.id.fab);
MultiTouchListener touchListener=new MultiTouchListener(this);
fab.setOnTouchListener(touchListener);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!drawer.isDrawerVisible(GravityCompat.START))
{
drawer.openDrawer(Gravity.LEFT);
fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_arrow_left));
}
else
{
fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_arrow_right));
}
}
});
if (getIntent().getStringExtra("website") == null) {
web = "http://www.lodkanadeje.maweb.eu/";
} else {
web = getIntent().getStringExtra("website");
}
wv = (WebView) findViewById(R.id.webb);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
progressBar.getIndeterminateDrawable().setColorFilter(Color.LTGRAY, PorterDuff.Mode.MULTIPLY);
progressBar.setScaleY(0.1f);
progressBar.setScaleX(0.1f);
progressBar.setVisibility(View.VISIBLE);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setDomStorageEnabled(true);
wv.getSettings().setPluginState(WebSettings.PluginState.ON);
wv.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.INVISIBLE);
}
});
wv.loadUrl(web);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Hups, niečo je zle :(")
.setMessage("Internet nie je dostupný")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
System.exit(0);
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Button buttonSettings = (Button) toolbar.findViewById(R.id.button_settings);
buttonSettings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, Settings_activity.class);
MainActivity.this.startActivity(myIntent);
}
});
if(!themeSetting.equals(themeInfo)) {
if (themeSetting.equals("Základná")) {
setTheme(R.style.AppTheme);
processer.changeTheme("Základná", checker, MainActivity.this, navigationView, drawer);
checker = true;
}
if (themeSetting.equals("Matrix")) {
setTheme(R.style.AppThemeMatrixDivider);
processer.changeTheme("Matrix", checker, MainActivity.this, navigationView, drawer);
checker = true;
}
if (themeSetting.equals("Gamers")) {
setTheme(R.style.AppThemeGamersDivider);
processer.changeTheme("Gamers", checker, MainActivity.this, navigationView, drawer);
checker = true;
}
}
} else
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Hups, niečo je zle :(")
.setMessage("Chýba pripojenie k internetu. Zapnite prosím dáta alebo Wi-Fi a spustite aplikáciu znova.")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
System.exit(0);
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
} catch (Exception e) {
Log.e("chyba", e.getMessage());
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Button sett = (Button)findViewById(R.id.button_settings);
TextView text = (TextView)findViewById(R.id.textview);
navigationView.setItemIconTintList(ContextCompat.getColorStateList(MainActivity.this, themeInfo.getInt("setItemIconTintList",R.drawable.menu_text_color_normal) ));
navigationView.setItemTextColor(ContextCompat.getColorStateList(MainActivity.this, themeInfo.getInt("setItemTextColor",R.drawable.menu_text_color_normal) ));
navigationView.setBackgroundDrawable(ContextCompat.getDrawable(MainActivity.this, themeInfo.getInt("setBackgroundDrawable",R.drawable.border_top_bottom_normal) ));
sett.setTextColor(ContextCompat.getColorStateList(MainActivity.this, themeInfo.getInt("settSetTextColor",R.color.colorWhite) ));
text.setTextColor(ContextCompat.getColorStateList(MainActivity.this, themeInfo.getInt("textSetTextColor",R.color.colorDefault) ));
toolbar.setBackground(ContextCompat.getDrawable(MainActivity.this, themeInfo.getInt("toolbarSetBackground",R.color.colorPrimary) ));
toolbar.getNavigationIcon().setColorFilter(getResources().getColor(themeInfo.getInt("toolbarGetNavigationIcon()",R.color.colorWhite)), PorterDuff.Mode.SRC_ATOP);
fab.setBackgroundTintList(ContextCompat.getColorStateList(MainActivity.this, themeInfo.getInt("fabBackground",R.color.colorPrimary)));
}
这是一个我选择在意图中做什么的功能
public void MenuProcessing(int id, final Activity context, ProcessFunction processer)
{
if (id == R.id.nav_domov) {
Intent myIntent = new Intent(context, MainActivity.class);
myIntent.putExtra("website","http://lodkanadeje.maweb.eu/");
context.startActivity(myIntent);
} else if (id == R.id.nav_gallery) {
String s = "https://drive.google.com/open?id=redacted";
Intent myIntent = new Intent(context, MainActivity.class);
myIntent.putExtra("website",s);
context.startActivity(myIntent);
} else if (id == R.id.nav_facebook) {
processer.SharingToSocialMedia("com.facebook.katana", context);
} else if (id == R.id.nav_twitter) {
processer.SharingToSocialMedia("com.twitter.android", context);
} else if (id == R.id.nav_mail){
Intent myIntent = new Intent(context, MainActivity2.class);
context.startActivity(myIntent);
} else if (id == R.id.nav_map){
if(!processer.isPermissionGranted(context)){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Hups, niečo je zle :(")
.setMessage("Neudelili ste povolenie pre zisťovanie polohy. Vrátime vás na pôvodnu stránku. Pre zapnutie povolenia prejdite do nastavení aplikácie.")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
final Activity innerContext = context;
Intent myIntent = new Intent(innerContext, MainActivity.class);
myIntent.putExtra("website", "http://lodkanadeje.maweb.eu/");
innerContext.startActivity(myIntent);
}
})
.setNegativeButton("Nastavenia", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
final Activity innerContext = context;
Intent myIntent = new Intent(innerContext, Settings_activity.class);
innerContext.startActivity(myIntent);
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
if(processer.isPermissionGranted(context)) {
Intent myIntent = new Intent(context, MainActivity3.class);
context.startActivity(myIntent);
}
} else if (id == R.id.nav_instagram){
processer.SharingToSocialMedia("com.instagram.android", context);
} else if (id == R.id.nav_snapchat){
processer.SharingToSocialMedia("com.snapchat.android", context);
}
}
因此。问题是当我使用网站时
" https://drive.google.com/open?id=redacted"
它只是向我显示一个空白页面。我在堆栈上检查了几乎所有的解决方案,但是他们没有帮助我。当我使用
" http://lodkanadeje.maweb.eu/"
它完美无缺。在某处我读到https可能是webview的一个问题,但我不知道我是否相信这一点:D
你们有些人可以帮我解决这个问题吗?
由于
PS:该网站位于MenuProcessing函数的R.id.nav_gallery中。
答案 0 :(得分:0)
您需要检查链接“https://drive.google.com/drive/folders/117iEjf4I”是否需要用户上下文。如果是,则可能无法在未设置用户上下文的情况下打开页面。