Need help with imported cordova project

108 views
Skip to first unread message

huym...@gmail.com

unread,
Jul 26, 2018, 8:07:36 PM7/26/18
to Google Mobile Ads SDK Developers
I created a project in cordova cli then imported it into android studio via gradle. I managed to put admob into the project but the banner is on top of the layout. I want to put it at the bottom of the layout. Can someone help?
This is the code in androidmanifest.xml:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="xxx" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:name="com.google.android.gms.ads.AdActivity" />
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
</manifest>

This is the code in mainactivity.java

import android.os.Bundle;
import org.apache.cordova.*;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;

public class MainActivity extends CordovaActivity
{
private AdView mAdView;
private String ad_unit_id = "xxx";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}

// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
// Set Ads
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);

// Create a banner ad. The ad size and ad unit ID must be set before calling loadAd.
mAdView = new AdView(this);
mAdView.setAdSize(AdSize.SMART_BANNER);
mAdView.setAdUnitId(ad_unit_id);

// Create an ad request.
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();



// Add the AdView to the view hierarchy.
layout.addView(mAdView);

// Start loading the ad.
mAdView.loadAd(adRequestBuilder.build());

// Show Ads
addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
@Override
public void onResume() {
super.onResume();

// Resume the AdView.
mAdView.resume();
}

@Override
public void onPause() {
// Pause the AdView.
mAdView.pause();

super.onPause();
}

@Override
public void onDestroy() {
// Destroy the AdView.
mAdView.destroy();

super.onDestroy();
}
}

mobileadssdk-a...@google.com

unread,
Jul 27, 2018, 2:50:04 AM7/27/18
to huym...@gmail.com, Google Mobile Ads SDK Developers
Hi,

Looking at your code snippets, please note that the first view (in your scenario is the AdView) added to the vertical LinearLayout is expected to be placed at the top of the layout.

Since you wish to put the AdView at the bottom relative to the layout, then I believe it's best to use a RelativeLayout for this scenario instead of a LinearLayout. You may refer to this code snippet on how it is implemented on our BannerExample app's main XML layout.

In addition, you may refer to the code snippets below on how you can do this programmatically on runtime inside onCreate.
protected void onCreate(Bundle savedInstanceState) {

....

RelativeLayout parentLayout = new RelativeLayout(this);

adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("YOUR AD UNIT ID");

RelativeLayout.LayoutParams adViewParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT
, RelativeLayout.LayoutParams.WRAP_CONTENT);
adViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
parentLayout.addView(adView, adViewParams);

AdRequest adRequest = new AdRequest.Builder()
.build();
adView.loadAd(adRequest);

addContentView(parentLayout, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT
, RelativeLayout.LayoutParams.MATCH_PARENT));

}
However, since your concern is more on general Android code implementation rather than anything specific to the Mobile Ads SDK, it's best to raise any implementation concerns to the Android developer forums to get more accurate recommendations. Please note that our team (Mobile Ads SDK Team) can mainly assist you on technical concerns specific to the Mobile Ads SDK.

Regards,
Ivan Bautista
Mobile Ads SDK Team




--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/fe71f89f-c5d6-4fe7-9163-40d62b47eb6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

SL7 Tech

unread,
Apr 23, 2020, 6:49:05 AM4/23/20
to Google Mobile Ads SDK Developers
Hi, can you tell me how did you get admob working on your cordova app? I've been trying a lot of  cordova plugins but nothing is working.

Mobile Ads SDK Forum Advisor Prod

unread,
Apr 23, 2020, 10:40:33 AM4/23/20
to lamsa...@gmail.com, google-adm...@googlegroups.com
Hi SL7 Tech,

Thank you for bringing this issue to our attention.

To start with this forum is for providing support to people who are implementing our SDK in Android Studio, iOS Xcode, and Unity.

We are not able to support cordova or any plugins that might be used to do that.

Regards,
William Pescherine
Mobile Ads SDK Team

ref:_00D1U1174p._5001UaS3AF:ref
Reply all
Reply to author
Forward
0 new messages