ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
.setTagForUnderAgeOfConsent(false)
.build();
consentInformation = UserMessagingPlatform.getConsentInformation(this);
consentInformation.requestConsentInfoUpdate(
this,
params,
new ConsentInformation.OnConsentInfoUpdateSuccessListener() {
@Override
public void onConsentInfoUpdateSuccess() {
// The consent information state was updated.
// You are now ready to check if a form is available.
if (consentInformation.isConsentFormAvailable()) {
}
}
},
new ConsentInformation.OnConsentInfoUpdateFailureListener() {
@Override
public void onConsentInfoUpdateFailure(FormError formError) {
// Handle the error.
}
});
Import
Add the imports option and add the following imports
com.google.android.ump.ConsentForm;
import com.google.android.ump.ConsentInformation;
import com.google.android.ump.ConsentRequestParameters;
import com.google.android.ump.FormError;
import com.google.android.ump.UserMessagingPlatform
Moreblock LOADFORM
In the moreblock loadform add an ASD block and add the following code.
// Loads a consent form. Must be called on the main thread.
UserMessagingPlatform.loadConsentForm(
this,
new UserMessagingPlatform.OnConsentFormLoadSuccessListener() {
@Override
public void onConsentFormLoadSuccess(ConsentForm consentForm) {
MainActivity.this.consentForm = consentForm;
if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.REQUIRED) {
consentForm.show(
MainActivity.this,
new ConsentForm.OnConsentFormDismissedListener() {
@Override
public void onConsentFormDismissed(@Nullable FormError formError) {
if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) {
// User has given consent, load personalized ads
_loadPersonalizedAds();
} else {
// User has declined consent or consent not obtained, load non-personalized ads
_loadNonPersonalizedAds();
}
}
});
} else if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) {
// Consent is already obtained, load personalized ads
_loadPersonalizedAds();
} else {
// Consent is not required, load personalized ads by default
_loadPersonalizedAds();
}
}
},
new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
@Override
public void onConsentFormLoadFailure(FormError formError) {
// Handle Error.
SketchwareUtil.showMessage(getApplicationContext(), "bus1344y");
}
}
);
In this code I added reference to two moreblocks the first is
loadNonPersonalizedAds
And the second is
loadPersonalizedAds
So you have to create two moreblocks with the same name.
After creating moreblocks you have got the data whether you have to show non personalised ads or personalised ads. So you can add any code on basis of your need. For example you can add shared preferences to store user consent status or you can show ads on that activity. Or you can Give other codes.
For example I added the adview load in personalised and toast in non personalised .
Mistake points
You have to change activity name if your launcher activity is not mainactivity
You have to create three moreblocks and be sure while writing their names.
ADDING APP ID
Go androidmanifest editor in sketchware
Click on App Components
Add the following code there
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxxxx~xxxxx"/>
Remember to replace your app id here.
LOCAL LIBRARY
Download the library by clicking on this link
https://www.mediafire.com/file/rw49fo3icnjuqiq/user-messaging-platform_V_2.0.0.zip/file
After that add that library to sketchware local library and turn on it in by going to project libraries.
This is the all work which was to be done in sketchware. I hope you like the tutorial.
For admob settings Read this post
http://swrevo.blogspot.com/2023/09/gdpr-message-in-sketchware-part-2-admob.html