Get admob Id remotely - java

I have an application I made using android studio. As of the moment, the admob ids are defined in the strings.xml file. However, I want to make the app get the admob ids from either my server or from firebase as I want to be able to change them remotely should any problems occur. How would I go about doing this?

Either you can load Ads From Firebase Using Remote Config
or you Can Use the Firebase database. Refer this Sample Project from my Github
Load Ads From Firebse

You can do it programmatically.
Layout
From your layout file, add AdView:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
Retrieving Ad Unit Id
You need to do network calls either on your splash screen or main activity to retrieve your Ad Unit Id/s
You can use Retrofit for doing such http request calls from your web server
If you choose Firebase, you can use their
Firebase Realtime Database
Setting Ad Unit Id
In Java
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111"); // Set ad unit id
In Kotlin
val adView = AdView(this)
adView.adSize = AdSize.BANNER
adView.adUnitId = "ca-app-pub-3940256099942544/6300978111" // Set ad unit id
Additional
Depending on your persistent storage implementation, here's a one liner way of saving the Ad Unit Id using SharedPreferences
PreferenceManager.getDefaultSharedPreferences(context).edit().putString("MY_AD_UNIT_ID", "YOUR_AD_UNIT_VALUE").apply();
Here's how you will retrieve it
PreferenceManager.getDefaultSharedPreferences(context).getString("MY_AD_UNIT_ID", "DEFAULT_STRING_IF_NOTHING_WAS_FOUND");
Where context is your Context.
Read more:
https://developers.google.com/admob/android/banner

There is a new API that allows you to manage Firebase projects and get configuration data from them. This would be the most logical place to look up such configuration data programmatically.
I checked the projects.get and projects.getAdminConfig, but haven't been able to find the ID you're looking for yet.
If that ID is indeed missing, it might be worth it to file a feature request.

Related

AdMob shows real ads even when using a test unit id; Android

TLDR: I get real ads even if I use a sample unit id provided by Google for testing.
I implemented native ads in my application.
I am using the Native Advanced sample ad unit as described here:
https://developers.google.com/admob/android/test-ads
However, the ads I get look very real, even though they have a "Test Ad" text in the title, and they also redirect me to real company websites. This has not happened with banner ads, I only got Google sample ads previously (e.g. Nice job, this is a test ad).
Some of the ads are coming from well-known restaurants in my country, and clicking on them navigates me to their website. I don't use my own unit id anywhere.
This is the code I use to initialize ads.
public static final String UNIFIED_AD_UNIT_ID = "ca-app-pub-3940256099942544/2247696110";
MobileAds.initialize(context, initializationStatus -> {
});
AdLoader adLoader = new AdLoader.Builder(context, UNIFIED_AD_UNIT_ID)
.forUnifiedNativeAd(unifiedNativeAd -> {
populateNativeAdView(unifiedNativeAd, nativeAdView);
}).build();
adLoader.loadAd(new AdRequest.Builder().build());
}
Is this a bug, or am I doing something wrong? (Or are these really test ads?) I really don't want to get banned from AdMob.
If you start your App running Android Studio, you can get the test device id for your device from the logcat at the bottom of Android Studio. Add this to your builder. By the way, the ads you are getting are looking like they should.

set custom labels for activity name in Google Analytics

i use Google Analytics for monitor my users in my Android app. Now i want to set label's for each activity in google analytics. Just for better understanding i don't want see Activity Class name, instead see my custom label's. how i can do this?
in onCreate:
// Get tracker.
Tracker t = ((MyApplicationClass)
getActivity().getApplication()).getTracker(MyApplicationClass.TrackerName.APP_TRACKER);
// Set screen name. Where path is a String representing the screen name.
t.setScreenName("YOUR_CUSTOM_LABLE_FOR_THIS_SCREEN");
// Send a screen view.
t.send(new HitBuilders.AppViewBuilder().build());
Initialize variable:
private Tracker tracker;
onCreate()
tracker = ((GlobalClass) getApplication()).getTracker(GlobalClass.TrackerName.APP_TRACKER);
tracker.setScreenName("Add_your_own_lable");
tracker.send(new HitBuilders.AppViewBuilder().build());
Hope this will help you.
You can also configure the activity names with XML tracker configuration file.
https://developers.google.com/analytics/devguides/collection/android/v4/#analytics-xml
For example if you like to name "com.example.app.MainActivity" activity as "Home Screen" you can add:
<screenName name="com.example.app.MainActivity">
Home Screen
</screenName>
to the configuration file. When creating the tracker, make sure you are using the XML configuration instead of hardcoded trackerId.

