Interstitial Admob ads: "IllegalStateException: Only fullscreen activities can request orientation" - android

Background
I have an app with Admob SDK used in it, to show Interstitial ads (full screen ads).
Reccently Google has updated the SDK, along with many other things (build tools, gradle plugin, IDE, etc...), including admob (firebase ads).
compile 'com.google.firebase:firebase-ads:11.4.2'
The problem
After updating, I noticed that whenever the app tries to show an Interstitial ad, it crashes.
The crash log is as such:
10-28 14:01:01.394 4523-4523/... I/Ads: Ad opening.
10-28 14:01:01.400 1606-2154/? E/ActivityManager: Activity Manager Crash. UID:10080 PID:4523 TRANS:63
java.lang.IllegalStateException: Only fullscreen activities can request orientation
at com.android.server.am.ActivityRecord.setRequestedOrientation(ActivityRecord.java:2189)
at com.android.server.am.ActivityManagerService.setRequestedOrientation(ActivityManagerService.java:4975)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:1101)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2927)
at android.os.Binder.execTransact(Binder.java:697)
10-28 14:01:01.403 4523-4523/... D/AndroidRuntime: Shutting down VM
10-28 14:01:01.406 4523-4523/... E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{.../com.google.android.gms.ads.AdActivity}: java.lang.IllegalStateException: Only fullscreen activities can request orientation
Thing is that it worked fine before. Now I'm not sure what causes it to occur.
Searching the web, I didn't see anything that talks about "Only fullscreen activities can request orientation" .
What I had in the manifest, is something a bit old, that might not be needed anymore:
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent"/>
I say it's probably not needed, because i can't see it anymore in the tutorials, even though I remember I did in the past:
https://developers.google.com/admob/android/quick-start
https://developers.google.com/admob/android/interstitial
What I've tried
I tried to remove the manifest entry. Still same issue.
I tried to set the theme to be "#android:style/Theme.Translucent.NoTitleBar.Fullscreen" by force, but it also didn't help.
I even thought that it might be because I currently have Android 8.1, but when I tried using the app from the play store, I noticed it worked just fine, without crashes.
I tried to go back to as far as version 11.2.2 of admob and use gradle v 2.3.3 , but it also didn't help.
When trying on an emulator with Android 7.0 , it worked fine with latest versions of everything, and removal of the whole manifest activity tag.
I tried to use this in gradle file, instead of what I used :
compile 'com.google.android.gms:play-services-ads:11.4.2'
Still crashed on my device (Nexus 5x with Android 8.1) yet didn't crash on emulator.
Finally, I tried to run the app on emulator with Android 8.1, and it crashed just as on the real device.
Reported about this to Google Admob team, as well as Android issue tracker. I hope they will answer me about this.
The questions
What could be the cause to this issue?
Is it because of Android 8.1 ? If so, how come the older version of the app worked fine? I tried to revert there a lot of versions to old ones, yet it still crashed.
And, most importantly, how can I solve it?

