我在我的应用程序中使用通过用户消息传递平台获得同意:https ://developers.google.com/admob/ump/android/quick-start
活动开始时,同意书不会显示在屏幕上。
日志显示onResume之后触发了方法,但是eran上没有出现form。我的代码有什么问题?
在运行中,我发现了以下几行:
UserMessagingPlatform:无法构建可用的表单。
D / UserMessagingPlatform:存储的信息不存在:IDFA_freqCapNumViews 存储的信息不存在:IABTCF_TCString 存储的信息不存在:IABTCF_AddtlConsent I / System.out: (HTTPLog) -Static: isSBSettingEnabled false (HTTPLog) -Static: isSBSettingEnabled false
D / UserMessagingPlatform: Action [clear]: {"keys": ["IABTCF_CmpSdkID", "IABTCF_CmpSdkVersion", "IABTCF_PolicyVersion", "IABTCF_gdprApplies", "IABTCF_PublisherCC", "IABTCFreat_Streats" , "IABTCF_VendorLegitimateInterests", "IABTCF_PurposeConsentimateLePurest", , "IABTCF_SpecialFeaturesOptIns", "IABTCF_PublisherConsent", "IABTCF_PublisherLegitimateInterests", "IABTCF_PublisherCustomPurposesConsents", "IABTCF_PublisherCustomPurposesLegitimateInterests", "IABTCF_AddtlConsent", "IABTCF_UserConsentRecordId", "IABTCF_idfaFlowControl"]} D / UserMessagingPlatform: Action [write]: {"IABTCF_idfaFlowControl": 2}
我的代码有什么问题?
public abstract class BaseActivity extends AppCompatActivity {
private final String TAG = "ART_APP";
private SharedPreferences sp;
private ConsentInformation consentInformation;
private ConsentForm consentForm;
final String LOG_TAG = "myLogs";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.sp = getSharedPreferences(Sp.SP_KEY, Context.MODE_PRIVATE);
ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(this)
.setDebugGeography(ConsentDebugSettings
.DebugGeography
.DEBUG_GEOGRAPHY_EEA)
.addTestDeviceHashedId("C258BF9BE13D842B973A20309A39C080")
.build();
ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
.setConsentDebugSettings(debugSettings)
.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()) {
loadForm();
}
}
},
new ConsentInformation.OnConsentInfoUpdateFailureListener() {
@Override
public void onConsentInfoUpdateFailure(FormError formError) {
// Handle the error.
}
});
}
public SharedPreferences getSp() {
return sp;
}
public void loadForm(){
Log.d(LOG_TAG, "showconsent");
UserMessagingPlatform.loadConsentForm(
this,
new UserMessagingPlatform.OnConsentFormLoadSuccessListener() {
@Override
public void onConsentFormLoadSuccess(ConsentForm consentForm) {
BaseActivity.this.consentForm = consentForm;
if(consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.UNKNOWN) {
consentForm.show(
BaseActivity.this,
new ConsentForm.OnConsentFormDismissedListener() {
@Override
public void onConsentFormDismissed(@Nullable FormError formError) {
// Handle dismissal by reloading form.
loadForm();
}
});
}
}
},
new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
@Override
public void onConsentFormLoadFailure(FormError formError) {
/// Handle Error.
}
}
);
}
/**
* Достать строку из переменных
*
* @param stringId
* @return
*/
public String getSpString(String stringId) {
return getResources().getString(sp.getInt(stringId, 0));
}
/**
* @param stringId
* @return
*/
public String getSpStringSt(String stringId) {
return sp.getString(stringId, "");
}
public void log(String msg) {
Log.d(TAG, msg);
}
/**
* Открываем ссылку в баузере
*
* @param url
*/
public void showLink(String url) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
/**
* Есть ли подписка ?
*
* @return
*/
}
public class CategoryActivity extends BaseActivity implements RVAdapter.ItemClickListener,
View.OnClickListener, BarMenu.OnItemClick {
private static final String TAG = CategoryActivity.class.getSimpleName();
private RecyclerView rv;
private List<Item> items;
private List<Modal> modals;
private BarMenu barMenu;
private HashMap<Integer, MoreApp> moreApps;
private AdView adView;
private FrameLayout adContainerView;
private ConsentInformation consentInformation;
private ConsentForm consentForm;
final String LOG_TAG = "myLogs";
private SliderView sliderView;
private SliderPromoAdapter adapter;
private ArrayList<SliderItem> sliderViewArrayList = new ArrayList<>();
private View banner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_category);
Log.d(LOG_TAG, "CategoryCreate");
initRateMe();
showRateMe();
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) { }
});
//StartAppSDK.init(this, "202286925", true);
//------------
this.barMenu = new BarMenu(this, R.menu.top_bar_menu);
barMenu.setOnItemClick(this);
//------------
adapter = new SliderPromoAdapter(this);
SliderItem sliderItem = new SliderItem();
sliderItem.setSource(R.drawable.banner_premium);
sliderItem.setType(GlobalData.TYPE_PREMIUM);
sliderViewArrayList.add(sliderItem);
sliderView = findViewById(R.id.slider_view);
sliderView.setIndicatorAnimation(IndicatorAnimations.WORM); //set indicator animation by using SliderLayout.IndicatorAnimations. :WORM or THIN_WORM or COLOR or DROP or FILL or NONE or SCALE or SCALE_DOWN or SLIDE and SWAP!!
sliderView.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
sliderView.setAutoCycleDirection(SliderView.AUTO_CYCLE_DIRECTION_BACK_AND_FORTH);
sliderView.setIndicatorSelectedColor(Color.WHITE);
sliderView.setIndicatorUnselectedColor(Color.GRAY);
sliderView.setScrollTimeInSec(4); //set scroll delay in seconds :
sliderView.startAutoCycle();
sliderView.setSliderAdapter(adapter);
adapter.renewItems(sliderViewArrayList);
///get the reference to your FrameLayout
adContainerView = findViewById(R.id.adView_container);
//Create an AdView and put it into your FrameLayout
adView = new AdView(this);
adContainerView.addView(adView);
String adUnitId = getResources().getString(getSp().getInt(Sp.SP_ADS_BANNER_ID, 0));
adView.setAdUnitId(adUnitId);
//start requesting banner ads
loadBanner();
//------------
((TextView) findViewById(R.id.top_bar_title)).setText(
getSp().getInt(Sp.SP_APP_NAME, 0)
);
this.items = new ArrayList<>();
this.moreApps = new HashMap<>();
/*
if (!getSp().getBoolean(Sp.SP_MORE_APP_UP, false)) {
readJson();
}*/
//TODO Есть ли вообще другие приложения ?)
try {
if (!getSpStringSt(Sp.SP_MORE_APPS).equals("")) {
Gson gson = new Gson();
Type type = new TypeToken<List<MoreApp>>() {
}.getType();
List<MoreApp> ma = gson.fromJson(getSpStringSt(Sp.SP_MORE_APPS), type);
for (MoreApp m : ma) {
moreApps.put(m.getPosition(), m);
}
}
} catch (Exception e) {
e.printStackTrace();
}
// Баннер
this.banner = findViewById(R.id.custom_banner);
banner.setOnClickListener(this);
if (getSp().getBoolean(Sp.SP_IS_FREE5DAY, false)) {
banner.setVisibility(View.VISIBLE);
}
//if (getSp().getBoolean(Sp.SP_MORE_APP_UP, false)) {
readJson();
//}
this.rv = findViewById(R.id.category_recycler);
LinearLayoutManager llm = new GridLayoutManager(getApplicationContext(), 2);
rv.setLayoutManager(llm);
rv.setHasFixedSize(true);
RVAdapter adapter = new RVAdapter(items, this, true);
rv.setAdapter(adapter);
adapter.setmClickListener(this);
findViewById(R.id.top_bar_check).setVisibility(View.GONE);
findViewById(R.id.top_bar_menu).setOnClickListener(this);
findViewById(R.id.top_bar_back).setOnClickListener(this);
}
@Override
protected void onResume() {
super.onResume();
Log.d(LOG_TAG, "onResume");
loadForm();
if (getSp().getBoolean(Sp.SP_IS_FAQ, true)) {
// startActivity(new Intent(this, FaqActivity.class));
getSp().edit().putBoolean(Sp.SP_IS_FAQ, false).commit();
}
if (getSp().getBoolean(Sp.SP_IS_FREE5DAY, false)) {
}
hideSystemUI();
}
}