Admob Limit Placed on my Account More Than 8 months - java

Ad serving on your account is currently being limited due to invalid traffic concerns. We’ll automatically review and update this limit as we continue to monitor your traffic.
It's been 8 months now the limit is still there and of course, there is no way to contact the AdMob team. It all started when I ran a google ads install campaign for one of my apps and I got a very high volume of installs and thus high impression and earnings from the app, then boom I got a limit on my account. I have paused the campaign and deleted all the ad unit id for all my apps and after 7 days the warning goes away but when I create a new ad unit and I get as little as 10 requests and 2 impressions the limit comes back. I have done that several times but it's Limit still comes and goes. I don't know what to do anymore please I need your help. Below is how I show Admob ads via firebase in my app.
private InterstitialAd mInterstitialAd;
//innitiatizing the ads
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-1137773547201239/7187777199");
mInterstitialAd.loadAd(new AdRequest.Builder().build());//loading the ads
if (mInterstitialAd.isLoaded()) {
final ProgressDialog dialog=new ProgressDialog(MainActivity.this);
dialog.setMessage("Loading...");
dialog.setCancelable(false);
dialog.setInverseBackgroundForced(false);
dialog.show();
Handler handler = new Handler();
Runnable r = new Runnable() {
public void run() {
dialog.dismiss();
mInterstitialAd.show();
}
};
handler.postDelayed(r, 2000);
}
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
#Override
public void onAdFailedToLoad(LoadAdError adError) {
// Code to be executed when an ad request fails.
}
#Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
}
#Override
public void onAdClicked() {
// Code to be executed when the user clicks on an ad.
}
#Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
#Override
public void onAdClosed() {
// Code to be executed when the interstitial ad is closed.
mInterstitialAd.loadAd(new AdRequest.Builder().build());//Reloading the ads
}
});
}
This is the code and permissions in my manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.android.vending.BILLING"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-1132553547777239~2704777871"/>

Related

Why previous Activity get destroyed pressing up button on Setting Activity Toolbar?