Offline tile caching using MapBox Android SDK

I have a working iOS prototype using the iOS tile-caching technique as shown below (Objective-C code):
RMTileCache * tileCache = [[RMTileCache alloc] initWithExpiryPeriod:0];
[tileCache setBackgroundCacheDelegate:self];
RMMapboxSource * tileSource = [[RMMapboxSource alloc] initWithMapID:mapID];
[tileCache beginBackgroundCacheForTileSource:tileSource southWest:southWest northEast:northEasth minZoom:minZoom maxZoom:maxZoom];
What this basically does is download the map, cache the tiles permanently and make it possible for the app to run offline in the future. Since we're going through the official payed API, this is of course not violating any of the legal restrictions.
Now I'd like to achieve the same on Android. I have the SDK running in Android Studio and a working project with a remote map using the Map ID, basically this (Android Eclipse layout XML):
<com.mapbox.mapboxsdk.views.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
mapid=“my_map_id" />
This works fine, but the solution has to be completely offline once the caching is done. My question is: is there a Java equivalent of the iOS source code above in the MapBox SDK? I attempted to look in the API, but could not find a solid reference to the tile caching system. And after some painful time trying to get it running based on the method names and code documentation, I gave up.
I'm running the latest GitHub distribution of MapBox along with the latest Android Studio, everything's up and running fine, but can't find the code to accomplish this. I don’t necessarily need an API reference, a few lines of code showing how it’s done would be enough.
Offline Tile Caching support is now available in the Mapbox Android SDK as of version 0.5.1. It was released on 20-December-2014. Here's a basic example of how to get started:
OfflineMapDownloader offlineMapDownloader = OfflineMapDownloader.getOfflineMapDownloader(getActivity());
BoundingBox boundingBox = mapView.getBoundingBox();
CoordinateSpan span = new CoordinateSpan(boundingBox.getLatitudeSpan(), boundingBox.getLongitudeSpan());
CoordinateRegion coordinateRegion = new CoordinateRegion(mapView.getCenter(), span);
offlineMapDownloader.beginDownloadingMapID("MapboxMapID", coordinateRegion, (int) mapView.getZoomLevel(), (int) mapView.getZoomLevel());
To load a previously saved map:
ArrayList<OfflineMapDatabase> offlineMapDatabases = offlineMapDownloader.getMutableOfflineMapDatabases();
OfflineMapDatabase db = offlineMapDatabases.get(0);
OfflineMapTileProvider tp = new OfflineMapTileProvider(getActivity(), db);
offlineMapOverlay = new TilesOverlay(tp);
mapView.addOverlay(offlineMapOverlay);
I asked this question to the support team, here's the answer:
"We don't currently have a release date for the Android SDK or for this feature, because both are in very early stages of development.
--
Tom MacWright
support#mapbox.com"
It's a very good product, I hope we can use it soon in Android.
In your layout file there must be:
<com.mapbox.mapboxsdk.views.MapView
android:id="#+id/yourMapViewId"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
In code where you want to initialize MapView:
File file = new File("your full path to tiles db");
MBTilesLayer mbTilesLayer = new MBTilesLayer(file);
MapView mapView = (MapView) findViewById(R.id.yourMapViewId);
mapView.setTileSource(mbTilesLayer);

Invalid unknown request error: Cannot determine request type. Is this ad unit id correct?

