Issue
for the blog reader app, the app work when i try to view the treehouse blog site inside of an activity as a webview. But when i try the itunes url or other websites, it doesnt show the content inside of my activity, instead it opens chrome. Now i dont know if this is normal or do i have to add some code for that, thanks. below is the code in the activity i am implementing the webview, thanks
package com.paveynganpi.applestorefeed;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
public class AppleFeedWebViewActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_apple_feed_web_view);
//get the intent from MainListActivity.java
Intent intent = getIntent();
Uri appleFeedUri = intent.getData();
WebView webView = (WebView)findViewById(R.id.webView);
webView.loadUrl(appleFeedUri.toString());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_apple_feed_web_view, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Solution
When the WebView has a null WebViewClient it defaults to this behavior (opening link in a browser). To keep navigations inside of your WebView do this:
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
Answered By - marcin.kosiba
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.