^ there is the image so you know I'm using sdk 3.2. There is more to this code, but basically this is everything for my java code inside my main one, and it doesn't load my ads when I go to load them. There are no errors and nothing in my Main.XML for the ad Basically the ad is not showing at all
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
public class LearningLettersActivity extends Activity
private AdView adView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create the adView
adView = new AdView(this, AdSize.BANNER, "aXXXXXXXXXXXXXXXX); //<---My Publisher Id there"
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="#+id/mainLayout" \
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
Here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.better.work.learning.letters.and.more"
android:versionCode="3"
android:versionName="1.00">
<application
android:icon="#drawable/icon"
android:label="#string/app_name">
<activity
android:name=".LearningLettersActivity"
android:label="#string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-sdk android:minSdkVersion="4"/>
</manifest>
Basically nothing is pooping up for my ads at all when I go to test it on my phone, I tried using the code below and still nothing.
AdRequest adrequest = new AdRequest();
adrequest.setTesting (true);
adView.loadAd(adrequest);
I've also tried:
AdRequest adrequest = new AdRequest();
adrequest.setTesting (true);
adrequest.setTestingDevices("HT0CWHL11423") //<--- the name of my phone that appears when I go to load the emulator tab
adView.loadAd(adrequest);
Result:
01-18 03:50:19.874: E/Ads(16938): Could not find com.google.ads.AdActivity, please make sure it is registered in AndroidManifest.xml.
01-18 03:50:19.874: E/Ads(16938): You must have AdActivity declared in AndroidManifest.xml with configChanges.
Look in the logcat for anything with the Tag Ads. Specifically, look for something like:
Ad Request successful, but no ad returned due to lack of inventory.
It is possible that you are not getting ads back because AdMob cannot fill an ad.
There are a couple of things to note here. AdRequest.setTesting(true), which only used to set test mode for emulators, is deprecated in favor of AdRequest.addTestDevice(AdRequest.TEST_EMULATOR) for setting test mode on an emulator. For setting a test device, the device id you are supposed to enter is a hashed device id, which you can find in the logcat as well if you are debugging on your device.
Finally, the picture that you're using shows you have the SDK included for a ButtonMasher app, but the code you provided looks like it's for a Letter Learning app. Make sure you are indeed using 4.3.1 in this app.
The Google AdMob Ads SDK for Android requires Android 1.5 or later. Make sure you have the latest copy of the Android SDK and that you're compiling against at least Android v3.2 (set target in default.properties to android-13).
So take android v3.2 as your target version for the latest copy (as your manifest file suggest that you have taken the latest one).
For more details please have a look on this
Hope this will help you.
Related
I am working to integrate the Login Screen of an application I am working to create with AWS Cognito and have been following the step by step instructions to connect with the server.
STEP 5 OF 7
Copy the Mobile Hub Helper and Custom Code
Copy the src/main/java/com/amazonaws folder from the code you downloaded into the java/com folder of your Android Studio project.
This folder contains a set of helper classes that have been custom generated for you. These were generated based on your project configuration and on the AWS cloud resources and identifiers that were created for you when you configured the project. These classes simplify the use of all the SDKs that are required to support your project.
It also contains the source code for the AWSMobileClient which is a singleton component which bootstraps the app and creates an identity manager to establish the user identity with Amazon Cognito. If your project uses the Mobile Hub NoSQL feature the AmazonAws folder will also contain model classes that simplify your access to the DynamoDB tables you configured.
I believe I am running into problems with the last half of this bit as I am unsure what a singleton component is or how to insert it into the code. I have created it as a Java class and included the included code
package com.your.app;
import android.support.multidex.MultiDexApplication;
import android.util.Log;
import com.amazonaws.mobile.AWSMobileClient;
/**
* Application class responsible for initializing singletons and other common components.
*/
public class Application extends MultiDexApplication {
private final static String LOG_TAG = Application.class.getSimpleName();
#Override
public void onCreate() {
Log.d(LOG_TAG, "Application.onCreate - Initializing application...");
super.onCreate();
initializeApplication();
Log.d(LOG_TAG, "Application.onCreate - Application initialized OK");
}
private void initializeApplication() {
// Initialize the AWS Mobile Client
AWSMobileClient.initializeMobileClientIfNecessary(getApplicationContext());
// ... Put any application-specific initialization logic here ...
}
}
however I get a red line in the manifest because it is not connected to an XML file, however the instructions never say to add an XML or to attach it to an XML file so im not sure how to connect these features. I imagine that the Application class should be populated following startup i.e. App opens to the login screen and it somehow initiates the communication with the server to transmit the strings which are typed into the text fields.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jason.mvp">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<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" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="Dreamer"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".LoginActivity" android:theme="#style/NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Application"/>
<activity android:name=".MainActivity" />
<activity android:name=".RegisterActivity" android:theme="#style/NoActionBar"
android:parentActivityName="com.example.jason.mvp.LoginActivity" >
</activity>
</application>
</manifest>
can anyone help me!? Thank you!
Jessy,
It looks like you didn't do step 7 yet or did it wrong? Rather than have .application as an activity you should instead add it directly under application:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="Dreamer"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="com.example.jason.mvp.Application">
Have you started the integration steps for "User Sign-In" yet? You have to walk through those steps as well. One way to display the login view is to use a splash activity as is discussed in step 3 of the user sign-in integration steps.
Kevin
i want to integrate admob code inside my test app, here are the steps i have followed.
Layout file looks like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:id="#+id/layout_ad">
</LinearLayout>
Manifest file looks like this
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".Dummyads2Activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
And finally here how the code looks
public class Dummyads2Activity extends Activity {//implements AdWhirlInterface{
/** Called when the activity is first created. */
private AdWhirlLayout adWhirlLayout;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try{
AdManager.setTestDevices( new String[] { AdManager.TEST_EMULATOR } );
LinearLayout layout = (LinearLayout)findViewById(R.id.layout_ad);
AdWhirlLayout adWhirlLayout = new AdWhirlLayout(this, "my adwhirl id");
Display d = this.getWindowManager().getDefaultDisplay();
RelativeLayout.LayoutParams adWhirlLayoutParams = new RelativeLayout.LayoutParams(d.getWidth(), 72);
layout.addView(adWhirlLayout, adWhirlLayoutParams);
}catch(Exception e){
//Log.e(TAG, "Unable to create AdWhirlLayout", e);
}
}
If i do like this, my app crashes, and no ads appear. Kindly help me in solving the problem.
This really depends on what versions of AdMob and AdWhirl you're using. I'm going to talk about AdMob SDK v6.1.0 and AdWhirl v3.2.0, which are currently the newest versions.
You're probably crashing because of this line:
AdManager.setTestDevices( new String[] { AdManager.TEST_EMULATOR } );
This looks like legacy AdMob AdManager; AdWhirl uses the Google AdMob SDK. Anyhow, if you want test ads with AdWhirl, you want to set testing through AdWhirl, not through an ad network. So remove the above line and set test mode like this:
AdWhirlTargeting.setTestMode(true);
Also, your manifest will need to have a superset of all the permissions and activity definitions of the networks you're mediating with. For AdMob, you'll need to add:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
...
<activity android:name="com.google.ads.AdActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|uiMode|screenSize|smallestScreenSize" />
If you still run into errors, posting some logging output would be useful. If you're using Eclipse, you can find logcat from Window -> Show View -> Other... -> Android -> LogCat. Or you can get the logcat output from the command line using adb logcat with Android's adb tool.
I'm in an early process of developping a game for Android and I'm trying to incorporate an ad banner using AdMob. I have downloaded the sample straight from the tutorial on the official site, so I guess that whatever I'm doing wrong here has to be basic since it crushes after a few seconds when debugging on my Galaxy S2 device. Pleae help.
package com.google.example.ads.fundamentals;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.widget.LinearLayout;
/**
* A simple {#link Activity} that embeds an AdView.
*/
public class BannerSample extends Activity {
private AdView adView;
private final TelephonyManager tm =
(TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
private final String AD_MOB_ID = "my AdMob ID goes here";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create an ad.
adView = new AdView(this, AdSize.BANNER, AD_MOB_ID);
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
layout.addView(adView);
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(tm.getDeviceId());
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
/** Called before the activity is destroyed. */
#Override
public void onDestroy() {
// Destroy the AdView.
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
The Logcat data in a screen shot is here
Edit: Also adding the Manifest.XML, which I suspect is what causeing the problems - amazingly the one that came with the example from the official site had an error in it (according to Eclipse), so I had to modify it a bit:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="3"
android:targetSdkVersion="13" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<activity
android:name=".HelloAdMobActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:screenOrientation="landscape" >
</activity>
</application>
</manifest>
Logcat information would be super useful, but I'm betting on one of these two reasons:
You referenced the SDK as an external Jar, and didn't add it into your libs/ folder. You have two options here to fix this: add it to your libs/ folder, or go to Properties -> Java Build Path -> Order and Export and check the AdMob jar.
You don't have a LinearLayout in your XML with android:id="linearLayout". This is less likely as the sample project should include this.
Alright, so it turns out the problem is with tm.getDeviceId(), which for whatever reason caused the program to crush.
You need to add the following permission.
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
I know this have been discussed many times but I couldn't menage to make this work :(. I really tried but I didn't make it.
I have add the GoogleAdMobAdsSdk-4.0.4.jar to my libs folder and I add it to build path.
What else should I do ? I do not see my banner, it never get shown
I guess I do something very stupid but I can not realize what
this is my activity
package com.google.ads.example;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
public class BannerEssentials extends Activity{
private static final String MY_BANNER_UNIT_ID = "123";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Lookup R.layout.main
LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
AdView adView = new AdView(this, AdSize.BANNER, MY_BANNER_UNIT_ID);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
}
}
this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.ads.example"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".BannerEssentials"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-sdk android:minSdkVersion="3" />
</manifest>
this is my layout main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
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>
Are you compiling your project against android API 13? Check out admob requirements:
Requirements
The Google AdMob Ads SDK for Android requires Android 1.5 or later. Make sure you have the latest copy of the Android SDK and that you're compiling against at least Android v3.2 (set target in default.properties to android-13).
If this does not help, try download and use the latest admob sdk from their official website.
Try to add admob banner in xml file( http://code.google.com/mobile/ads/docs/android/banner_xml.html )
And remember that you won't always see ad in applicatio, even if everything works fine(read what is a fill rate)
Are you setting MY_BANNER_UNIT_ID to your actual publisher ID? If not, you need to go to the AdMob website, and sign up and create a site/app to get your publisher ID.
FYI, 4.0.4 is a pretty old version of the SDK. I would recommend upgrading to 4.3.1 instead. 4.3.1 requires a couple new configChanges in your manifest and requires you to compile against android-13 (4.0.4 does NOT), but it is a more stable and is a more well supported version. You can find documentation on integrating 4.3.1 here.
You need to manually add your app on the admob site. It will ask you for the name and what type of ad banner or interstitial. Mine was not showing even though I had publisher ID, until I manually added it and hit the finish button at the bottom of the page.
I am at my wits' end. I have a special LinearLayout for ads
<LinearLayout
android:id="#+id/layout1"
android:layout_width="fill_parent"
android:layout_height="52dp"
>
</LinearLayout>
I fill it with ads from the code
adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
LinearLayout bout = (LinearLayout) findViewById(R.id.layout1);
bout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
Manifest file looks like this
<!--Permissions-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"
/>
And the JAR GoogleAdMobAdsSdkAndroid-4.1.1 is added to the path.
No ads EVER show up. In Logcat I see that
08-23 12:03:04.527: WARN/Ads(28980): IOException connecting to ad url.
08-23 12:03:04.527: INFO/Ads(28980): onFailedToReceiveAd(A network
error occurred.)
I test this on a real device.
Any suggestions?
With the latest version of admob (4.1 i think) the easy form to put admob ads is with xml. You only should put :
//At the beginin of the xml
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
<com.google.ads.AdView
android:id="#+id/Ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="a14daeadccXXXXX"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
Then the permision and remember dont put padding to de linearlayout or the ads dont appear.
It seems that Manifest file still NEEDS meta data, although the official docs do not say anything about it. So in the manifest file add the meta data (besides other data) and the ads will show up
<application android:label="App Name" android:icon="#drawable/icon">
<meta-data
android:name="ADMOB_PUBLISHER_ID"
android:value="XXXXXXXXXXXXXX"
>
</meta-data>
...
I came up to this conclusion by implementing AdListener and adding Log messages into it. I suggest you do the same in case you need to closely investigate what is going on when an ad has been received.