I am getting this error while integrating InMobi Banner ad.
InMobiBanner is not initialized. Ignoring InMobiBanner.load()
I am using version 7.0.4 of InMobi Ads SDK. I have followed the instructions given in the documentation.
How can I fix this problem? Please help me regarding this.
Finally, I got the solution. Somehow, InMobiBanner is not working if the placement id is given in XML layout. So, we have to initialize the InMobiBanner programmatically with the Java code.
But complete your profile information and add your payment information before integrating the InMobi SDK. Also, don't create any placements before that.
Step 1:
Initialize the InMobiSdk in your Application file with the below code:
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
InMobiSdk.init(this, "Your Account ID");
InMobiSdk.setLogLevel(InMobiSdk.LogLevel.DEBUG);
}
}
Step 2:
Add the Application file in your Manifest file and also make the hardwareAccelerated attribute of application tag to true. Check the sample code given below:
<application
android:name=".MyApplication"
android:hardwareAccelerated="true"
..
<activity
android:name="com.inmobi.rendering.InMobiAdActivity"
android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize|screenLayout"
android:resizeableActivity="false"
android:hardwareAccelerated="true"
android:theme="#android:style/Theme.NoTitleBar"
tools:ignore="UnusedAttribute" />
</application
Step 3:
Add a ViewGroup in your layout so that we can add the InMobiBanner view within that view.
<RelativeLayout
android:id="#+id/banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center" />
Step 4:
Now add the below Java code in your Activity or Fragment to initialize and load the InMobiBanner ad.
InMobiBanner bannerAd = new InMobiBanner(this, 1234567890L);
RelativeLayout adContainer = findViewById(R.id.banner);
float density = getResources().getDisplayMetrics().density;
RelativeLayout.LayoutParams bannerLp = new RelativeLayout.LayoutParams((int) (320 * density), (int) (50 * density));
adContainer.addView(bannerAd, bannerLp);
bannerAd.load();
Hope this helps.
You need to create the InMobiBanner class instance inside UI Thread as it is not thread-safe.
Official documentation says -
Notes:
The InMobiBanner class is not thread-safe. A banner instance must be created on the UI thread.
Similarly, all methods on this instance must be called on the UI thread. Not doing so will lead to unpredictable behavior and may affect your ability to monetize with InMobi.
Hope this answer your question. Thanks
Also, you need to add these line android manifest file
<activity
android:name="com.inmobi.rendering.InMobiAdActivity"
android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize|screenLayout"
android:resizeableActivity="false"
android:hardwareAccelerated="true"
android:theme="#android:style/Theme.NoTitleBar"
tools:ignore="UnusedAttribute"/>
Related
I started to update our wear module to be up to date with latest guidelines of Google Play.
Since I'm doing so, I decided to add the Tiles API to the app. When ready for public release it will already be implemented.
Doc: https://developer.android.com/training/articles/wear-tiles#preview
Very unclear... Does anybody understand this?
The wear-tiles-renderer library provides a way to preview Tiles in an activity within your app.
To preview your Tile, create an activity that uses the renderer library to render the Tile. Add this activity in src/debug instead of src/main, as you’ll use this activity only for debugging purposes. See the following code sample for an example:
I tried adding the example code to the debug folder manually since I can't add it from Android Studio.
Added the xml file in the main and also added in debug folder to test.
When I load the app it opens my main file of folder src/main but freezes.
Do I need to add any code to load the example if in debug?
In Android Studio Dolphin you can now create a Launch configuration without the preview
What the quote from the documentation is trying to explain is that you need a module that looks something like this:
Your actual tile, and everything it needs, goes in the main folder. Then in the debug folder you need the following three things:
Manifest - Pretty standard
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tiles">
<uses-feature android:name="android.hardware.type.watch" />
<application
android:label="#string/tiles_app_name">
<activity
android:name=".MainActivity"
android:label="#string/tiles_app_name"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity - The important thing here is the TileManager
class MainActivity : ComponentActivity() {
private lateinit var tileManager: TileManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.tile_test)
val rootLayout = findViewById<FrameLayout>(R.id.tile_container)
tileManager = TileManager(
context = this,
component = ComponentName(this, SampleTile::class.java),
parentView = rootLayout
)
tileManager.create()
}
override fun onDestroy() {
super.onDestroy()
tileManager.close()
}
}
Layout - Also pretty standard
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tile_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
If you have all of this set up and it's still freezing, you probably have a bug in your Tile class. See if there are any error messages in Logcat that can help you understand what is going wrong.
If you split your TileService and Tile layout code using Horologist
You can use Android Studio previews for this
#WearSmallRoundDevicePreview
#WearLargeRoundDevicePreview
#Composable
fun Run() {
val context = LocalContext.current
LayoutRootPreview(
Run.layout(
context,
context.deviceParams(),
lastRunText = "2 days ago",
startRunClickable = emptyClickable,
moreChipClickable = emptyClickable
)
)
}
See the example here https://github.com/android/wear-os-samples/blob/main/WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/GoldenTilesPreviewsRow1.kt
My app just keeps crashing after I tryed to use banner ads with AdMob (without it everything works just fine). The SplashScreen loads but the app crashes when the game should start. Here are the steps that I followed to implemet this:
1) I made sure that I have installed Google Play Services and Google Repository
2) Then I connected my app to Firebase using Firebase Tool Assistant ( it just added google services.json under the app folder in my project )
3)Then I added the AdMob to my app, as shown here:
4)I added this codes in my layout:
xmlns:ads="http://schemas.android.com/apk/res-auto"
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
5)In my Main Activity class called "Game" I added this code to onCreate() method as you can see here:
public class Game extends Activity {
//ADMOB
private AdView mAdView;
MediaPlayer sound;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//turn title off
requestWindowFeature(Window.FEATURE_NO_TITLE);
//set to full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new GamePanel(this));
//ADMOB
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
int[] sounds={R.raw.chiptune, R.raw.chiptune1, R.raw.chiptune2, R.raw.chiptune3};
Random r = new Random();
int Low = 0;
int High = 4;
int rand = r.nextInt(High-Low) + Low;
sound = MediaPlayer.create(getApplicationContext(),sounds[rand]);
sound.start();
sound.setLooping(true);
}
6) Add this to my strings: <string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
7) In my AndroidManifest.xml I added this pieces of codes:
<!-- Include required permissions for Google Mobile Ads to run-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!--This meta-data tag is required to use Google Play services.-->
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!--Include the AdActivity configChanges and theme. -->
<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 wounder what's wrong, if anybody can help!
Here is the Crash Log:
findViewById(R.id.adView); returns a View if it exists in the layout you provided in setContentView(), otherwise it returns null and that's what happening to you.
mAdView is null so you're getting null pointer exception.
So create a layout.xml, embed GamePanel view and AdView both then pass that layout to setContentView(); method.
I have crash that in my app that I have never managed to reproduce myself but that I know happens occasionally because I can see that in the Google Analytics console.
The crash happens as the user launches the application. An exception is raised when I call setContentView in my Activity derived class
H:0kfgjhA== T:main RuntimeException(Unable to start activity ComponentInfo{com.mydomain·myapp/com.mydomain·myapp.activity.history.HistoryActivit) Cause: NotFoundException(Resource ID #0x7f020134) S:24 00:Resources:android.content.res.Resources.getValue:1274
01:Resources:android.content.res.Resources.getDrawable:797
02:Context:android.content.Context.getDrawable:402
03:ToolbarWidgetWrapper:com.android.internal.widget.ToolbarWidgetWrapper.setIcon:320
04:ActionBarOverlayLayout:com.android.internal.widget.ActionBarOverlayLayout.setIcon:738
05:PhoneWindow:com.android.internal.policy.impl.PhoneWindow.setDefaultIcon:1623
06:Activity:android.app.Activity.initWindowDecorActionBar:2139
07:Activity:android.app.Activity.setContentView:2154
09:MyActivity:com.mydomain·myapp.activity.MyActivity.onCreate:121
The resource that I set in the call to setContentView is an empty FrameLayout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content_frame">
</FrameLayout>
The resource that the Resource class cannot find is the application icon (ID #0x7f020134). That icon is only referenced at one place and that is in the manifest file
<application
android:name=".MyApplication"
android:allowBackup="false"
android:icon="#drawable/my_launcher_icon"
.../>
It seems as this defect appeared after we included the appcompat support library v7. That is done in the manifest file (in the dependencies section)
compile 'com.android.support:appcompat-v7:23.1.1'
Does anybody know anything about this problem? How can I fix it?
According to Google Analytics the crash seems to happen only on 5.0, 5.01 and 5.1.1 devices. And it is not a very frequent crash and it is very stochastic.
Thanks
Ola, Sweden
Edit:
The oncreate function looks like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT >= 21) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
}
setContentView(R.layout.activity_trackid);
}
You can add this line in application tag
android:theme="#style/AppTheme"
Like:
<application
android:theme="#style/AppTheme"
android:name=".MyApplication"
android:allowBackup="false"
android:icon="#drawable/my_launcher_icon"
/>
I am trying to install the ACRA crash report system to my android project. Now, my project is already extending a class, the Activity class. How can I implement the Acra project then?
As they state in normal way, you have to make a class f.e. MyApplication and extend it with Application. Since I am already extending the Activity class I am not sure what to do... They say: If your app already contains an Application subclass, add ACRA to this class; however, I don't know how I should do this..
Thanks!
http://code.google.com/p/acra/wiki/BasicSetup
Just create a MyApplication class that extends from Application, do what they say about overriding onCreate() and then go to your AndroidManifest.
You should have an <application> with values such as android:label or android:theme. Just add android:name=".MyApplication" there and you're ready to go.
Have in mind that if your package is com.example.test, MyApplication has to be there. If you want to put MyApplication wherever else, you must point to where it is.
For example, if your package is com.example.test and MyApplication is in com.example.test.application, you must add android:name=".application.MyApplication to your manifest. I strongly reccomend you to use a package just for your Application, as it atomizes your project and makes it far more manageable and mantainable.
Application is used because of the manifest. In the manifest, it is just to add this to the application tag(with all activities inside):
android:name=".MyApplication"
Ex:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:name=".MyApplication"
android:theme="#style/AppTheme" >
Because of the easy initialization(as it is automatically initialized by the Android System on launch) it will never not report. It can crash instantly on startup and still report. So it is a really smart setup.
My application class looks like this:
#ReportsCrashes(
formUri = "https://backend.com",
customReportContent = { /* */ReportField.APP_VERSION_NAME, ReportField.PACKAGE_NAME,ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL,ReportField.LOGCAT },
mode = ReportingInteractionMode.TOAST,
resToastText = R.string.crash_toast_text
)
public class ACRAHandler extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
final ACRAConfiguration config = new ConfigurationBuilder(this)
.build();
// Initialise ACRA
ACRA.init(this, config);
}
}
If you for an instance are using Firebase, you can use both together in the same application-extending class without any issues. I tried it myself and it worked, no problems with error reporting or Firebase.
Additionally, the new links for ACRA is now on Github: https://github.com/ACRA/acra/wiki/BasicSetup
I answered this because it was so long ago the answers came and it needs an update
An application sub class is required to maintain a global application state, it is not necessary for every app to sub class it. If you app does not have one yet, you can create it.
Example:
/* do ACRA imports */
#ReportsCrashes(formKey = "x-x-x-x-x-x")
public class YourApplication extends Application{
public void onCreate(){
ACRA.init(this);
super.onCreate();
}
}
you should also declare in the manifest file as stated in the tutorial.
i tried using Admob in my app by running it in a device and it showed nothing and i found the followig errors in logcat
04-07 10:49:05.570: ERROR/Ads(1084): AdView missing required XML attribute adUnitId.
04-07 10:49:07.850: ERROR/Ads(1084): Could not find com.google.ads.AdActivity, please make sure it is registered in AndroidManifest.xml.
But in manifest file i have mentioned the following lines
{<meta-data android:value="axxxxxxxxxxxxxxxx" android:name="ADMOB_PUBLISHER_ID"/>
<activity android:name="com.google.ads.AdMobActivity"/>}
What is my error...
I have totally 4 Activities in my App and i am trying to add the admob in my 4th activity.
whether i have to add the above said lines with that activity or anything else pls help me friends...
The error shown can be fixed by adding the following to the manifest file:
<activity android:name="com.google.ads.AdActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|keyboard|keyboardHidden" />