I'm incorporating AdMob into my app. I've followed the steps in the developers page. However AdRequest.Builder() is being underlined with red and it says:
AdRequest cannot be resolved to a type
and
AdRequest.Builder cannot be resolved to a type.
What could be the problem?
import com.google.ads.AdRequest;
import com.google.ads.AdView;
public class FireRoomActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fire_room);
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
In xml I've shown admob as such:
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="bla bla"
ads:adSize="BANNER"/>
Your code is mix for Admob SDK (Google Play) and Android (6.4.1 and earlier SDKs)
Use
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
AdRequest adRequest = new AdRequest.Builder().build();
and
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="bla bla"
ads:adSize="BANNER"/>
if you use Admob SDK (Google Play)
Or use
import com.google.ads.AdRequest;
import com.google.ads.AdView;
AdRequest adRequest = new AdRequest();
and
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="bla bla"
ads:adSize="BANNER"/>
if you use earlies SDK
For Admob SDK (Google Play) not forget to change namespase
xmlns:ads="http://schemas.android.com/apk/res-auto"
Try this..
AdRequest adRequest = new AdRequest();
AdView adView = (AdView)this.findViewById(R.id.adView);
adView.loadAd(adRequest);
Note:
Make sure you have included the necessary library
in your project
and permissions in your manifest
.
Also check whether you have given correct ad-mob
id in your xml.
EDIT :
To add test device, you could try
adRequest.addTestDevice(AdRequest.TEST_EMULATOR); //for emulators
adRequest.addTestDevice("device_id"); //for real device, enter device id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With