GOAL: when the user press back on SettingsActivity toolbar the previous Activity should be resumed from where the user left.
PROBLEM: From Activity lifecycle reported on android developer website I understand that the previous Activity should be resumed calling OnResume method, instead in my case the MainActivity start again calling OnCreate method.
In particular the flow is as follows:
1) User click on icon to start SettingsActivity
2)MapsActivity invokes onPause, then onSaveInstanceState, then onStop
3) User click back button on SettingsActivity
4)MapsActivity invokes onDestroy then onCreate (and everything I tried to save during point 2 with saveInstanceState is lost because Bundle is always null)
CODE
MapsActivity (main activity)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// .... other initialization code ... //
// If location permission is granted initialize Map
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mapSync();
} else {
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSION_FINE_LOCATION);
}
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean("prova", true);
}
// Where I start the second activity
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.connection_type:
// .... handle this case ... //
case R.id.settings:
Intent intent = new Intent(MapsActivity.this, SettingsActivity.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
SettingsActivity (called activity)
public class SettingsActivity extends AppCompatActivity
{
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
// Set the toolbar
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
myToolbar.setTitle("Settings");
myToolbar.setNavigationIcon(R.drawable.ic_baseline_arrow_back_24px);
myToolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
finish();
}
});
setSupportActionBar(myToolbar);
}
public static class MainSettingsFragment extends PreferenceFragmentCompat {
public final static String KEY_ENABLE_BACKGROUND_UPDATE = "enable_background_update";
public final static String KEY_ENABLE_LAST_KNOWN_LOCATION = "enable_last_known_location";
public final static String KEY_DELETE_DB_DATA = "delete_db_data";
public final static String KEY_CHANGE_MAP_COLOR ="change_map_color";
private SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener;
#Override
public void onCreatePreferences(Bundle bundle, String s) {
// Load the Preferences from the XML file
addPreferencesFromResource(R.xml.preferences);
preferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
#Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals(KEY_DELETE_DB_DATA))
{
String connectivityType = sharedPreferences.getString(key, null);
new DeleteAreaAsync(SignalAreaDatabase.getDatabase(getContext()), connectivityType).execute();
} else if(key.equals(KEY_CHANGE_MAP_COLOR)){
String gradientColor = sharedPreferences.getString(key, null);
SignalAreaDrawer signalAreaDrawer = SignalAreaDrawer.getSignalAreaDrawer();
signalAreaDrawer.setGradientColor( gradientColor);
}
}
};
}
#Override
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(preferenceChangeListener);
}
#Override
public void onPause() {
super.onPause();
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(preferenceChangeListener);
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Less accurate location: telephony manager and location requests -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Access to wifi network information -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Change wifi connectivity state -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:parentActivityName=".MapsActivity"
android:theme="#style/PreferenceScreen" />
</application>
QUESTION: how can I restore the previous Activity state and show to the user exactly what he was visualizing when he opened the second Activity?
EDIT #1:
I tried to override oonDestroy() , onSaveInstance(), onRestoreInstance() and this is what happens:
when I start the setting activity, the main activity go onPause() as I would expect.
when I press the back button on the settings activity , the main activity go before onDestroy() and immediately after onCreate(), not calling onSaveInstance() or onRestoreInstance() at all.
EDIT #2: the app didn't go through onSaveInstanceState(Bundle outState) probably because I declared it public. Now the app calls it. So I tried to save some info like outState.putBoolean("prova", true); but when the mainActivity is destroyed , at new onCreate(Bundle savedInstanceState) invokation the Bundle savedInstanceState is always null.
EDIT #3: as #SherifelKhatib suggested I tried to delete all finish() statement from MapsActivity, and I tried to substitute MapsActivity with a minimal EmptyActivity to see if the problem was in MapsActivity. Unfortunately the app has the same behaviour.
When the user press the back button the previous app is always destroyed. No way to restore its state.
EDIT #4: what I tried and still doesn't work. Modifying SettingsActivity :
First approach
#Override
public void onBackPressed(){
moveTaskToBack(true);
}
Second approach
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
Third approach
#Override
public void onBackPressed() {
Intent backIntent = new Intent(this, MapsActivity.class);
backIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(backIntent);
}
And add this in MainActivity:
Intent intent = new Intent(MapsActivity.this, SettingsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
SOLUTION:
Add this attribute to MainActivity in the manifest .
android:launchMode="singleTop"
Explanation
The "standard" and "singleTop" modes differ from each other in just
one respect: Every time there's a new intent for a "standard"
activity, a new instance of the class is created to respond to that
intent. Each instance handles a single intent. Similarly, a new
instance of a "singleTop" activity may also be created to handle a new
intent. However, if the target task already has an existing instance
of the activity at the top of its stack, that instance will receive
the new intent (in an onNewIntent() call); a new instance is not
created.

Android MobileAds loads ad too long

I want my Android application to display ad – InterstitialAd. I want it appears after the welcome screen. It means that I have WelcomeActicity that appears on app start, and recently after this – the ad is displayed.
I create InterstitialAd and start loading ad in application’s OnCreate() method. If application was closed for the long time, ad loads for more then 13 seconds. Of course this is inappropriate – user should not wait for so long. I made this tests building release apk that was directly installed on my phone Xiaomi Redmi 4X.
So the question is – should it be done in some other way? Or ad is always loaded for the long time and I just need to move it forward in user’s workflow?
In app's OnCreate() I start loading
public class MyApp extends Application {
private FullScreenAd mFullScreenAd;
#Override
public void onCreate() {
super.onCreate();
mFullScreenAd = new FullScreenAd(this);
mFullScreenAd.loadAd();
}
}
Implementation is the following:
public class FullScreenAd{
private static final String APP_AD_ID = "ca-app-pub-3940256099942544~3347511713";
private static final String SCREEN_AD_ID = "ca-app-pub-3940256099942544/1033173712";
private String mAdAppId;
private String mAdScreenId;
private InterstitialAd mInterstitialAd;
private long mLoadStart;
public FullScreenAd(Context context) {
super();
DebugLogger.d();
mContext = context;
initAdIDs(null, null);
}
private void initAdIDs(String adAppId, String adScreenId) {
DebugLogger.d();
mAdAppId = (adAppId != null) ? adAppId : APP_AD_ID;
mAdScreenId = (adScreenId != null) ? adScreenId : SCREEN_AD_ID;
mInterstitialAd = new InterstitialAd(mContext);
mInterstitialAd.setAdUnitId(mAdScreenId);
setInterstitialAdListener();
}
public void loadAd() {
// Initialize the Mobile Ads SDK.
MobileAds.initialize(mContext, mAdAppId);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
// Start loading the ad in the background.
mAdIsLoaded.set(false);
mInterstitialAd.loadAd(adRequest);
mLoadStart = System.currentTimeMillis();
}
private void setInterstitialAdListener() {
DebugLogger.d();
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
DebugLogger.d();
DebugLogger.d(String.format("Ad loaded in %d ms", System.currentTimeMillis() - mLoadStart));
mAdIsLoaded.set(true);
}
});
}
public void showAd(OnAdClosedAction action) {
DebugLogger.d();
mInterstitialAd.show();
}
}
Loading an AddMob interstitial ad takes some time. Usually it's as quick as a few seconds, but can go up to 20-30 seconds if the connection is poor, or the ad contains animation/video. It might even not load at all!
A good practice is to load and keep in memory the ad upon app launch, and show it later at some point - make it all as seamless as possible. Make sure that ad loading/displaying is not interfering with user experience - don't make the user wait for your ad loading.
Yes, loading interstitial can take some time, it is advisable to load ad in advance:
mInterstitialAd.loadAd(adRequest);
and show it when you want
mInterstitialAd.show();
but as you are saying you want you start your app with an interstitial ad on the launch itself. It may result in google policy violation as it says you can't show ad on app load or exit.

