Working on displaying google ads in android app by using stackoverflow
link
After following instructions it shows ad view but ad not display and on ad view a message appears - you must have AdAcitvity declared in AndroidManifest.xml with config changes.
I have allready added activity in manifest,i am surprising why this occure. Please help me in my problem and give your suggestion .
Thanks in Advance.
This is very Good Example of admob integration into android app.
Your problem is nothing just put into manifest file.
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
The question in the link is a bit old. You should make a few changes:
Use the latest version of AdMob. The latest version is 6.4.1 and you can find it here.
Your manifest should have more config changes declared like this:
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
Check all the instructions in the official documentation.
// try this
1. download latest google-play-services,jar
2. add jar to project build path
**main.xml**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/lnrMain">
</LinearLayout>
public class MyActivity extends FragmentActivity {
LinearLayout lnrMain;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lnrMain = (LinearLayout) findViewById(R.id.lnrMain);
runOnUiThread(new Runnable() {
#Override
public void run() {
AdView adView = new AdView(MyActivity.this);
adView.setAdUnitId("0445b7141d9d4e1b");
adView.setAdSize(AdSize.BANNER);
AdRequest.Builder builder = new AdRequest.Builder();
builder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
adView.loadAd(builder.build());
lnrMain.addView(adView);
}
});
}
}
**AndroidManifest.xml**
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.Demo"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="17"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher">
<activity
android:name="MyActivity"
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.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<meta-data
android:name="ADMOB_ALLOW_LOCATION_FOR_ADS"
android:value="true" />
<meta-data
android:name="com.google.android.gms.version"
android:value="4030500" />
</application>
</manifest>
Related
I was tried to embed google map into my android application. When I executed the application it display as below
could anyone help with this?. and my source code .
public class MainActivity extends MapActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
Here is my Manifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.mapp.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>
</application>
</manifest>
You have just tried to develop with deprecated Google Maps Android API v1. This will not work for any new project since March.
Delete all the maps related code (seriously, this is the easiest path) and follow this https://developers.google.com/maps/documentation/android/start to use new Google Maps Android API v2.
I've edited and added features from a programme which has involved adding another class (not activity class) since then when I load the app onto my android device I cannot see an icon appear but the app appears in the Application Manager. I have no errors showing and have commented out each section of the new class to turn it back to the original app. Could anyone tell me whether the problem is most likely to be in the manifest, the main.xml or the activity class? Or if they have come across a similar problem?
Cannot publish code due to company policy.
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myAppName" <!-- real package name cannot be supplied -->
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="com.example.MyAppName.ProviderClassName"
android:authorities="com.example.MyAppName.ProviderClassName"
/>
</application>
</manifest>
can anyone provide me a sample for integrating adwhril into android.I tried this sample
http://paste2.org/p/2168910
I used the same code as that one replacing the sdk key of mine But i am getting warnings saying
Can anyone suggest me
updated the code as suggested and got this warning
Yea, i have also faced this problem and solved in this way
Add those if you didn't already added in your menifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
In your activity where you want to show the add
<meta-data android:value="---- Your Key ----"
android:name="ADWHIRL_KEY"/>
Now add all the jar of the add provider you used, in your ad-whirl network. Add them to your app's libs folder and then add them to build path by right clicking on them from libs.
For example if you use Admob then add admob's jar to libs and add it to build path. And then add this line to menifest as this is needed to show add from admob individually or by using adwhirl
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >
</activity>
Now you will see the adds of admob.
Thank you
Ps: i have added the full code with image
Menifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.expadwhirl"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<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"
android:theme="#style/AppTheme" >
<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>
<meta-data android:value="2f120f401e9a40d0afa55557d3a3a58c"
android:name="ADWHIRL_KEY"/>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >
</activity>
</application>
</manifest>
Layout
<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" >
<com.adwhirl.AdWhirlLayout
android:id="#+id/adwrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
Activity
import android.app.Activity;
import android.os.Bundle;
import com.adwhirl.AdWhirlLayout;
import com.adwhirl.AdWhirlLayout.AdWhirlInterface;
public class MainActivity extends Activity implements AdWhirlInterface {
AdWhirlLayout adwrl;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void adWhirlGeneric() {
// TODO Auto-generated method stub
}
}
Overall project
I am Using Millenial media in my app. i have several apps running with following code but now when i try to copy paste running code for new apps it shows the error java.lang.NoClassDefFoundError: com.millennialmedia.android.MMAdView
this is how i am creating MMAdView object and inserting it in my Linear Layout.
LinearLayout myLayout = (LinearLayout) findViewById(R.id.layoutadd);
adview = new MMAdView(MyClass.this, MYAPID,"MMBannerAdBottom", 30);
myLayout.addView(adview, new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
MMAdListener listener = new MyAdListener();
adview.setListener(listener);
adview.callForAd();
this is the xml declaration
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.xxx"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MyClass"
android:label="#string/app_name"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.millennialmedia.android.MMAdViewOverlayActivity">
</activity>
<activity android:name="com.millennialmedia.android.VideoPlayer"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="keyboardHidden|orientation|keyboard" >
</activity>
</application>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>
i have also imported liabrary...
THIS THING IS WORKING IN MY OTHER APPS JUST IS THAT FROM FEW DAYS ITS NOT WORKING PROPERLY FOR NEW APPS.
This usually happens when the JAR file isn't copied onto the device. On Millennial Media's wiki page, they show you how to add the JAR to your project. After you select the library (9th bullet point), but before you hit "OK", go to the "Order and Export" tab and make sure the checkbox next to MMAdView.jar is checked. By default, it isn't. Push OK and try running your program.
I read a lot of previous AdMob posts, but none sufficiently answer the question about the AdLoader timeout problem. This is the error: http://i42.tinypic.com/9s5ag4.jpg
Note: I am using older jar file (GoogleAdMobAdsSdk-4.1.1.jar) because I am targeting an older Android version.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.something.www"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".AdActivityActivity"
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" >
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
AdActivity.java
package com.something.www;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import com.google.ads.*;
public class AdActivity extends Activity {
private AdView adView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adView = new AdView(this, AdSize.BANNER, "xxxxxxxxxxxxxxx");
LinearLayout layout = (LinearLayout) findViewById(R.id.main);
layout.addView(adView);
AdRequest ar = new AdRequest();
ar.addTestDevice(AdRequest.TEST_EMULATOR);
ar.addTestDevice("425EF274CEBECB11F9EFEBF5B51458B1");
adView.loadAd(ar);
return;
}
}
The code looks fine - this is likely just a network error? Can you reach the internet on a web browser on the emulator/device?
FYI, you can still target old Android versions with the latest AdMob SDK (currently 4.3.1). Check out this blog post for details on how to migrate to 4.3.1.
I was getting this same error (AdLoader timed out after 60000ms while getting the URL), but only in release builds. The error was shown in under 1 second, so it might be a different issue than the one you are having. Disabling proguard optimizations by adding the following to my proguard.cfg solved the problem:
-dontoptimize
# Also comment out the existing line controlling optimizations:
# -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*