How to add admob?

edited March 3 in Android Mode

sorry my english low.

download Google Play Services in sdk and "google-play-services.jar" add my sketch.

import cassette.audiofiles.*;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.widget.RelativeLayout;
import com.google.ads.*;

edit:

----------
1. ERROR in C:\Users\sebahat\AppData\Local\Temp\android143427635335561130sketch\src\processing\test\bari\bari.java (at line 662)
    RelativeLayout adsLayout = new RelativeLayout(this);
                               ^^^^^^^^^^^^^^^^^^^^^^^^
The constructor RelativeLayout(bari) is undefined
----------
2. ERROR in C:\Users\sebahat\AppData\Local\Temp\android143427635335561130sketch\src\processing\test\bari\bari.java (at line 667)
    AdView adView = new AdView(this, AdSize.BANNER, "xzcxz");  // add your app-id
                                     ^^^^^^
The type AdSize is ambiguous
----------
3. ERROR in C:\Users\sebahat\AppData\Local\Temp\android143427635335561130sketch\src\processing\test\bari\bari.java (at line 669)
    AdRequest newAdReq = new AdRequest();
    ^^^^^^^^^
The type AdRequest is ambiguous
----------
4. ERROR in C:\Users\sebahat\AppData\Local\Temp\android143427635335561130sketch\src\processing\test\bari\bari.java (at line 669)
    AdRequest newAdReq = new AdRequest();
                             ^^^^^^^^^
The type AdRequest is ambiguous
Tagged:
«13

