Ich habe mich bei AdMob angemeldet und habe mit hilfe des YT einen Banner problemlos erstellt(App stürtzt bei View.Gone).
Nun wollte ich eine Prämium Ads machen, wo man 10 Videos anschaut für einen Schlüssel.
Habe des wegen YT angeschaut und zu 100% nachgemacht.
Leider Wird keine Testanzeige angezeigt.
Ich brauche Hilfe und möchte Verstehen wo das Problem ist.
AdMob start: https://developers.google.com/admob/android/quick-start?hl=de
Premium: https://developers.google.com/admob/android/rewarded?hl=de
Der erste Versuch (Macht wenig sinn, wo aber in YT klappt):
der zweite Versuch(Wo es mehr sinn macht):
Ich hoffe ihr könnt mir Helfen.
Danke im Vorraus.
Nun wollte ich eine Prämium Ads machen, wo man 10 Videos anschaut für einen Schlüssel.
Habe des wegen YT angeschaut und zu 100% nachgemacht.
Leider Wird keine Testanzeige angezeigt.
Ich brauche Hilfe und möchte Verstehen wo das Problem ist.
AdMob start: https://developers.google.com/admob/android/quick-start?hl=de
Premium: https://developers.google.com/admob/android/rewarded?hl=de
Der erste Versuch (Macht wenig sinn, wo aber in YT klappt):
Java:
package ;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.google.android.gms.ads.AdError;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.OnUserEarnedRewardListener;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
import com.google.android.gms.ads.rewarded.RewardItem;
import com.google.android.gms.ads.rewarded.RewardedAd;
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;
import org.json.JSONException;
import org.json.JSONObject;
public class Ads extends Fragment {
TextView keyText;
Integer keys_menge = 0;
Integer zähler = 0;
ImageView play;
public static String REWARD_AD_UNIT_ID = "ca-app-pub-3940256099942544/5224354917";
private RewardedAd mrewardedAd;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View fragmentlayout_ads = inflater.inflate(R.layout.activity_ads, null);
return fragmentlayout_ads;
}
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
// hier hast du deine View dein Layout
MobileAds.initialize(getActivity(), new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
keyText = (TextView)view.findViewById(R.id.key_ads_textView);
play = (ImageView)view.findViewById(R.id.play_imageView);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showRewardAds();
}
});
CoinImport();
}
private void CoinImport(){
RequestQueue queue = Volley.newRequestQueue(getActivity());
String url = "";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("Virtuell", response.toString());
try {
keys_menge = response.getInt("keys");
keyText.setText(keys_menge + "");
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
alertDialog.setTitle("Volly Error");
alertDialog.setMessage(error.toString());
alertDialog.setCancelable(false);
alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "Okay", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
alertDialog.dismiss();
}
});
alertDialog.show();
}
});
queue.add(jsonObjectRequest);
}
private void showRewardAds(){
if (mrewardedAd != null) {
Activity activityContext = getActivity();
mrewardedAd.show(activityContext, new OnUserEarnedRewardListener() {
@Override
public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
// Handle the reward.
Log.d("Ads", "The user earned the reward.");
int rewardAmount = rewardItem.getAmount();
String rewardType = rewardItem.getType();
}
});
} else {
Log.d("Ads", "The rewarded ad wasn't ready yet.");
}
}
private void Play(){
AdRequest adRequest = new AdRequest.Builder().build();
RewardedAd.load(getActivity(), REWARD_AD_UNIT_ID, adRequest, new RewardedAdLoadCallback() {
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
super.onAdFailedToLoad(loadAdError);
mrewardedAd = null;
}
@Override
public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
super.onAdLoaded(rewardedAd);
mrewardedAd = rewardedAd;
rewardedAd.setFullScreenContentCallback(new FullScreenContentCallback() {
@Override
public void onAdClicked() {
super.onAdClicked();
}
@Override
public void onAdDismissedFullScreenContent() {
super.onAdDismissedFullScreenContent();
}
@Override
public void onAdFailedToShowFullScreenContent(@NonNull AdError adError) {
super.onAdFailedToShowFullScreenContent(adError);
}
@Override
public void onAdImpression() {
super.onAdImpression();
}
@Override
public void onAdShowedFullScreenContent() {
super.onAdShowedFullScreenContent();
}
});
}
});
}
}
der zweite Versuch(Wo es mehr sinn macht):
Java:
package ;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.google.android.gms.ads.AdError;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.OnUserEarnedRewardListener;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
import com.google.android.gms.ads.rewarded.RewardItem;
import com.google.android.gms.ads.rewarded.RewardedAd;
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;
import org.json.JSONException;
import org.json.JSONObject;
public class Ads extends Fragment {
TextView keyText;
Integer keys_menge = 0;
Integer zähler = 0;
ImageView play;
public static String REWARD_AD_UNIT_ID = "ca-app-pub-3940256099942544/5224354917";
private RewardedAd mrewardedAd;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View fragmentlayout_ads = inflater.inflate(R.layout.activity_ads, null);
return fragmentlayout_ads;
}
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
// hier hast du deine View dein Layout
MobileAds.initialize(getActivity(), new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
keyText = (TextView)view.findViewById(R.id.key_ads_textView);
play = (ImageView)view.findViewById(R.id.play_imageView);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showRewardAds();
}
});
CoinImport();
}
private void CoinImport(){
RequestQueue queue = Volley.newRequestQueue(getActivity());
String url = "";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("Virtuell", response.toString());
try {
keys_menge = response.getInt("keys");
keyText.setText(keys_menge + "");
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
alertDialog.setTitle("Volly Error");
alertDialog.setMessage(error.toString());
alertDialog.setCancelable(false);
alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "Okay", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
alertDialog.dismiss();
}
});
alertDialog.show();
}
});
queue.add(jsonObjectRequest);
}
private void showRewardAds(){
if (mrewardedAd != null) {
Activity activityContext = getActivity();
mrewardedAd.show(activityContext, new OnUserEarnedRewardListener() {
@Override
public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
// Handle the reward.
Log.d("Ads", "The user earned the reward.");
int rewardAmount = rewardItem.getAmount();
String rewardType = rewardItem.getType();
}
});
mrewardedAd.setFullScreenContentCallback(new FullScreenContentCallback() {
@Override
public void onAdClicked() {
super.onAdClicked();
}
@Override
public void onAdDismissedFullScreenContent() {
super.onAdDismissedFullScreenContent();
Play();
}
@Override
public void onAdFailedToShowFullScreenContent(@NonNull AdError adError) {
super.onAdFailedToShowFullScreenContent(adError);
}
@Override
public void onAdImpression() {
super.onAdImpression();
}
@Override
public void onAdShowedFullScreenContent() {
super.onAdShowedFullScreenContent();
}
});
} else {
Log.d("Ads", "The rewarded ad wasn't ready yet.");
}
}
private void Play(){
AdRequest adRequest = new AdRequest.Builder().build();
RewardedAd.load(getActivity(), REWARD_AD_UNIT_ID, adRequest, new RewardedAdLoadCallback() {
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
super.onAdFailedToLoad(loadAdError);
mrewardedAd = null;
}
@Override
public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
super.onAdLoaded(rewardedAd);
mrewardedAd = rewardedAd;
}
});
}
}
Ich hoffe ihr könnt mir Helfen.
Danke im Vorraus.