EDIT
Now a newer admob version is available.
I confirm that using the latest releases (15.0.1 or newer) the issue doesn't appear anymore, so you can use the latest version of Admob
com.google.firebase:firebase-ads:17.1.2
setting the target version to the latest, if you have used the workaround previously suggested.
----------------------------------------------------------
Set the target to Android API Level to 26 to fix the issue, waiting for Admob update
In build.gradle
targetSdkVersion 26
if targetSdkVersion is >=27 ( > android.os.Build.VERSION_CODES.Othat is 26) you get this error, they have changed ActivityRecord in latest Android version adding this:
void setRequestedOrientation(int requestedOrientation) {
if (ActivityInfo.isFixedOrientation(requestedOrientation) && !fullscreen
&& appInfo.targetSdkVersion > O) {
throw new IllegalStateException("Only fullscreen activities can request orientation");
....
}
The change has been introduced in this commit
Prevent non-fullscreen activities from influencing orientation This
changelist enforces that activities targeting O and beyond can only
specify an orientation if they are fullscreen.
and probably in admob lib have messed some check

EDIT
the newer (above 16) admob version fixed the issue
Old Answer
try to add this in your manifest
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
tools:replace="android:theme"
/>
Or, if you are using appcompat:
<style name="TranslucentTheme" parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
etc
And in the manifest, make sure the activity is declared with
android:theme="#style/TranslucentTheme"

please do not use any properties in Android Manifest files AdActivity.
please remove this line from AdActivity in Manifest file
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
Just simply add this following line to Android Manifest file.
<activity android:name="com.google.android.gms.ads.AdActivity" />
If you want to set your desired activity as portrait mode please add this following line to your activities onCreate method:
if (android.os.Build.VERSION.SDK_INT != Build.VERSION_CODES.O) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
For firebase ADS 17.0.0 and upper versions use this line to manifest file.
<application
...........>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/app_id" />
</application>
You can get app id from Admob -> Apps -> your app -> App Settings -> App Id. Please copy and paste this App_Id into your project.

This issue will Automatically be fixed when ad mob will update their ads sdk for API 27
their ads dependency do not support API 27 so due to this issue occurring.
compile 'com.google.android.gms:play-services-ads:11.8.0'
Only full screen activities can request orientation, this is due to ads meta data in your mainfest file,admob should update their sdk for 27 version.
if you have set target sdk version 27 then you would get this error, actually android updating sdk very fast, and some update admob left behind to do ,for integration with android sdk, so admob have pending this update, they should do this very soon ,Its not on developer side issue, if you wants to escape from this crash then set your sdk to 26.

It seems that upgrading to:
com.google.firebase:firebase-ads:15.0.1
solved this issue for me. I've just tested it on Nexus 5X with 8.1.0 and Interstitial Admob ads work now.
More complete solution:
app's build.gradle:
...
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
...
targetSdkVersion 27
..
}
}
dependencies {
...
implementation 'com.google.firebase:firebase-core:15.0.2'
implementation 'com.google.firebase:firebase-ads:15.0.1'
...
}
apply plugin: 'com.google.gms.google-services'
top level build.gradle:
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:3.3.0'
...
}
}
...

I got the same crash with Vungle SDK (which was included through Appodeal SDK), so this does not precisely answer the question related to Admob SDK, but in case anyone's getting this with Vungle or Appodeal SDK:
The versions were as follows: Appodeal SDK - 2.4.2-220518, Vungle SDK - 6.2.5.
After upgrading to the at that time newest Appodeal SDK (version 2.4.9-051218), newer Vungle SDK was included (version 6.3.12) and the crash no longer occured.

In Android Oreo You can't change the orientation by code so you have check whenever change the orientation
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

Related

Login with facebook shows error as unsupported request and failed to login

Login with facebook shows unsupported request and failed to login with unsupported request.
I am using implementation 'com.facebook.android:facebook-android-sdk:12.1.0'
I have added these permissions ["email", "public_profile"]
I'm not exactly sure about your situation but I came across this error message myself in the last few days after updating my Facebook SDK.
After reading through some documentation I found this page...
https://developers.facebook.com/docs/facebook-login/android/deprecating-webviews
which talked about web views being deprecated and to ensure that custom tabs were setup correctly, which in turn lead me here...
https://developer.chrome.com/docs/android/custom-tabs/
I found that Facebook SDK 12.1 required that I set androidx.browser:browser to 1.3.0 or higher to function properly with custom tabs.
This required me to then increase my minSdkVersion to 24 which I didn't want to do.
So after a bit more experimenting I found that I could go back to Facebook SDK 8.2, which still functioned fine in my case, and continue using an older version of androidx.browser:browser allowing me to keep the lower minSdkVersion.
Hopefully that helps you too.
Edit:
Just for completeness, what I am currently using in my dependencies is...
implementation 'com.facebook.android:facebook-login:8.2.0'
implementation 'androidx.browser:browser:1.0.0'
and to get Facebook login 12.1 working I had to use...
implementation 'com.facebook.android:facebook-login:12.1.0'
implementation 'androidx.browser:browser:1.3.0'

Strict Secure Cookie policy error in AdMob after updating to Android 11

After updating my app to compile with API level 30 (Android R, 11), I can't see AdMob test ads, and I'm receiving this error in the log:
Strict Secure Cookie policy does not allow setting a secure cookie for
http://googleads.g.doubleclick.net/ for apps targeting >= R. Please
either use the 'https:' scheme for this URL or omit the 'Secure'
directive in the cookie value.
I'm using the last AdMob version, and I don't have "org.apache.http.legacy" references in Gradle or manifest.
This might come from the webview cookie_manager.cc.
Also this: https://www.chromestatus.com/feature/5633521622188032
Same question here: How to resolved http and Site Behavior: Navigation error in android app?
It might be temporarily broken, unless they'd set the cookie as expected.
I'm using flutter and I'm facing the same issue while implementing banner test ads.
Just add the below in android manifest file under application:
android:usesCleartextTraffic="true"
and issue will be resolved.