After updating to "new abMob", it appears to have this problem...
use this code, but nothing displays:
adView = new AdView(this, AdSize.BANNER, "pub-xxxxxxxxxxxxxxxx");
and got warning:
Invalid unknown request error: Cannot determine request type. Is your
ad unit id correct?
What's wrong?
Using android emulator, admob 6.4.1
In my case, the ad unit id was incorrect in AdMob app management section! There was a ~ instead of / in the id. I fixed it by viewing the GoogleService info plist and found the correct unit id.
Change:
ca-app-pub-XXXXXXXXXX~XXXXXXXXXX
to:
ca-app-pub-XXXXXXXXXX/XXXXXXXXXX
The adUnit Ids in the new Admob console are of the form:
ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY
This is what your problem is.
Go check your Admob console and update your app to reflect that.
First you have to go to www.admob.com. There sign in with your account. Then klick at "Monetize" next to "Home". There you have to add your app and set the settings for your advertisement. After that, the website is asking you to send you an e-mail with your ad unit id, you have to put in your strings.xml file instead of the exsample id. Hope this helps.
#if UNITY_ANDROID
string adUnitId = " ca-app-pub-8572140050384888/1853336688 "; //no spaces are allowed before and after admob-id..
Change to :
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-8572140050384888/1853336688";
android java admobunity
You don't need to have an app already on the market to get a Publisher ID for a new app. In the Android Package URL field that's on the "Add Site/App" form, just enter "market://details?id=your.package.name". You'll of course want to replace the 'your.package.name' with your app's actual package name.
The viewWidth warnings are fine and you will likely still see them after inserting your Publisher ID.
Refer below links..
How to get Google's example code working for AdMob 4.1.0 using an Android device
AdMob 4.3.1 adds not showing up (No AdMob ID yet (just for test), can't get ViewWidth)
Try this format
GADBannerView * bannerView_;
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
bannerView_.adUnitID=#"ca-app-pub-5250422073333775/6825580043"; //Id for Top Banners
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];

Display Video thumbnails from URL

Okay this might be a stupid one but kindly pardon me because I'm new to Android. I'm working on an App in which I want to display video thumbnails using remote URL's like:
Video URL:
http://173.193.24.66/~kanz/video/flv/9.flv
.JPG URL:
http://173.193.24.66/~kanz/video/Images/9.jpg
I have got both the video URL's and Image File URL's that I want to display on thumbnails stored on SQL database. The only thing is I don't know how to put them in List view inside a ScrollView. I tried searching on the Internet but they all seem to give tutorials on how to display video thumbnails from sd card path. I want to use any of these URL's to display video thumbnails.
I heard about API's but I can't use Youtube API since Youtube is banned in my country. If anyone knows any useful API or any other hack around, let me know. It would be highly appreciated. I'm using Gingerbread.
Add these lines to your Module:app gradle:
dependencies {
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}
// pass video url into .load() method
Glide.with(context)
.asBitmap()
.load(/*Video Url*/)
.into(/*Name of Imageview*/);
Listview has its own scroll. So do not put listview inside a scroll view.
Use a custom listview to display the thumbnail.
Get your urls form the database.
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
http://www.youtube.com/watch?v=wDBM6wVEO70. The talk is about listview and performance.
Use a viewholder.http://developer.android.com/training/improving-layouts/smooth-scrolling.html.
If you are displaying lot of images in listview consider using one of the below libraries.
1.Universal Image loader. https://github.com/nostra13/Android-Universal-Image-Loader.
2.Lazy List. https://github.com/thest1/LazyList.
Both use caching.
For univarsal Image Loader
In your adapter constructor
File cacheDir = StorageUtils.getOwnCacheDirectory(a, "UniversalImageLoader/Cache");
imageLoader = ImageLoader.getInstance();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(a)
// You can pass your own memory cache implementation
.discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.enableLogging()
.build();
// Initialize ImageLoader with created configuration. Do it once.
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.stub_id)//dummy image
.cacheInMemory()
.cacheOnDisc()
.displayer(new RoundedBitmapDisplayer(20))
.build();
In your getview()
ImageView image=(ImageView)vi.findViewById(R.id.imageview);
imageLoader.displayImage(imageurl, image,options);
Those tutorials are correct but you're missing a step. You need to download these images to the device first using the URL. Then you can set them up to be viewed in a listview.
See how to do this in these threads:
How to load an ImageView by URL in Android?
Android, Make an image at a URL equal to ImageView's image
There is a popular open source library that handles downloading and caching of images automatically. Check it out:
https://github.com/koush/UrlImageViewHelper

Categories

Resources