I have a ViewPager with several fragments inside, and one of them contains a webview. Inside that WebView, I would like to open links to images (jpeg/png) in a designated activity which I use to show images:
MyFragment.java
webView.setWebViewClient(new WebViewClient() {
public void startImageView(String url) {
Intent imageIntent = new Intent(getActivity(), ImageActivity.class);
imageIntent.putExtra(ImageActivity.IMAGE_URL, Uri.parse(url));
startActivity(imageIntent);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if (url.toLowerCase().endsWith(".png") || url.toLowerCase().endsWith(".jpg") || url.toLowerCase().endsWith(".jpeg")) {
startImageView(url);
} else {
view.loadUrl(url);
}
return false;
}
});
ImageActivity.java
public class ImageActivity extends ActionBarActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_full_size);
...
}
AndroidManifest.xml
...
<activity
android:name="com.example.main.ImageActivity"
android:label="Picture"
android:screenOrientation="portrait"
>
</activity>
...
When I click on an image link inside the webview, the image activity indeed loads. However, the activity is loaded inside the fragment, instead of opening in a new window (as activities usually do). When I start this activity from a different activity (and not inside a webview as mentioned above) the activity opens in a new window as expected. Any ideas how to open the ImageActivity in a new window when started from WebView?