Google AdMob TBannerAd LoadAd exception after upgrading to Delphi v10.2.3

My application was originally written using Delphi v10.2.2 and TBannerAd worked just fine.
Without any code changes and after upgrading Delphi to v10.2.3 (by installing over the existing v10.2.2 using the ISO without changing anything in the installation dialogs), calling TBannerAd's "LoadAd" method started triggering this exception:
Project myproject.apk raised exception class EJNIException with message
'java.lang.IllegalStateException: The meta-data tag in your app's
AndroidManifest.xml does not have the right value. Expected 4323000
but found 7095000. You must have the following declaration within the
< application > element: < meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" / >'.
I reviewed the AndroidManifest.xml file and indeed the "7095000" value is used, but I don't know why/how delphi uses this value. Rebuilding the project generates a new AndroidManifest.xml file with the "7095000" value, so I can't directly edit the XML file as a work-around.
What causes this? Is it some setting or SDK path that changed due to the upgrade? (I tried searching but couldn't find anything relevant)
Things I tried:
Completely uninstalling the application and running it again from Delphi (on a real device, a Galaxy note 4).
Under options, changing the NDK API location and C++ Builder NSK Library paths from "\platforms\android-14" to "\platforms\android-19".
Tokyo 10.2.3 has updated Google Play Services and its libraries.
Applications created with old version don't automatically update the libraries to new ones shipped with 10.2.3 release.
To update the libraries go to Project Manager -> Android -> Android SDK xxx -> Libraries and select "Revert System Files to Default" from the popup menu.
After reverting list of included libraries should be

Android Admob implementation: Get the error : "Google Play Services resources were not found"

I tried to upgrade my implementation of AdMob. Using the GoogleAdMobSDK, I would like to turn into the google-play-services-lib.
The ad appears. So it seems ok, but I still got this error at the method call loadAd() in log
Requesting resource 0x7f0c000d failed because it is complex
GooglePlayServicesUtil: The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
Here's my checklist:
I import the library project in my workspace, copying the source.
I reference the library into my project
I add the meta-data in the Manifest
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
My code
this.request = new AdRequest.Builder().addTestDevice(id).build();
this.adView = new AdView(context);
this.adView.setAdUnitId(MY_AD_UNIT_ID);
this.adView.setAdSize(AdSize.SMART_BANNER);
...
this.adView.loadAd(request);
The target version for my app in 9 (2.3). I test on Nexus 5 with KitKat version.
I also tried to put the google-play-services-lib jar in the properties, but no result.
I want to be sure that this error could be handle before submit my app.
This is a benign error with the current version of Google Play Services.
Don't worry about it. Submit your app. Get some sleep.

Error: String types not allowed (at 'screenOrientation' with value 'sensorPortait')

I imported android project an I got 3 errors
error: Error: String types not allowed (at 'screenOrientation' with value 'sensorPortait'). AndroidManifest.xml /com.cartmillimaging.fishingmate.MapViewActivity line 16 Android AAPT Problem
same error on different lines.
<activity android:name=".MapViewActivity" android:screenOrientation="sensorPortait">
For project build target I have selected Google APIs 2.3.3. 10.
I also enabled Java compiler project specific settings and put compiler compliance error to 1.6.
I am new to android development, so can you help me?
checkout your API level. The following attributes:
android:screenOrientation="sensorPortrait" only can work on API level 16+
android:screenOrientation="sensorPortait" can work under level 15
I think it's a fixed bug
There's a typo error in the value. The correct name is "sensorPortrait"
when you load project I get this error (I use api level 10). I found solution for this. You change screenOrientation to something else, save it, and then return to sensorPortait and everything now is working.
Confirmed what cashmere said.
i changed all
android:screenOrientation="sensorPortrait"
to
android:screenOrientation="sensorLandscape"
built the project and then changed it back again for all my activites in the manifest and all works good :)
Had this error and couldn't kick it. Some how my build settings had API 13 selected... Selected API 21 and yay no more issue!

Categories

Resources