This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I get device ID for Admob
My activity has a ListView and I've put an ad at the bottom. When I run the app on the emulator, I see the test ad. When I run on my phone, I get an actual ad. I want to test on my phone and not get real ads.
I followed the instructions on the AdMob site about looking in logcat for a message stating how to manually add the device ID to the AdRequest. The problem is this message would never appear in logcat. This is a RAZR running 4.1. In an SO post, answered by Aracem, I read that the encoded string is available in the Developer Options preference panel, and I found it. When I read the guide for this command, the format of the device ID was alphanumeric (e.g. "E83D20734F72FB3108F104ABC0FFC738"), but the value in my phone contains letters, numbers, and dashes (e.g. "MQKF-RB61-BBKS-E").
I've added the encoded device ID into the XML googleads:testDevices and I've also manually added an AdRequest into my onCreate and use addTestDevice with this string. Neither work.
One thing that I've noticed is the namespace that works is googleads, not ads as shown in the examples. When I use ads, I get prefix errors in the XML. I'm guessing with the switch from 4.x to 6.1, the namespace changed.
I can make this happen with the minimal project where onCreate does nothing more than call super and setContentView.
Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_above="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
googleads:adSize="BANNER"
googleads:adUnitId="#string/admob_id"
googleads:loadAdOnCreate="true"
googleads:testDevices="TEST_EMULATOR, MQKF-RB61-BBKS-E" />
Manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16" />
<application android:label="#string/app_name" >
<activity
android:name="mainActivity"
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|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
In the Logcat, you will find the device ID. You will see something like
To get test ads on this device, call adRequest.addTestDevice("**")
Related
Everything was working fine, the only problem I had is when I change the city to some place south in my country and I get the common "app stopped working problem" but that's fine, I also think what messed this thing up is when I tried to export the application and filled the keystore fields etc.
I searched everywhere on Google and didn't find anything useful, all the solutions I've tried failed so far. Including:
- Creating a whole new project from the beginning with the map only. I still get only grey tiles and no map. (I also tried using MapFragment and not SupportMapFragment)
- I deleted debug.keystore and even default.keyset and generated the API key a few times, still nothing worked.
Here's the code though I don't think there's anything wrong with it:
The Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pfetest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/icon_pfe"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDMsGnxt0GrU7Se5arkExJ96uLKqJWmjcQ"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.example.pfe.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.pfe.Couverture"
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>
</manifest>
I retrieve the map using this on MainActivity in the onCreate() method
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
googleMap = fm.getMap();
</code>
Still need a little try catch for this but it was working.
the layout is like this.
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/m1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="1"
android:orientation="horizontal"
tools:ignore="NewApi" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="458dp"
android:layout_column="0"
android:layout_gravity="left|fill_vertical"
android:layout_row="2"
class="com.google.android.gms.maps.SupportMapFragment" />
</GridLayout>
I just want to press the compile button and get the map working, so if anyone could help with anything, I'll be very grateful!
Problem solved.
Here's what I did for those who encountered such an issue: I first removed the project and re-imported it onto eclipse, renamed the package completely, deleted the debug.keystore file and rebuilt the project to get a new one then regenerated a new API key and put it into my manifest using the new SHA1 fingerprint.
The thing is that I did all of the above several times without success and decided to leave it for a while and retried to run it every now and then (without touching the source code) and today it just worked so maybe the API key needs some time to function correctly.
Feel free to ask me about any detail if you get the same problem!
I'm recently been trying to get R.JAVA to generate with no avail. I've tried the following
1. Adding spaces to the manifest file
2. Project--> Clean
So my last guess is that there is some error in my xml files that I/eclipse haven't been able to see. So I was hoping to have a second pair of eyes that might be able to check my xml files for review. There's only three and they should be pretty basic(I'm following a intro to android book).
Manifest File
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.activites"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity2"
android:label="Activity 2" >
<intent-filter>
<action android:name="com.example.ACTIVITY2" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
Activity2.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Activity 2!" />
</RelativeLayout>
Again thanks to all of you that have taken time out of your busy day/night to help out a beginner like myself. Also if there's any suggestion other than errors in the xml feel free to bring them up.
As requested here are the problems appear in windows-> show view -> problems
R cannot be resolved to a variable
R cannot be resolved to a variable
R cannot be resolved to a variable
Tag is not that obvious it is used to show debug information in catlog with the following lines of code.
public class MainActivity extends Activity {
String tag = "Events";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
Log.d(tag, "In the onCreate() event");
}
In eclipse you can check the Problems view(windows-->show view-->Problems) or/and the Console view to help locate errors in Xml efficiently. If you remain need help you may want to post these errors to us
I get following error when I compile your code:
res\layout\Activity2.xml: Invalid file name: must contain only
[a-z0-9_.]
So remove capital A and rename "Activity2.xml" to "activity2.xml"
Also, if this doesn't help, try this:-
Rename your package name to some other. Clean. Restart Eclipse. Rename package back to the previous one. Again clean. Restart Eclipse.
check your imports. is import android.R anywhere there? if so, remove it. if you're indeed following some android tutorial in a book and it instructed you to organize or manage imports with Ctrl+shift+O or otherwise, that will cause that to pop up.
tag should be a String variable. What is it defined as? You should probably hard-code it there, unless you are using it as a global variable for your application.
http://developer.android.com/reference/android/util/Log.html#d%28java.lang.String,%20java.lang.String%29
EDIT: R cannot be resolved - Android error has a lot of different answers, try reading through those. If the first one doesn't solve your problem, another one might.
I'd like to test my admob ads in my Android application, but the ads can't display. And no error can be found in the logcat. I also can find the success request for ads from Admob.
I use "X" to indicate my publish id.
package com.admob.test;
import android.app.Activity;
import android.os.Bundle;
public class AdmobTestActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.admob.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".AdmobTestActivity"
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|screenLayout|uiMode|screenSize|s mallestScreenSize" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="xxxxxxxxxxxxxxx"
ads:adSize="BANNER"
ads:testDevices="C904358AFB272CDFA888A5C1CB914DA4"
ads:loadAdOnCreate="true"/>
</LinearLayout>
If AdMob says you app status is "Active" it means everything is fine with your code and your app is sending request to admob. The problem is that there is for some reason no ads for you.
As you said it is active I would try this:
Click "Manage Settings" of your app (at AdMob > Sites & Apps) then choose App Settings tab and select
"Use keyword-targeted ads and Google certified ad networks (GCANs) to
improve fill rate."
This way you will have more chances for some ad to display.
You will receive this message at Sites & Apps page:
Google AdSense Ads Enabled Congratulations! Apps in your account have
been enabled to serve Google AdSense ads. For any unfilled ad request,
AdMob will attempt to serve Google AdSense ads to help improve your
fill rate. No further changes are required on your part.
This helped for me. I was not receiving ads, now it works perfectly.
Maybe this will help someone.
Has anyone experienced their app widget not being listed in the ICS app drawer?
Originally I started this app for FroYo and below, which supports the app widget just fine. Along came Gingerbread and Honeycomb, those work too.
The widget appears in the list in the emulator if I open up the "Widget Preview" app, however when you just open the drawer it isn't listed with the others. It does appear on Honeycomb. I don't (and others haven't also) see it on my Galaxy Nexus anywhere either.
I've tried rebooting as I've seen that solving the problem for some people after initial installation. Also I do have a main activity with the action.MAIN/category.LAUNCHER intent filter since I have app activities, this isn't a widget only type of project.
I'll post some snippets below, let me know if more is needed. My minSdkVersion is at 7 and targetSdkVersion at 15, project properties also has the target checked at 4.0.3. The installLocation attribute is set to auto.
AndroidManifest.xml:
<receiver android:name=".AppWidget" android:label="#string/one_cell_widget_label">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<intent-filter>
<action android:name="com.frankcalise.h2droid.FORCE_WIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/one_cell_widget_settings" />
</receiver>
one_cell_widget_settings.xml:
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="#layout/one_cell_widget"
android:minWidth="#dimen/one_cell_widget"
android:maxHeight="#dimen/one_cell_widget"
android:updatePeriodMillis="0" >
</appwidget-provider>
one_cell_widget.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget_background"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/widget_margin"
android:background="#drawable/widget_background">
<TextView
android:id="#+id/widget_title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/widget_amount_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/default_widget_amount"
android:textSize="12sp"
android:textColor="#color/amount_color" />
<TextView
android:id="#+id/widget_percent_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/default_widget_percent" />
</LinearLayout>
and then obviously I implemented the class in AppWidget.java
public class AppWidget extends AppWidgetProvider
UPDATE:
An important logcat message I found earlier today which helped me solve the issue:
06-01 14:41:31.606: E/AppsCustomizePagedView(199): Widget ComponentInfo{com.frankcalise.h2droid/com.frankcalise.h2droid.AppWidget} has invalid dimensions (108, 0)
I found the issue. My appwidget-provider element has a typo in one of the attributes, it should say "minHeight", not "maxHeight".
What lead me to finding this was finding an error output in logcat from the launcher. It mentioned my widget had invalid dimensions (therefore it didn't add it to the list of widgets). So then I started checking all the dimension attributes related to my widget.
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.