harryjamesuk

BlogWebViewActivity.java

Jul 22nd, 2014
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. package com.harryjamesuk.blogreader;
  2.  
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.support.v7.app.ActionBarActivity;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.webkit.WebView;
  10.  
  11. public class BlogWebViewActivity extends ActionBarActivity {
  12.  
  13.     protected String mUrl;
  14.    
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.activity_blog_web_view);
  19.        
  20.         Intent intent = getIntent();
  21.         Uri blogUri = intent.getData();
  22.         mUrl = blogUri.toString();
  23.        
  24.         WebView webView = (WebView) findViewById(R.id.webView1);
  25.         webView.loadUrl(mUrl);
  26.     }
  27.  
  28.     @Override
  29.     public boolean onCreateOptionsMenu(Menu menu) {
  30.         // Inflate the menu; this adds items to the action bar if it is present.
  31.         getMenuInflater().inflate(R.menu.blog_web_view, menu);
  32.         return true;
  33.     }
  34.  
  35.     @Override
  36.     public boolean onOptionsItemSelected(MenuItem item) {
  37.         // Handle action bar item clicks here. The action bar will
  38.         // automatically handle clicks on the Home/Up button, so long
  39.         // as you specify a parent activity in AndroidManifest.xml.
  40.         int itemId = item.getItemId();
  41.         if (itemId == R.id.action_share) {
  42.             sharePost();
  43.         }
  44.         return super.onOptionsItemSelected(item);
  45.     }
  46.  
  47.     private void sharePost() {
  48.         Intent shareIntent = new Intent(Intent.ACTION_SEND);
  49.         shareIntent.setType("text/plain");
  50.         shareIntent.putExtra(Intent.EXTRA_TEXT, mUrl);
  51.         startActivity(Intent.createChooser(shareIntent, getString(R.string.share_chooser_title)));
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment