Skip to content

Commit

Permalink
Android: fix problem with market:// redirects leading to about:blank;…
Browse files Browse the repository at this point in the history
… add closebutton asset
  • Loading branch information
Andrew He committed Jun 24, 2011
1 parent 02c6a8b commit 659a537
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 36 deletions.
25 changes: 1 addition & 24 deletions Android/mopub-android-sdk/gen/com/mopub/mobileads/R.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,6 @@ public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
public static final int logo=0x7f020001;
public static final int spacer=0x7f020002;
}
public static final class id {
public static final int bannerview=0x7f050005;
public static final int consoletext=0x7f050006;
public static final int loadshowinterstitial=0x7f050007;
public static final int mrectview=0x7f050004;
public static final int opensite=0x7f050001;
public static final int searchbutton=0x7f050002;
public static final int searchtext=0x7f050003;
public static final int toplayout=0x7f050000;
}
public static final class layout {
public static final int about=0x7f030000;
public static final int banners=0x7f030001;
public static final int console=0x7f030002;
public static final int interstitials=0x7f030003;
public static final int main=0x7f030004;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
public static final int closebutton=0x7f020000;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 24 additions & 12 deletions Android/mopub-android-sdk/src/com/mopub/mobileads/AdView.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public AdView(Context context, MoPubView view) {
private class AdWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d("MoPub", "Ad view is loading " + url);
AdView adView = (AdView) view;

// Handle the special mopub:// scheme calls.
Expand Down Expand Up @@ -166,9 +165,8 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
// If the URL being loaded shares the redirectUrl prefix, open it in the browser.
String redirectUrl = ((AdView)view).getRedirectUrl();
if (redirectUrl != null && url.startsWith(redirectUrl)) {
Intent actionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.stopLoading();
view.getContext().startActivity(actionIntent);
showBrowserAfterFollowingRedirectsForUrl(url);
}
}
}
Expand Down Expand Up @@ -221,30 +219,44 @@ private class LoadClickedUrlTask extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
HttpClient httpclient = getAdViewHttpClient();
HttpContext ctx = new BasicHttpContext();
HttpGet httpget = new HttpGet(urls[0]);
String startingUrl = urls[0];
HttpGet httpget = new HttpGet(startingUrl);
httpget.addHeader("User-Agent", getSettings().getUserAgentString());

try {
httpclient.execute(httpget, ctx);
} catch (Exception e) {
Log.d("MoPub", "Couldn't load click URL.");
return null;
Log.d("MoPub", "Handling exception: " + e.getLocalizedMessage());
return startingUrl;
}

HttpHost host = (HttpHost) ctx.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
HttpUriRequest req = (HttpUriRequest) ctx.getAttribute(ExecutionContext.HTTP_REQUEST);
String finalUri = host.toURI() + req.getURI();

HttpHost host = (HttpHost) ctx
.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
HttpUriRequest req = (HttpUriRequest) ctx
.getAttribute(ExecutionContext.HTTP_REQUEST);
String finalUri = "";
if (host != null) finalUri += host.toURI();
if (req != null) finalUri += req.getURI();
Log.d("MoPub", "Final URI to show in browser: " + finalUri);
return finalUri;
}

@Override
protected void onPostExecute(String uri) {
if (uri == null) uri = "about:blank";
Intent actionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
try {
getContext().startActivity(actionIntent);
} catch (ActivityNotFoundException e) {
String action = actionIntent.getAction();
if (action.startsWith("market://")) {
Log.w("MoPub", "Could not handle market action: " + action
+ ". Perhaps you're running in the emulator, which does not have "
+ "the Android Market?");
} else {
Log.w("MoPub", "Could not handle intent action: " + action);
}

getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("about:blank")));
}
}
Expand Down

0 comments on commit 659a537

Please sign in to comment.