PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → [WM21-59n] Publicité AdMob sous Androïd
[WM21-59n] Publicité AdMob sous Androïd
Débuté par Fabrice De Weerd, 25 avr. 2016 08:33 - 6 réponses
Posté le 25 avril 2016 - 08:33
Bonjour,

J'ai mis une champ publicité dans mon appli Androïd, mais celui-ci reste
désespérément vide, depuis plusieurs jours.

Il me semble pourtant avoir suivi (toutes) les recommandations de PC-Soft.

- Google Play services Rev 29 installé
- Id AdMob annonces ca-app-pub-xxxxxx indiqué à la compilation

Quelqu'un a-t-il un retour d'expérience ou quelques conseils utiles à
partager ?

D'avance merci pour votre aide.

Fabrice De Weerd
www.fawax.com/dev
Membre enregistré
283 messages
Popularité : +4 (4 votes)
Posté le 01 mars 2019 - 01:08
J'ai le même souci.
Je viens d'aller sur le site admob et en voulant ajouter une nouvelle application, le site m'a demandé si elle était diffusée sur le Play Store afin de l'associer.
Du coup, j'ai l'impression qu'il faut passer par cette étape pour que les pub fonctionne.
Je vais voir pour créer un compte Google Developers afin de diffuser mes applis et, peut-être, avoir les pubs dans celles-ci.
Posté le 01 mars 2019 - 06:30
Salut,
Maintenant Google a mis en place un formulaire de consentement.
Rubén Sánchez Peña a mis sur le dépôt un exemple a modifier en version 23 pour que cette demande soit faite.
Voir : https://depot.pcsoft.fr/resource.awp…
Membre enregistré
796 messages
Popularité : +40 (42 votes)
Posté le 01 mars 2019 - 16:26
Bonjour, la procédure d'exemple doit également fonctionner avec WM21. Le code utilisé ne dépend pas de la version de WM.

Mais ensuite votre application devrait être compatible avec les périphériques 64bits, et WM21 ne l'était pas.


Rubén
Message modifié, 01 mars 2019 - 16:28
Membre enregistré
283 messages
Popularité : +4 (4 votes)
Posté le 03 mars 2019 - 23:37
Bonsoir Popoy,

Dommage que le projet soit en WM23 car je n'ai que WM22...:(
Membre enregistré
796 messages
Popularité : +40 (42 votes)
Posté le 04 mars 2019 - 14:41
Je suis désolé, mais je n'ai plus les versions précédentes de WM23 installées.

Rubén
Membre enregistré
796 messages
Popularité : +40 (42 votes)
Posté le 04 mars 2019 - 15:17
Le code Java qui gère le consentement est :

import android.os.Bundle; 
import java.net.URL;
import java.net.MalformedURLException;

//import com.google.android.gms.ads.*;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdRequest;

//import com.google.ads.consent.*;
import com.google.ads.consent.ConsentForm;
import com.google.ads.consent.ConsentFormListener;
import com.google.ads.consent.ConsentInfoUpdateListener;
import com.google.ads.consent.ConsentInformation;
import com.google.ads.consent.ConsentStatus;
import com.google.ads.consent.DebugGeography;

import com.google.ads.mediation.admob.AdMobAdapter;