Android Studio - HTML Buttons in MainActivity.java

So beforehand I made a project with Phonegap. In the Index.html file of the project I have this Button:
<button class="button" onclick="next()">Next Question</button>
Now i've imported this project into Android Studio to get it working with Admob to load interstitial ads like this:
MainActivity.java
import org.apache.cordova.*;
public class MainActivity extends CordovaActivity{
InterstitialAd mInterstitialAd;
private InterstitialAd interstitial;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)){
moveTaskToBack(true);
}
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
loadInterstitial();
}
public void loadInterstitial(){
//Interstitial Intergration Part
AdRequest adRequest = new AdRequest.Builder().build();
//Prepare the Interstitial Ad
interstitial = new InterstitialAd(MainActivity.this);
// Insert the Ad Unit ID
interstitial.setAdUnitId(getString(R.string.admob_interstitial_id));
interstitial.loadAd(adRequest);
//Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
public void onAdLoaded(){
//call displayInterstitial() function
displayInterstitial();
}
});
}
public void displayInterstitial(){
//If Ads are loaded, show Interstitial else show nothing.
if (interstitial.isLoaded()){
interstitial.show();
}
}}
So now I want to get the loadInterstitial(); function called when the button above is pressed. Is this possible when the button is already initiated in the HTML file? if so ( or not ), can I possibly get a step in the right direction?
Thanks!

Android - after splash screen app stuck - can open ads - only on Android 4.4+

I've made app that has splash screen, and after the app is loading the ads, the splash screen is gone and the ads is open (full screen).
it's working on android 2.3 to 4.2 (made it for APK 8), but on 4.4+ its getting stuck - it's only showing the splash screen logo but isn't moving to the ad itself (checked on galaxy 5/4, Nexus 4/5).
by the way - I have the 4.4 jar:
splash_screen_logo.java
public class splash_screen_logo extends Activity {
private InterstitialAd interstitial;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen_logo);
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("*****"); // deleted the id
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest);
// Begin loading your interstitial.
displayInterstitial();
interstitial.setAdListener(new AdListener() {
public void onAdLoaded(){
finish();
displayInterstitial();
}
#Override
public void onAdClosed() {
// TODO Auto-generated method stub
super.onAdClosed();
Intent intent_openStartingPage = new Intent(splash_screen_logo.this, MainActivity.class);
startActivity(intent_openStartingPage);
}
});
}
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
}
why in the Android 4.4 it's getting stuck?
You haven't provided enough information to debug your question. but you should NOT be calling interstitial.show from OnAdLoaded as this results in a very poor user experience.
Calling finish from OnAdLoaded is also not a good idea. As this means your Actiivty will be terminated when you have received an ad, potentially before your Activity or your Ad has had a chance to be displayed.

Admob - no ad to show

