我正在实施谷歌提供的原生广告代码.这样做还可以google
广告单元ID ADMOB_AD_UNIT_ID ="ca-app-pub-3940256099942544/2247696110"
但当我用我的id替换它没有显示广告和执行onAdFailedToLoad方法并且 无法加载原生广告:0错误.
I tried two different ad unit id but it didn't load ad.
so what should I do??please help me
Run Code Online (Sandbox Code Playgroud)
我试过下面的代码
final LayoutInflater li = (LayoutInflater) appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
AdLoader.Builder builder = new AdLoader.Builder(appContext, Global.ADMOB_AD_UNIT_ID);
builder.forContentAd(new NativeContentAd.OnContentAdLoadedListener() {
@Override
public void onContentAdLoaded(NativeContentAd ad) {
//viewHolder.rlnativead.setVisibility(View.VISIBLE);
NativeContentAdView adView = (NativeContentAdView)li
.inflate(R.layout.ad_content, null);
populateContentAdView(ad, adView);
viewHolder.fl_adplaceholder.removeAllViews();
viewHolder.fl_adplaceholder.addView(adView);
}
});
AdLoader adLoader = builder.withAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int errorCode) {
// Toast.makeText(appContext, "Failed to …Run Code Online (Sandbox Code Playgroud) 我通过在片段中使用以下代码来获取用户的运行时权限。
if (ContextCompat.checkSelfPermission(getActivity(),
Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(mActivity,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
STORAGE_PERMISSION_CODE);
}
Run Code Online (Sandbox Code Playgroud)
并压倒一切
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case 21: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the
// contacts-related task you need to do.
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(getActivity(), "Permission …Run Code Online (Sandbox Code Playgroud)