jimmykobe1171 / EmbeddedCorovaWebViewDemo

An Android Studio project that use cordova android 4.0.0 to embed cordova webview to native android application
22 stars 15 forks source link

Importing Cordova App and then Adding Banner #1

Open moeenuddin opened 9 years ago

moeenuddin commented 9 years ago

I read your post for embeding cordova in Android project. Thanks for sharing knowledge.

I want to know, what if, i use import to load my cordova project in Android Studio. right now, it imports correctly, but i want to add Admob Banner at the bottom. A statement of loadUrl() is loading the page correctly, now the Layout is to be added at the bottom. If i setContentView with the newly created AD View, My cordova app view hides behind it( i guess so). Either way, I am see one view, my cordova index view or My Ad banner view. I want to add banner view such that rest of the Cordova index view is seen as well and touchable as well.

Thanks in Advance :)

jimmykobe1171 commented 9 years ago

Hi moeenuddin,

Do you use the xml to config the layout? I haven't try out this, but I imagine putting the AdView in the same xml with the cordorva webview, and then use relative layout to config their position, say the AdView is at the bottom.

for example:

<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"
    tools:context="com.example.jimmy.embeddedcordovawebviewdemo.TestCordovaWithLayoutActivity">

    <org.apache.cordova.engine.SystemWebView
        android:id="@+id/cordovaWebView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

     <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>

</RelativeLayout>
moeenuddin commented 9 years ago

I am using this code right now. I guess, I have right now no serving of Ads, due to numerous device testing. But your post gave me the biggest clue for it. Though Ad is not showing up right now. If I got it working, I will keep you posted. Thanks.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CordovaActivity"
tools:ignore="MergeRootFrame">
<org.apache.cordova.CordovaWebView
    android:id="@+id/rudView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:layout_above="@+id/ad_view" />

<com.google.android.gms.ads.AdView
    android:id="@+id/ad_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id"
    android:visibility="visible" />
</RelativeLayout>