Hello
I try to make some example program showing ads on Android phone, and I try to test it on Emulator of v2.2
Everything in code seems to be fine, but AdListener in debugger says that:
Response message is zero or null;
onFailedToReceiveAd( No ad to show).
Is there any way for it to be my fault? Did anyone encounter same problem?
Heres the code
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.AdTest"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".AdTest"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- AdMobActivity definition -->
<activity android:name="com.google.ads.AdActivity"
android:configChanges="orientation|keyboard|keyboardHidden" />
</application>
<uses-sdk android:minSdkVersion="7"></uses-sdk>
<!-- AdMob SDK requires Internet permission -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Layout xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
</LinearLayout>
and Activity code
package com.AdTest;
import com.google.ads.*;
import com.google.ads.AdRequest.ErrorCode;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
public class AdTest extends Activity implements AdListener{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layout = (LinearLayout)findViewById(R.id.main);
AdView adView = new AdView(this, AdSize.BANNER, "anonymouse");
// Unit ID is correct, I changed it on purpose while pasting here
adView.setAdListener(this);
layout.addView(adView);
AdRequest request= new AdRequest();
adView.loadAd(request);
}
public void onFailedToReceiveAd(AdView adView)
{
Log.d("AdListener", "onFailedToReceiveAd");
}
public void onFailedToReceiveRefreshedAd(AdView adView)
{
Log.d("AdListener", "onFailedToReceiveRefreshedAd");
}
public void onReceiveAd(AdView adView)
{
Log.d("AdListener", "onReceiveAd");
}
public void onReceiveRefreshedAd(AdView adView)
{
Log.d("AdListener", "onReceiveRefreshedAd");
}
#Override
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
}
#Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
Log.d("AdListener", "onFailedToReceiveAD");
}
#Override
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
#Override
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
#Override
public void onReceiveAd(Ad arg0) {
Log.d("AdListener", "Received succesfully");
}
}
I have confront the same problem with
onFailedToReceiveAd( No ad to show).
It seems AdMob not sent ad content for our app for some reasons. Even when I in testing mode there's still no ad.
I create my house ad on AdMob to verify my application. It's an easier way in development than testing mode.
I implemented AdListener on my Activity and set it as the AdView listener, then added the following
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1)
{
Log.d("AdMob", "Failed to receive an Ad. Requesting a new one..." + arg1);
arg0.stopLoading();
arg0.loadAd(new AdRequest());
}
I had the same problem too. So I changed the code to set the test mode true, then the Admob test ad started to show on the emulator. Try this in your OnCreate() method:
LinearLayout layout = (LinearLayout)findViewById(R.id.main);
AdView adView = new AdView(this, AdSize.BANNER, "anonymouse");
// Unit ID is correct, I changed it on purpose while pasting here
adView.setAdListener(this);
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
If you run this on a real device and still no ad to show, then I guess it might have something to do with Admob fill rate.
Change the test mode to true. Note that ads will not be displayed until at least 3 access attempts are made for the day.
It appears that the latest admob SDK 4.0.4 doesn't display ads on 1.5 devices.
In the emulator it works fine for 1.6+, but not 1.5.
I think its from the new cross-over advertising with AdSense. As far as I can tell the SDK now wraps a webview as the visual component of the view so it can publish the different kinds of ads. A close look at the log shows WebView.multitouch enabled - as 1.5 doesn't support multitouch (for us developers in Java) due to Apple throwing its toys out of the pram and having a dummyspit (I understand they believe only they are allowed to use two fingers at once..) and perhaps enabling multitouch on the webview causes an internal exception and the view never gets created, and thus cannot receive the HTML reply from the admob http server.
Also see this link
1/ get the latest SDK version
2/ try admob demo with your publisher id
3/ try it in test mode (this should work always)
4/ try to add some sample house ads (shown when there is no other ad available)
5/ try to change your keywords
In general, admob prints detailed error to log (ID missing, activity missing in manifest etc).
I had done the admob integration and that is run on device as well as on emulator.
so, please try below code:
I think you have to remove textview from main.xml
and also try this:
1) Create new app on in your admob a/c
2) then simply replace the id of previous app by new one
try it bro.
I also get this problem. You can try to customized the request, before loading. Like this:
AdRequest re = new AdRequest();
//re.setTesting(true);
re.setGender(AdRequest.Gender.FEMALE);
adview.loadAd(re);
I put my example, apk file and source code here, you can try:
Add Google Admob in Android Application

Categories