Skip to content

Instantly share code, notes, and snippets.

@Ray33
Last active November 14, 2017 15:42
Show Gist options
  • Save Ray33/80cfa9b87235446ea191d4107b874a87 to your computer and use it in GitHub Desktop.
Save Ray33/80cfa9b87235446ea191d4107b874a87 to your computer and use it in GitHub Desktop.
Assemble requred parameters for video
public static String getVideoUrl(View view, String clickUrl) {
int height = 300, width = 600;
String appName ="";
String gpUrl="";
try {
appName = URLEncoder.encode(view.getContext().getString(R.string.app_name), "UTF-8");
gpUrl = URLEncoder.encode( "http://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (view.getHeight() > 0) {
height = view.getHeight();
width = view.getWidth();
}
LocationManager locationManager = (LocationManager) view.getContext()
.getSystemService(LOCATION_SERVICE);
double lat = NetworkHelper.getLatitude(locationManager);
double longt = NetworkHelper.getLongitude(locationManager);
return clickUrl + "&width=" + width + "&height=" + height + "&app_name=" + appName +
"&app_version=" + BuildConfig.VERSION_CODE + "&app_id=" + BuildConfig.APPLICATION_ID +
"&gp_url=" + gpUrl +
"&lat=" + lat + "&long=" + longt + "&volume=1";
}
@Ray33
Copy link
Author

Ray33 commented Nov 14, 2017

Usage:
//Open the article in Chrome custom tab
if (newsArticle.has_video) {
String videoUrl = VideoAdsHelper.getVideoUrl(view, newsArticle.clickUrl);
CustomTabHelper.openCustomTab(getContext(), mBuilder, getResources(), videoUrl);
} else {
CustomTabHelper.openCustomTab(getContext(), mBuilder, getResources(), newsArticle.clickUrl);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment