title: Hide Adsense ad space in android app webview by its id?
body: <p>I want to hide space caused by the google <code>AdSense</code> ads in the android app while fetching data from its WordPress site through <code>WebView</code>. My Code is:</p>
  
  <pre><code>public class PostViewActivity extends AppCompatActivity {
  
  private static final String TAG = PostViewActivity.class.getSimpleName();
  public static final String TAG_SEL_POST_ID = "post_id";
  public static final String TAG_SEL_POST_TITLE = "post_title";
  public static final String TAG_SEL_POST_IMAGE = "post_image";
  private String commentsNumber;
  
  
  private String selectedPostID, selectedPostTitle;
  ImageLoader imageLoader = AppController.getInstance().getImageLoader();
  private ImageButton fab;
  private TextView post_name;
  private TextView post_content;
  private TextView post_author;
  private ImageView postImageView;
  private String post_image, objURL, objTitle;
  private Integer commentsCount;
  private TextView timestamp;
  private NetworkImageView profilePic;
  private ShareActionProvider mShareActionProvider;
  private WebView post_contentHTML;
  private Boolean user_can_comment = true;
  
  private Spanned spannedContent;
  private ProgressBar pbLoader;
  private LinearLayout llayout;
  
  private Integer OC = 0;
  String html;
  Gson gson;
  Map&lt;String, Object&gt; mapPost;
  Map&lt;String, Object&gt; mapTitle;
  Map&lt;String, Object&gt; mapContent;
  //----------Exit and Banner Ad----------------------------------
  private InterstitialAd interstitial;
  private AdView mAdView,mAdView1;
  
  private Toolbar toolbar;
  String URL ="http://www.asiannews.co.in/_STORY_ID_/";
  
  public static void navigate(AppCompatActivity activity, View transitionImage, Post post) {
      Intent intent = new Intent(activity, PostViewActivity.class);
      intent.putExtra(TAG_SEL_POST_IMAGE, post.getImge());
      intent.putExtra(TAG_SEL_POST_TITLE, post.getName());
  
      ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, transitionImage, TAG_SEL_POST_IMAGE);
      ActivityCompat.startActivity(activity, intent, options.toBundle());
  }
  
  @Override
  public void onSaveInstanceState(Bundle savedInstanceState) {
      // Save UI state changes to the savedInstanceState.
      // This bundle will be passed to onCreate if the process is
      // killed and restarted.
      savedInstanceState.putString(TAG_SEL_POST_ID, selectedPostID);
      savedInstanceState.putString(TAG_SEL_POST_TITLE, selectedPostTitle);
      Log.d(TAG, savedInstanceState.toString());
      super.onSaveInstanceState(savedInstanceState);
  }
  
  @Override
  protected void onRestoreInstanceState(Bundle savedInstanceState) {
      Log.d(TAG, "Restored: " + savedInstanceState.toString());
      selectedPostID = (String) savedInstanceState.getString(TAG_SEL_POST_ID);
      selectedPostTitle = (String) savedInstanceState.getString(TAG_SEL_POST_TITLE);
      super.onRestoreInstanceState(savedInstanceState);
  }
  
  @Override
  public void onResume() {
      super.onResume();
      //Get a Tracker (should auto-report)
      if (Const.Analytics_ACTIVE) {
          AnalyticsUtil.sendScreenName(this, TAG);
      }
  
  }
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      initActivityTransitions();
      setContentView(R.layout.activity_post_view);
  
      //Forcing RTL Layout, If Supports and Enabled from Const file
      Utils.forceRTLIfSupported(this);
  
      ActivityCompat.postponeEnterTransition(this);
      final String id = getIntent().getExtras().getString("id");
      toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      toolbar.setNavigationOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              onBackPressed();
          }
      });
  
  
  
      //Get and Set the Post Title
      String itemTitle = getIntent().getStringExtra(TAG_SEL_POST_TITLE);
      setTitle(Html.fromHtml(itemTitle));
  
      if (savedInstanceState == null) {
          if (getIntent().getExtras() == null) {
              selectedPostID = null;
              selectedPostTitle = "Unknown Error";
          } else {
              selectedPostID = getIntent().getExtras().getString(TAG_SEL_POST_ID);
              selectedPostTitle = getIntent().getExtras().getString(TAG_SEL_POST_TITLE);
          }
      } else {
          Log.d(TAG, "Resume: " + savedInstanceState.toString());
          selectedPostID = (String) savedInstanceState.getString(TAG_SEL_POST_ID);
          selectedPostTitle = (String) savedInstanceState.getString(TAG_SEL_POST_TITLE);
          /*selectedPostID = (String) savedInstanceState.getSerializable(TAG_SEL_POST_ID);
          selectedPostTitle = (String) savedInstanceState.getSerializable(TAG_SEL_POST_TITLE);*/
  
      }
  
      //Setting up Fields Display
      fab = (ImageButton) findViewById(R.id.fab);
      post_name = (TextView) findViewById(R.id.title);
      timestamp = (TextView) findViewById(R.id.timestamp);
      Typeface font = Typeface.createFromAsset(getAssets(), "fonts/GenR102.ttf");
      post_name.setTypeface(font);
  
  
      float density = getResources().getDisplayMetrics().density;
      int leftPadding = (int) (20 * density);
      Configuration config = getResources().getConfiguration();
      if (ViewCompat.getLayoutDirection(post_name) == ViewCompat.LAYOUT_DIRECTION_RTL) {
          //post_name.setPadding(leftPadding,R.dimen.spacing_large,0,0);
          post_name.setPadding(leftPadding, 0, 0, 0);
      } else {
          post_name.setPadding(0, 0, leftPadding, 0);
      }
  
  
      post_content = (TextView) findViewById(R.id.description);
      post_contentHTML=(WebView) findViewById(R.id.descriptionHTML);
      String post_con = "&lt;!DOCTYPE html&gt;" +
              "&lt;html lang=\"en\"&gt;" +
              "  &lt;head&gt;" +
              "    &lt;meta charset=\"utf-8\"&gt;" +
              "  &lt;/head&gt;" +
              " &lt;body&gt;"+ "&lt;script&gt;" +
              "&lt;ins&gt;" +"&lt;/ins&gt;" +
              "&lt;/script&gt;"+"&lt;script&gt;"+
              "&lt;/script&gt;"
              +"#content" +
              "  &lt;/body&gt;" +
              "&lt;/html&gt;" ;
      html= "&lt;html&gt;&lt;body style='margin:0;padding:0;'&gt;&lt;script type='text/javascript' src='http://asiannews.co.in/myads.html'&gt;&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;";
  
  
      if (!Const.ShowPostAsWebView) {
          post_content.setMovementMethod(LinkMovementMethod.getInstance());
          Typeface font_postcontent = Typeface.createFromAsset(getAssets(), "fonts/OSRegular.ttf");
          post_content.setTypeface(font_postcontent);
            String url = "http://www.asiannews.co.in/bp4a-api/v1/post/_STORY_ID_/";
           /* StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener&lt;String&gt;() {
                @Override
                public void onResponse(String s) {
                    gson = new Gson();
                    mapPost = (Map&lt;String, Object&gt;) gson.fromJson(s, Map.class);
                    mapTitle = (Map&lt;String, Object&gt;) mapPost.get("title");
                    mapContent = (Map&lt;String, Object&gt;) mapPost.get("content");
  
                    post_content.setText(mapTitle.get("name").toString());
                    post_contentHTML.loadData(mapContent.get("description").toString(), "text/html", "UTF-8");
  
                    //  progressDialog.dismiss();
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    // progressDialog.dismiss();
                    Toast.makeText(PostViewActivity.this,id, Toast.LENGTH_LONG).show();
                }
            });
  
            RequestQueue rQueue = Volley.newRequestQueue(PostViewActivity.this);
            rQueue.add(request);*/
      } else {
          post_contentHTML.setVisibility(View.VISIBLE);
          WebSettings webSettings = post_contentHTML.getSettings();
          post_contentHTML.getSettings().setJavaScriptEnabled(true);
  
        //  post_contentHTML.addJavascriptInterface(post_contentHTML,post_contentHTML);
            post_contentHTML.loadUrl("http://www.asiannews.co.in/bp4a-api/v1/post/_STORY_ID_/");
          post_contentHTML.getSettings().setAllowContentAccess(true);
          post_contentHTML.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
          post_contentHTML.getSettings().setLoadsImagesAutomatically(true);
          post_contentHTML.getSettings().setDefaultTextEncodingName("utf-8");
          post_contentHTML.getSettings().setUseWideViewPort(true);
            post_contentHTML.getSettings().getMixedContentMode();
          post_contentHTML.getSettings().setLoadWithOverviewMode(true);
            post_contentHTML.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
            post_contentHTML.loadDataWithBaseURL(" ",post_con,"text/html","utf-8"," ");
          post_contentHTML.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
          post_contentHTML.setWebChromeClient(new WebChromeClient());
  
          post_contentHTML.setWebViewClient(new WebViewClient() {
              @Override
              public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
              {
                  // Handle the error
              }
  
              public void onPageFinished(WebView view, String url) {
                  post_contentHTML.loadUrl("javascript:(function() { " +
                          "document.getElementsByClassName('adsbygoogle')[0].style.display='none'; " +
                          "})()");
              }
              @Override
              public boolean shouldOverrideUrlLoading(WebView view, String url) {
  
                view.loadUrl(url);
                  return true;
              }
              });
        //  post_contentHTML.loadUrl(URL);
  
          // post_contentHTML.loadData(html,"text/html","utf-8");
          // post_contentHTML.loadUrl("http://asiannews.co.in/myads.html");
  
           if (Build.VERSION.SDK_INT &gt;= 16) {
                webSettings.setAllowFileAccessFromFileURLs(false);
                webSettings.setAllowUniversalAccessFromFileURLs(false);
            }
  
      }
  
      post_author = (TextView) findViewById(R.id.post_author);
  
  
      postImageView = (ImageView) findViewById(R.id.image);
      profilePic = (NetworkImageView) findViewById(R.id.profilePic);
  
  
      //Setting up Post Image and Toolbar Activity
      //final ImageView image = (ImageView) findViewById(R.id.image);
      /*ViewCompat.setTransitionName(postImageView, TAG_SEL_POST_IMAGE);
  
      Bitmap bitmap = ((BitmapDrawable) postImageView.getDrawable()).getBitmap();
      Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
          public void onGenerated(Palette palette) {
              applyPalette(palette, postImageView);
          }
      });*/
  
  
      //Setting Up Post Admob Banner
      ////Standard Banner
      mAdView = (AdView) findViewById(R.id.adView);
  
      if (Const.ADMOBService_ACTIVE) {
          //----------Exit Ad----------------------------------
          interstitial = new InterstitialAd(this);
          interstitial.setAdUnitId(getString(R.string.unit_id_interstitial));
          AdRequest adRequestInterstitial = new AdRequest.Builder().build();
          interstitial.loadAd(adRequestInterstitial);
          //----------Exit Ad----------------------------------
  
          AdRequest adRequest = new AdRequest.Builder().build();
          mAdView.loadAd(adRequest);
          mAdView.setAdListener(new AdListener() {
              @Override
              public void onAdLoaded() {
                  super.onAdLoaded();
                  mAdView.setVisibility(View.VISIBLE);
              }
          });
      } else {
          mAdView.setVisibility(View.GONE);
      }
  
      getPost();
  
  }
  
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  private void initActivityTransitions() {
      if (Utils.isLollipop()) {
          Slide transition = new Slide();
          transition.excludeTarget(android.R.id.statusBarBackground, true);
          getWindow().setEnterTransition(transition);
          getWindow().setReturnTransition(transition);
      }
  }
  
  private void applyPalette(Palette palette, ImageView image) {
      int primaryDark = getResources().getColor(R.color.primary_dark);
      int primary = getResources().getColor(R.color.primary);
      toolbar.setBackgroundColor(primary);
      Utils.setStatusBarcolor(getWindow(), primaryDark);
      initScrollFade(image);
      ActivityCompat.startPostponedEnterTransition(this);
  }
  
  private void initScrollFade(final ImageView image) {
      final View scrollView = findViewById(R.id.scroll);
  
      setComponentsStatus(scrollView, image);
  
      scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
          @Override
          public void onScrollChanged() {
              setComponentsStatus(scrollView, image);
          }
      });
  }
  
  private void setComponentsStatus(View scrollView, ImageView image) {
      int scrollY = scrollView.getScrollY();
      image.setTranslationY(-scrollY / 2);
      ColorDrawable background = (ColorDrawable) toolbar.getBackground();
      int padding = scrollView.getPaddingTop();
      double alpha = (1 - (((double) padding - (double) scrollY) / (double) padding)) * 255.0;
      alpha = alpha &lt; 0 ? 0 : alpha;
      alpha = alpha &gt; 255 ? 255 : alpha;
  
      background.setAlpha((int) alpha);
  
      float scrollRatio = (float) (alpha / 255f);
      int titleColor = getAlphaColor(Color.WHITE, scrollRatio);
      toolbar.setTitleTextColor(titleColor);
      toolbar.setSubtitleTextColor(titleColor);
  }
  
  private int getAlphaColor(int color, float scrollRatio) {
      return Color.argb((int) (scrollRatio * 255f), Color.red(color), Color.green(color), Color.blue(color));
  }
  
  /**
   * It seems that the ActionBar view is reused between activities. Changes need to be reverted,
   * or the ActionBar will be transparent when we go back to Main Activity
   */
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  private void restablishActionBar() {
      if (Utils.isLollipop()) {
          getWindow().getReturnTransition().addListener(new TransitionAdapter() {
              @Override
              public void onTransitionEnd(Transition transition) {
                  toolbar.setTitleTextColor(Color.WHITE);
                  toolbar.setSubtitleTextColor(Color.WHITE);
                  toolbar.getBackground().setAlpha(255);
              }
          });
      }
  }
  
  @Override
  public void onBackPressed() {
      restablishActionBar();
      if (Const.ADMOBService_ACTIVE) {
          displayInterstitial();
      }
      super.onBackPressed();
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
  
      if (item.getItemId() == android.R.id.home) {
          restablishActionBar();
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  
  private void getPost() {
      //Requesting The Story
      String url = null;
      url = Const.URL_STORY_PAGE.replace("_STORY_ID_", selectedPostID.replace("P", ""));
      //Log.i(TAG, "Taging: " + url);
      // making fresh volley request and getting json
      JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener&lt;JSONObject&gt;() {
  
          @Override
          public void onResponse(JSONObject response) {
              //Log.i(TAG, "Taging: " + response.toString());
              VolleyLog.d(TAG, "Response: " + response.toString());
              if (response != null) {
                  try {
                      if (response.has("error")) {
                          String error = response.getString("error");
                          Toast.makeText(getApplicationContext(), error, Toast.LENGTH_LONG).show();
                      } else {
                          parseJsonFeed(response);
                      }
                  } catch (JSONException es) {
                      es.printStackTrace();
                      Toast.makeText(getApplicationContext(), es.getMessage(), Toast.LENGTH_LONG).show();
                  }
              }
          }
      }, new Response.ErrorListener() {
  
          @Override
          public void onErrorResponse(VolleyError error) {
              VolleyLog.d(TAG, "Error: " + error.getMessage());
          }
      }) {
          /** Passing some request headers **/
          @Override
          public Map&lt;String, String&gt; getHeaders() throws AuthFailureError {
              HashMap&lt;String, String&gt; headers = new HashMap&lt;String, String&gt;();
              headers.put("Content-Type", "application/json");
              headers.put("ApiKey", Const.AuthenticationKey);
              return headers;
          }
      };
  
      // Adding request to volley request queue
      AppController.getInstance().addToRequestQueue(jsonReq);
  }
  
  
  private void parseJsonFeed(JSONObject feedObj) {
      try {
          objTitle = feedObj.getString("name");
          post_name.setText(Html.fromHtml(objTitle));
  
          commentsCount = feedObj.getInt("comments");
          if (feedObj.getString("can_comment") == "no") {
              user_can_comment = false;
          }
  
         if (!Const.ShowPostAsWebView) {
              post_contentHTML.setVisibility(View.GONE);
              URLImageParser p = new URLImageParser(this, post_content);
              spannedContent = Html.fromHtml(feedObj.getString("story_content"), p, null);
              post_content.setText(trimTrailingWhitespace(spannedContent));
          } else {
  
              post_content.setVisibility(View.GONE);
              post_contentHTML.setVisibility(View.VISIBLE);
              post_contentHTML.loadData(html,"text/html","utf-8");
  
              String post_con = "&lt;!DOCTYPE html&gt;" +
                      "&lt;html lang=\"en\"&gt;" +
                      "  &lt;head&gt;" +
                      "    &lt;meta charset=\"utf-8\"&gt;" +
                      "  &lt;/head&gt;" +
                      " &lt;body&gt;"+ "&lt;script&gt;" +
                      "&lt;ins&gt;" +"&lt;/ins&gt;" +
                      "&lt;/script&gt;"+"&lt;script&gt;"+
                      "&lt;/script&gt;"
                      +"#content" +
                      "  &lt;/body&gt;" +
                      "&lt;/html&gt;" ;
              try {
                  InputStream in_s = getResources().openRawResource(R.raw.post_format);
                  byte[] b = new byte[in_s.available()];
                  in_s.read(b);
                  post_con = new String(b);
              } catch (Exception e) {
                  e.printStackTrace();
              }
  
              post_con = post_con.replace("#title#", feedObj.getString("name"));
              post_con = post_con.replace("#content#", feedObj.getString("story_content"));
  
              post_contentHTML.loadData(html, "text/html", "utf-8");
              post_contentHTML.loadDataWithBaseURL(null,
                      post_con,
                      "text/html",
                      "UTF-8",
                      null);
          }
  
          if (feedObj.getString("story_content").length() &lt;= 0) {
              post_content.setVisibility(View.GONE);
              post_contentHTML.setVisibility(View.GONE);
          }
  
          post_author.setText(feedObj.getString("author"));
          getSupportActionBar().setSubtitle("By " + feedObj.getString("author"));
  
          post_image = feedObj.getString("image");
          objURL = feedObj.getString("url");
  
          if (Const.Analytics_ACTIVE) {
              AnalyticsUtil.sendEvent(this, "Post View", objTitle, objURL);
          }
  
          //Setting Up a Share Intent
          fab.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  Intent shareIntent = new Intent(Intent.ACTION_SEND);
                  shareIntent.setType("text/plain");
                  shareIntent.putExtra(Intent.EXTRA_TEXT, objTitle + " - " + objURL);
                  startActivityForResult(Intent.createChooser(shareIntent, "Share via"), 300);
              }
          });
  
          //setShareIntent(shareIntent);
  
          //Comment Button Click
          Button viewComments = (Button) findViewById(R.id.btnViewComments);
          commentsNumber = Utils.formatNumber(commentsCount);
          viewComments.setText(String.format(getString(R.string.comments_button), commentsNumber));
          viewComments.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent i = new Intent();
                  i.setClass(PostViewActivity.this, PostComments.class);
                  i.putExtra("post_id", selectedPostID.replace("P", ""));
                  i.putExtra("post_title", getIntent().getStringExtra(TAG_SEL_POST_TITLE));
                  i.putExtra("commentsCount", commentsCount);
                  i.putExtra("user_can_comment", user_can_comment);
                  startActivityForResult(i, 1000);
              }
          });
  
          //Button Click
          Button viewWeb = (Button) findViewById(R.id.btnViewWeb);
          if (Const.ShowPostOnExternalBrowser) {
              viewWeb.setVisibility(View.VISIBLE);
              viewWeb.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      goToUrl(objURL);
                  }
              });
          }
  
  
          // Converting timestamp into x ago format
          CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(
                  Long.parseLong(feedObj.getString("timeStamp")),
                  System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
          timestamp.setText(timeAgo);
  
          profilePic.setImageUrl(feedObj.getString("profilePic"), imageLoader);
  
  
          loadConfig();
          //pbLoader.setVisibility(View.GONE);
          //llayout.setVisibility(View.VISIBLE);
      } catch (JSONException e) {
          e.printStackTrace();
      }
  }
  
  
  private void goToUrl(String url) {
      Uri uriUrl = Uri.parse(url);
      Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
      startActivity(launchBrowser);
  }
  
  private void loadConfig() {
      if (post_image != null) {
          ViewCompat.setTransitionName(postImageView, TAG_SEL_POST_IMAGE);
          Picasso.with(this).load(post_image).into(postImageView, new Callback() {
              @Override
              public void onSuccess() {
                  Bitmap bitmap = ((BitmapDrawable) postImageView.getDrawable()).getBitmap();
                  new Palette.Builder(bitmap).generate(new Palette.PaletteAsyncListener() {
                      public void onGenerated(Palette palette) {
                          applyPalette(palette, postImageView);
                      }
                  });
                  /*Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
                      public void onGenerated(Palette palette) {
                          applyPalette(palette, postImageView);
                      }
                  });*/
              }
  
              @Override
              public void onError() {
  
              }
          });
      } else {
          postImageView.setVisibility(View.GONE);
      }
  }
  
  
  @JavascriptInterface
  public void resize(final float height) {
      PostViewActivity.this.runOnUiThread(new Runnable() {
          @Override
          public void run() {
              Toast.makeText(getApplicationContext(), "Trigger: " + height + " // " + (int) (height * getResources().getDisplayMetrics().density), Toast.LENGTH_LONG).show();
              //post_contentHTML.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, (int) (height * getResources().getDisplayMetrics().density)));
          }
      });
  }
  
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      post_contentHTML.loadUrl("javascript:Asiannews.resize(document.body.getBoundingClientRect().height)");
  }
  
  public static CharSequence trimTrailingWhitespace(CharSequence source) {
  
      if (source == null)
          return "";
  
      int i = source.length();
  
      // loop back to the first non-whitespace character
      while (--i &gt;= 0 &amp;&amp; Character.isWhitespace(source.charAt(i))) {
      }
  
      return source.subSequence(0, i + 1);
  }
  
  // Invoke displayInterstitial() when you are ready to display an interstitial.
  public void displayInterstitial() {
      if (interstitial.isLoaded()) {
          interstitial.show();
      }
  }
  
  
  public class URLImageParser implements Html.ImageGetter {
      @SuppressWarnings("deprecation")
      class URLDrawable extends BitmapDrawable {
          // the drawable that you need to set, you could set the initial drawing
          // with the loading image if you need to
          protected Drawable drawable;
  
          @Override
          public void draw(Canvas canvas) {
              // override the draw to facilitate refresh function later
              if (drawable != null) {
                  drawable.draw(canvas);
              }
          }
      }
  
      class ImageGetterAsyncTask extends AsyncTask&lt;String, Void, Drawable&gt; {
          URLDrawable urlDrawable;
  
          public ImageGetterAsyncTask(URLDrawable d) {
              this.urlDrawable = d;
          }
  
          @Override
          protected Drawable doInBackground(String... params) {
              String source = params[0];
              Uri uri = Uri.parse(source);
              Bitmap bitmap = null;
              try {
                  Picasso pic = new Picasso.Builder(mContext).build();
                  bitmap = pic.load(uri).get();
              } catch (IOException e) {
                  Log.e(TAG, e.getMessage());
              }
              return new BitmapDrawable(mContext.getResources(), bitmap);
          }
  
          @Override
          protected void onPostExecute(Drawable result) {
              // set the correct bound according to the result from HTTP call
              urlDrawable.setBounds(0, 0, 0 + result.getIntrinsicWidth(), 0
                      + result.getIntrinsicHeight());
  
              // change the reference of the current drawable to the result
              // from the HTTP call
              urlDrawable.drawable = result;
  
              // redraw the image by invalidating the container
              URLImageParser.this.mView.invalidate();
          }
      }
  
      private final Context mContext;
      private final View mView;
  
      public URLImageParser(Context context, View view) {
          mContext = context;
          mView = view;
      }
  
      @Override
      public Drawable getDrawable(String source) {
          Uri uri = Uri.parse(source);
          URLDrawable urlDrawable = new URLDrawable();
          ImageGetterAsyncTask task = new ImageGetterAsyncTask(urlDrawable);
          task.execute(source);
          return urlDrawable;
      }
  }
  
  
  @Override
  protected void onStart() {
      super.onStart();
      GoogleAnalytics.getInstance(PostViewActivity.this).reportActivityStart(this);
  }
  
  @Override
  protected void onStop() {
      super.onStop();
      GoogleAnalytics.getInstance(PostViewActivity.this).reportActivityStop(this);
  }
  }
  </code></pre>
  
  <p>How can I do that?
  What am I doing wrong?</p>