Answers

  • edited May 2016

    @chamo===

    put your code & the real console code rather than your screenshots... there are errors in your errors! (two AdRequest)

  • @chamo=== first error is evident, you are in a fragment, so::

    RelativeLayout ads layout = new RelativeLayout(this.getActivity());

    as for the two others i am quite sure (not any time to see more in details) that you are missing things (builder for adRequest, instance for adSize).

  • edited May 2016
  • edited May 2016

    @chamo=== ok; though i have not tested your code (not any time for this!!!) i can give you some code without error for your on create().Yet, i am sure that there are other errors; first one is your imports; second one is that using gms you have to add metadata in your application element; third one is that you are in a fragment and it is quite sure that you have to get the main UI thread with a runnable... code rewritten below::

                import android.os.Looper;//for setup() if needed
                import android.os.Bundle;
                import android.view.Window;
                import android.widget.RelativeLayout;
                import android.app.Activity;
                //import com.google.ads.*;//un comment if you use other from ads
                import com.google.android.gms.ads.AdRequest;
                import com.google.android.gms.ads.AdView;
                import com.google.android.gms.ads.AdSize;
                import com.google.android.gms.ads.MobileAds;
    
    
    
    
                public void setup(){
                  size(900,600);
                 }
    
                public void draw(){
    
                }
    
                @ Override
                public void onCreate(Bundle savedInstanceState) {
                   super.onCreate(savedInstanceState);
                Window window = getActivity().getWindow();
                 RelativeLayout adsLayout = new RelativeLayout(this.getActivity());
                 RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.MATCH_PARENT);//Fill is deprecated
    
                AdView adView = new AdView(this.getActivity());
                adView.setAdSize(AdSize.BANNER);
                adView.setAdUnitId("xcvbn,,kkk");
                  adsLayout.addView(adView);
                    AdRequest newAdReq = new AdRequest.Builder()
    
                    .build();
    
                    adView.loadAd(newAdReq);
                    window.addContentView(adsLayout,lp2);
    
    
                };
    
  • @akenaton export no problem but apk not launch "Unfortunaely ,bari has stopped"

  • @chamo=== and it does not crash when running with processing ??? no error code???

  • edited May 2016

    @akenaton not crash and no error code.

  • edited May 2016

    @akenaton i dont use if it works but not show ads

    AdRequest newAdReq = new AdRequest.Builder().build();

    adView.loadAd(newAdReq);

  • edited May 2016

    @chamo:: verify your deviceId & adunitId; verify your permissions

  • edited May 2016

    @akenaton

    캡처_2016_05_20_23_34_30_568

    How can I solve this errors?

  • @unnamed===

    this happens because you dont have added the google play service jar to your build path....

  • edited March 3

    @akenaton

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="">
    <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="14"/>
    <application android:debuggable="true" android:icon="@drawable/icon" android:label="">
    <activity android:name=".MainActivity">
    android:theme="@android:style/Theme.NoTitleBar"&gt;
    <intent-filter><action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    </activity>
    <activity android:configChanges="keyboard|keyboardHidden|orientation" android:name="com.google.ads.AdActivity"/>
    </application><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    </manifest>
    
  • @chamo====

    and so??? where are the added jars???

  • @akenaton

    you mean the sdk? I already installed Google Play services package in android SDK manager

  • @ unnamed=== i mean that you have to find the jar and put it in your app folder, subfolder "code"

  • @akenaton

    Oh I see. but where can I cat the jar file?

  • @akenaton

    I got the jar file in http://www.java2s.com/Code/Jar/g/Downloadgoogleplayserviceslibjar.htm this site and I added the jar file in code folder. but still not fixed

  • @unnamed=== what errors in the console???

  • @akenaton

    캡처_2016_05_23_16_30_20_436 캡처_2016_05_23_16_30_32_238 캡처_2016_05_23_16_30_48_438 캡처_2016_05_23_16_30_55_519

    this is errors. Anyway, did I add right jar file?

  • @unnamed:: probably that you have not added the right jar...BTW it is an error to get it from web as it is already in your SDK: copy it from there!

  • @akenaton:: Oh my English.. Sorry but I don't get what you mean... Please explane it easier..

  • @unnamed=== - do not put screen shots from the console: i cannot read them; cut and copy as text

    • your jar is not the good one i think

      • take (copy!) the google play service jar which is your SDK
  • edited May 2016

    @akenaton:: Ok I'm sorry

    Error in
    1. 
    import com.google.ads.*;
    The import com.google cannot be resolved
    
    2.
    import com.google.android.gms.ads.AdRequest;
    The import com.google cannot be resolved
    
    3.
    import com.google.android.gms.ads.AdView;
    The import com.google cannot be resolved
    
    4.
    import com.google.android.gms.ads.AdSize;
    The import com.google cannot be resolved
    
    5.
    import com.google.android.gms.ads.MobileAds;
    The import com.google cannot be resolved
    
    6.
    AdView adView = new AdView(this.getActivity());
    AdView cannot be resolved to a type
    
    7.
    AdView adView = new AdView(this.getActivity());
    AdView cannot be resolved to a type
    
    8.
    adView.setAdSize(AdSize.BANNER);
    AdSize cannot be resolved to a variable
    
    9.
    AdRequest newAdReq = new AdRequest.Builder()
    AdRequest cannot be resolved to a type
    
    10.
    AdRequest newAdReq = new AdRequest.Builder()
    AdRequest cannot be resolved to a type
    

    Those are Errors.

    To sum up, Those errors mean something cannot be resolved, something cannot be resolved to a type, something cannot be resolved to a variable..

  • @akenaton::

    I don't know how to copy jar file here... and the file isn't opened.. but the website which has the jar file says

    Files contained in google-play-services.jar:

    META-INF/MANIFEST.MF com.google.android.gms.auth.GoogleAuthException.class com.google.android.gms.auth.GoogleAuthUtil.class com.google.android.gms.auth.GooglePlayServicesAvailabilityException.class com.google.android.gms.auth.UserRecoverableAuthException.class com.google.android.gms.auth.UserRecoverableNotifiedException.class com.google.android.gms.common.AccountPicker.class com.google.android.gms.common.ConnectionResult.class com.google.android.gms.common.GooglePlayServicesClient.class com.google.android.gms.common.GooglePlayServicesNotAvailableException.class com.google.android.gms.common.GooglePlayServicesUtil.class com.google.android.gms.common.Scopes.class com.google.android.gms.common.SignInButton.class com.google.android.gms.common.data.DataBuffer.class com.google.android.gms.common.data.DataBufferIterator.class com.google.android.gms.common.data.DataBufferRef.class com.google.android.gms.common.data.DataBufferUtils.class com.google.android.gms.common.data.DataHolder.class com.google.android.gms.common.data.DataHolderCreator.class com.google.android.gms.common.data.EntityBuffer.class com.google.android.gms.common.data.Freezable.class com.google.android.gms.common.images.ImageManager.class com.google.android.gms.dynamic.LifecycleDelegate.class com.google.android.gms.internal.a.class com.google.android.gms.internal.aa.class com.google.android.gms.internal.ab.class com.google.android.gms.internal.ac.class com.google.android.gms.internal.ad.class com.google.android.gms.internal.ae.class com.google.android.gms.internal.af.class com.google.android.gms.internal.ag.class com.google.android.gms.internal.ah.class com.google.android.gms.internal.ai.class com.google.android.gms.internal.aj.class com.google.android.gms.internal.ak.class com.google.android.gms.internal.al.class com.google.android.gms.internal.am.class com.google.android.gms.internal.an.class com.google.android.gms.internal.ao.class com.google.android.gms.internal.ap.class com.google.android.gms.internal.aq.class com.google.android.gms.internal.ar.class com.google.android.gms.internal.as.class com.google.android.gms.internal.at.class com.google.android.gms.internal.au.class com.google.android.gms.internal.av.class com.google.android.gms.internal.aw.class com.google.android.gms.internal.ax.class com.google.android.gms.internal.ay.class com.google.android.gms.internal.az.class com.google.android.gms.internal.b.class com.google.android.gms.internal.ba.class com.google.android.gms.internal.bb.class com.google.android.gms.internal.bc.class com.google.android.gms.internal.bd.class com.google.android.gms.internal.be.class com.google.android.gms.internal.bf.class com.google.android.gms.internal.bg.class com.google.android.gms.internal.bh.class com.google.android.gms.internal.bi.class com.google.android.gms.internal.bj.class com.google.android.gms.internal.bk.class com.google.android.gms.internal.bl.class com.google.android.gms.internal.bm.class com.google.android.gms.internal.bn.class com.google.android.gms.internal.bo.class com.google.android.gms.internal.bp.class com.google.android.gms.internal.bq.class com.google.android.gms.internal.br.class com.google.android.gms.internal.bs.class com.google.android.gms.internal.bt.class com.google.android.gms.internal.bu.class com.google.android.gms.internal.bv.class com.google.android.gms.internal.bw.class com.google.android.gms.internal.bx.class com.google.android.gms.internal.by.class com.google.android.gms.internal.bz.class com.google.android.gms.internal.c.class com.google.android.gms.internal.ca.class com.google.android.gms.internal.cb.class com.google.android.gms.internal.cc.class com.google.android.gms.internal.cd.class com.google.android.gms.internal.ce.class com.google.android.gms.internal.cf.class com.google.android.gms.internal.cg.class com.google.android.gms.internal.ch.class com.google.android.gms.internal.ci.class com.google.android.gms.internal.cj.class com.google.android.gms.internal.ck.class com.google.android.gms.internal.cl.class com.google.android.gms.internal.cm.class com.google.android.gms.internal.cn.class com.google.android.gms.internal.co.class com.google.android.gms.internal.d.class com.google.android.gms.internal.e.class com.google.android.gms.internal.f.class com.google.android.gms.internal.g.class com.google.android.gms.internal.h.class com.google.android.gms.internal.i.class com.google.android.gms.internal.j.class com.google.android.gms.internal.k.class com.google.android.gms.internal.l.class com.google.android.gms.internal.m.class com.google.android.gms.internal.n.class com.google.android.gms.internal.o.class com.google.android.gms.internal.p.class com.google.android.gms.internal.q.class com.google.android.gms.internal.r.class com.google.android.gms.internal.s.class com.google.android.gms.internal.t.class com.google.android.gms.internal.u.class com.google.android.gms.internal.v.class com.google.android.gms.internal.w.class com.google.android.gms.internal.x.class com.google.android.gms.internal.y.class com.google.android.gms.internal.z.class com.google.android.gms.maps.CameraUpdate.class com.google.android.gms.maps.CameraUpdateFactory.class com.google.android.gms.maps.GoogleMap.class com.google.android.gms.maps.GoogleMapOptions.class com.google.android.gms.maps.GoogleMapOptionsCreator.class com.google.android.gms.maps.LocationSource.class com.google.android.gms.maps.MapFragment.class com.google.android.gms.maps.MapView.class com.google.android.gms.maps.MapsInitializer.class com.google.android.gms.maps.Projection.class com.google.android.gms.maps.SupportMapFragment.class com.google.android.gms.maps.UiSettings.class com.google.android.gms.maps.internal.ICameraUpdateFactoryDelegate.class com.google.android.gms.maps.internal.IGoogleMapDelegate.class com.google.android.gms.maps.internal.ILocationSourceDelegate.class com.google.android.gms.maps.internal.IMapFragmentDelegate.class com.google.android.gms.maps.internal.IMapViewDelegate.class com.google.android.gms.maps.internal.IProjectionDelegate.class com.google.android.gms.maps.internal.IUiSettingsDelegate.class com.google.android.gms.maps.model.BitmapDescriptor.class com.google.android.gms.maps.model.BitmapDescriptorFactory.class com.google.android.gms.maps.model.CameraPosition.class com.google.android.gms.maps.model.CameraPositionCreator.class com.google.android.gms.maps.model.Circle.class com.google.android.gms.maps.model.CircleOptions.class com.google.android.gms.maps.model.CircleOptionsCreator.class com.google.android.gms.maps.model.GroundOverlay.class com.google.android.gms.maps.model.GroundOverlayOptions.class com.google.android.gms.maps.model.GroundOverlayOptionsCreator.class com.google.android.gms.maps.model.LatLng.class com.google.android.gms.maps.model.LatLngBounds.class com.google.android.gms.maps.model.LatLngBoundsCreator.class com.google.android.gms.maps.model.LatLngCreator.class com.google.android.gms.maps.model.Marker.class com.google.android.gms.maps.model.MarkerOptions.class com.google.android.gms.maps.model.MarkerOptionsCreator.class com.google.android.gms.maps.model.Polygon.class com.google.android.gms.maps.model.PolygonOptions.class com.google.android.gms.maps.model.PolygonOptionsCreator.class com.google.android.gms.maps.model.Polyline.class com.google.android.gms.maps.model.PolylineOptions.class com.google.android.gms.maps.model.PolylineOptionsCreator.class com.google.android.gms.maps.model.RuntimeRemoteException.class com.google.android.gms.maps.model.Tile.class com.google.android.gms.maps.model.TileCreator.class com.google.android.gms.maps.model.TileOverlay.class com.google.android.gms.maps.model.TileOverlayOptions.class com.google.android.gms.maps.model.TileOverlayOptionsCreator.class com.google.android.gms.maps.model.TileProvider.class com.google.android.gms.maps.model.UrlTileProvider.class com.google.android.gms.maps.model.VisibleRegion.class com.google.android.gms.maps.model.VisibleRegionCreator.class com.google.android.gms.maps.model.internal.IPolylineDelegate.class com.google.android.gms.panorama.PanoramaClient.class com.google.android.gms.plus.GooglePlusUtil.class com.google.android.gms.plus.PlusClient.class com.google.android.gms.plus.PlusOneButton.class com.google.android.gms.plus.PlusShare.class com.google.android.gms.plus.model.apps.ApplicationBuffer.class com.google.android.gms.plus.model.moments.ItemScope.class com.google.android.gms.plus.model.moments.Moment.class com.google.android.gms.plus.model.moments.MomentBuffer.class com.google.android.gms.plus.model.people.Person.class com.google.android.gms.plus.model.people.PersonBuffer.class

  • @unnamed===

    all these errors are one::: or you have not added the jar or you have added some version of it which is not the good one; the good one supposing that you have downloaded && updated the SDK is in your SDK folder: you go there, copy the jar and put it in the code folder, that s all.I have tested and seen that everything works fine, without any error.

  • @akenaton Hmm, where did you get the .jar file?

  • @akenation I found the SDK folder and I found google_play_services folder(not jar file) and paste it into the code folder. But still don't work? Do you know where the google play service SDK is?

  • @ unnamed ===

    no, you have to copy/paste the jar which is in the libs folder of google_play_service

  • @akenaton

    캡처_2016_05_28_20_32_11_327

    I can't find libs folder...

  • @unnamed===

    1) Be sure that your SDK is updated with google_Play_services

    2) you are not looking at the good place which, normally, is not in P5 (mode) BUT:

    (anywhere)android_sdk/extras/google/google_play_services/libproject/google_play_services/libs/the jar

  • @akenaton I have installed the google_play_services SDK

    캡처_2016_05_29_10_38_48_760

    SDK Path is different with your path and there is no android_sdk folder of libproject folder.. What's wrong with me?

  • edited May 2016

    @unnamed=== Sorry, i cannot understand why libproject folder is missing...Try to download one new version of the sdk, unzip it elsewhere (not in the P5 folder), go to tools folder launch the monitor.exe , choose sdk manager and install google play services:: then see wether you have the complete folder. And tell me!

  • @akenaton Sorry, I don't understand... Can you just send me the file? My E-mail is yho252525@gmail.com

  • @akenaton What's wrong?

  • @akenaton Anyway, What's ("xcvbn,,kkk") mean?

  • @unnamed====

    means nothing, here you put your unit id

  • @akenaton As you know, I don't have the lib file, so I googled and I found an lib file. I put that in the code folder and only import com.google.android.gms.ads.MobileAds; has error. so I deleted it and the program runs... but when I run the program Unfortunately, adtest has stopped.. is import com.google.android.gms.ads.MobileAds; important?

  • @unnamed=== have you downloaded a new version of your idk and done what i explained??? i cannot send you "my" jar because it must be the same than your lib version.

    Of course this import is important!

  • @akenaton

    i tried to install the sdk in monitor.exe and the result is same.. there is no lib file..

  • @akenaton

    I have a question. Which processing version is you use?

  • @akenaton

    Do you have any Idea?

  • @akenaton

    Which google_play_service Rev. do you use? I think there was a great change for admob. The help page moved to FIREBASE(https://firebase.google.com/docs/admob/android/existing-app#banner_ads) and the way to add ads did changed..

  • @unnamed=== mine one is rev 27 Looking to the firebase code i cannot see great differences as for the code and for the imports.

  • @akenaton === You use rev 27 but I use 30... 30 has no lib file..so it is a great change

  • @unnamed=== you are right; no lib folder in rev30...That is new!

    See here for some workarounds stackoverflow.com/questions/37310684/missing-sdk-extras-google-google-play-services-libproject-folder-after-updat

    But, as for now, i am puzzled with this stuff. You can try to download rev 28 from the provided link. Or try to use the .aar files. I see also that there is (rev30) a "sample" folder; what is inside it???

  • @unnamed===

    ok, i think i begin to understand what they have done: instead of having 1 jar for all the ggplservices they have created a lot of jars which you can use according to your needs. Knowing that the "jar in one" was 5 or 6 mo it seems to be a good idea. Yet i have not tried, i will as soon as possible.

  • @akenaton ==...Hmm.. I will wait for you.

Sign In or Register to comment.