// Verify the consent form. If the user choice a consent form, then a WM procedure will be called.
public static void VerifyConsentAdmobGPRD_Google(final boolean bRepetirConsentimiento,final String sProcedimiento)
{

consentInformation = ConsentInformation.getInstance(getCurrentActivity());

if (bAD_Debug == true){ // Debug options{
// We add our device as a debug device
//ConsentInformation.getInstance(getCurrentActivity()).addTestDevice(deviceTest);

// AND
// 1) Geography appears as in EEA for test devices.
//ConsentInformation.getInstance(getCurrentActivity()).setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_EEA);

// OR
// 2) Geography appears as not in EEA for debug devices.
//ConsentInformation.getInstance(getCurrentActivity()).setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_NOT_EEA);
}

consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
@Override
public void onConsentInfoUpdated(ConsentStatus consentStatus) {
// Se fuerza la repeticion del formulario
if (bRepetirConsentimiento == true)
consentStatus = ConsentStatus.UNKNOWN;

// User's consent status successfully updated.
if (ConsentInformation.getInstance(getCurrentActivity()).isRequestLocationInEeaOrUnknown() == true)
{

// UE
if (consentStatus == ConsentStatus.PERSONALIZED || consentStatus == ConsentStatus.NON_PERSONALIZED)
{

// User gave his consent yet
if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent","User gave his consent yet");

// We use his choice

// Ads personalized
if (consentStatus == ConsentStatus.PERSONALIZED) 
{
ConsentInformation.getInstance(getCurrentActivity()).setConsentStatus(ConsentStatus.PERSONALIZED);

Bundle extras = new Bundle();
extras.putString("npa", "1");

AD_Request = new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, extras).build();
AD_Estado = "PERSONALIZED";

if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent","User gave consent ads PERSONALIZED");

// We call the first window app 
if (sProcedimiento != ""){
callWLProcedure(sProcedimiento);
}


else // Ads not personalized
{
if (consentStatus == ConsentStatus.NON_PERSONALIZED) 
{
ConsentInformation.getInstance(getCurrentActivity()).setConsentStatus(ConsentStatus.NON_PERSONALIZED);

AD_Request = new AdRequest.Builder().build();
AD_Estado = "NOT PERSONALIZED";

if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent","User gave consent ads NOT PERSONALIZED");

// We call the first window app 
if (sProcedimiento != ""){
callWLProcedure(sProcedimiento);
}
}
}

}
else // User must choose his option and we must sho him the consent form
{
// we must take the user option
//URL privacyUrl = null;
try {
// your app's privacy policy URL.
privacyUrl = new URL(privacidad);
} catch (MalformedURLException e) {
e.printStackTrace();
// Handle error.
}

form = new ConsentForm.Builder(getCurrentActivity(), privacyUrl).withListener(new ConsentFormListener() {
@Override
public void onConsentFormLoaded() {
// Consent form loaded successfully.
//callWLProcedure("COL_GlobalProcedures.DebugMsg","Consent","Form loaded");
showConsentForm();
}

@Override
public void onConsentFormOpened() {
// Consent form was displayed.
if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent","Form showed");
}

@Override
public void onConsentFormClosed(ConsentStatus consentStatus, Boolean userPrefersAdFree) {
// Consent form was closed.
if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent","Form Closed");

// We must manage user shoice
if (userPrefersAdFree == true) 
{ // User choose a option without ads. You can send him to no ads option or you can close the app or other option

// We don't allow use the app without ads
System.exit(0);

}  
else
{ // User choose an ads option

// Personalized
if (consentStatus == ConsentStatus.PERSONALIZED) 
{
ConsentInformation.getInstance(getCurrentActivity()).setConsentStatus(ConsentStatus.PERSONALIZED);

Bundle extras = new Bundle();
extras.putString("npa", "1");

AD_Request = new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, extras).build();
AD_Estado = "PERSONALIZED";

if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent","User choose Personalized ads");

// We call the first window app 
if (sProcedimiento != ""){
callWLProcedure(sProcedimiento);
}


else // Not personalized
{

if (consentStatus == ConsentStatus.NON_PERSONALIZED) 
{
ConsentInformation.getInstance(getCurrentActivity()).setConsentStatus(ConsentStatus.NON_PERSONALIZED);

AD_Request = new AdRequest.Builder().build();
AD_Estado = "NOT PERSONALIZED";

if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent","User choose not Personalized ads");

// We call the first window app 
if (sProcedimiento != ""){
callWLProcedure(sProcedimiento);
}
}
}
}
}

@Override
public void onConsentFormError(String errorDescription) {
// Consent form error.
if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent","Form Error:" + errorDescription);

AD_Estado = "ERROR FORM";

}
})
.withPersonalizedAdsOption() // Show Personalized option
.withNonPersonalizedAdsOption() // Show not Personalized option
.withAdFreeOption() // Show not ads option
.build();

form.load();

}
}
else
{
// no UE
if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent","No UE");

AD_Estado = "NO UE";

// We select here personalized ads
ConsentInformation.getInstance(getCurrentActivity()).setConsentStatus(ConsentStatus.PERSONALIZED);

Bundle extras = new Bundle();
extras.putString("npa", "1");

AD_Request = new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, extras).build();

// We call the first window app 
if (sProcedimiento != ""){
callWLProcedure(sProcedimiento);
}
}
}

@Override
public void onFailedToUpdateConsentInfo(String errorDescription) {
// User's consent status failed to update.
if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent","Error updating ads state: " + errorDescription,"Verify the publisherId values and other configuration data.");

AD_Estado = "ERROR STATE";

}
});


}

// CONFIGURATIONS
static ConsentInformation consentInformation = null;
static ConsentForm form;
static boolean bAD_Debug = false; // Debug option. Activate it to show debug dialogs and debug options
static AdRequest AD_Request = null; // AD Request generated by consent

static String[] publisherIds = {"pub-xxxx"}; // publishers codes
static String publisherId = "pub-xxxxx";
static String deviceTest ="2E34AF58B256EC62CA580546E1F1F7E0"; // Device test code. You will find this code in logcat when you execute this app on device.
static String privacidad = "https://xxxxxxxxxxxxx"; // Url of privacy definition of app
static URL privacyUrl = null;
static String AD_Estado = ""; // State of consent process


private static void showConsentForm(){ 

if (form == null) {
if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent", "Consent form is null");
}

if (form != null) {
if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent", "Showing consent form");

form.show();
} else {
if (bAD_Debug == true)
callWLProcedure("COL_GlobalProceduresGPRD_Google.DebugMsg","Consent", "Not Showing consent form");
}
}


Dans chaque fenêtre où vous voulez afficher la publicité, vous devez inclure un contrôle avec le code :

import com.google.android.gms.ads.*;
import android.view.ViewGroup;

public static void LoadBanner(int nParentId)
{
if (AD_Request != null){
AdView adView = new AdView(getCurrentActivity());
adView.setAdSize(AdSize.BANNER);

if (bAD_Debug == true){
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
}
else {
adView.setAdUnitId("ca-app-pub-xxxxxxxx");
}

adView.loadAd(AD_Request);

ViewGroup parent = (ViewGroup)getCurrentActivity().findViewById(nParentId);
if(parent!= null)
{
parent.addView(adView);
}
}
}


Le principal problème avec les anciennes versions de WM est qu'il n'y a pas de contrôle natif pour inclure le code Java.


Rubén