Chapter 30 Browsing the Web and WebView
Switch up your code in PhotoGalleryFragment to launch your new activity instead of the implicit
intent.
Listing 30.7 Switching to launch your activity (PhotoGalleryFragment.java)
public class PhotoGalleryFragment extends VisibleFragment {
...
private class PhotoHolder extends RecyclerView.ViewHolder
implements View.OnClickListener{
...
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW, mGalleryItem.getPhotoPageUri());
Intent i = PhotoPageActivity
.newIntent(getActivity(), mGalleryItem.getPhotoPageUri());
startActivity(i);
}
}
...
}
And, finally, add your new activity to the manifest.
Listing 30.8 Adding activity to manifest (AndroidManifest.xml)
<manifest ... >
...
<application
...>
<activity
android:name=".PhotoGalleryActivity"
android:label="@string/app_name" >
...
<activity
android:name=".PhotoPageActivity" />
...
Run PhotoGallery and press on a picture. You should see a new empty activity pop up.
OK, now to get to the meat and actually make your fragment do something. You need to do three
things to make your WebView successfully display a Flickr photo page. The first one is straightforward
- you need to tell it what URL to load.
The second thing you need to do is enable JavaScript. By default, JavaScript is off. You do not always
need to have it on, but for Flickr, you do. (If you run Android Lint, it gives you a warning for doing
this. It is worried about cross-site scripting attacks. You can suppress this Lint warning by annotating
onCreateView(...) with @SuppressLint("SetJavaScriptEnabled").)