maybe you know is necesary add this agreement form in android
https://developers.google.com/mobile-ads-sdk/docs/dfp/android/eu-consent
i add this code just above the method onCreate on the main_activity.java
ConsentInformation consentInformation = ConsentInformation.getInstance(this);
String[] publisherIds = {"pub-123"};
ConsentInformation.getInstance(this)
.setConsentStatus(ConsentStatus.PERSONALIZED);
ConsentInformation.getInstance(this).
setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_EEA);
handler = new Handler();
consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
#Override
public void onConsentInfoUpdated(ConsentStatus consentStatus) {
// User's consent status successfully updated.
}
#Override
public void onFailedToUpdateConsentInfo(String errorDescription) {
// User's consent status failed to update.
}
});
URL privacyUrl = null;
try {
// TODO: Replace with your app's privacy policy URL.
privacyUrl = new URL("https://www.123.com/privacy");
} catch (MalformedURLException e) {
e.printStackTrace();
// Handle error.
}
ConsentForm form = new ConsentForm.Builder(this, privacyUrl)
.withListener(new ConsentFormListener() {
#Override
public void onConsentFormLoaded() {
// Consent form loaded successfully.
}
#Override
public void onConsentFormOpened() {
// Consent form was displayed.
}
#Override
public void onConsentFormClosed(
ConsentStatus consentStatus, Boolean userPrefersAdFree) {
// Consent form was closed.
}
#Override
public void onConsentFormError(String errorDescription) {
// Consent form error.
}
})
.withPersonalizedAdsOption()
.withNonPersonalizedAdsOption()
.withAdFreeOption()
.build();
form.load();
form.show();
but the form dont load when i open the app for testing. Where can be the problem. i assume, the line with: DEBUG_GEOGRAPHY_EEA << define the location of the mobile, but i dont see nothing
thanks for your time !
Related
Am trying to implement Braintree Vault PayPal payment, the problem am facing here is getting the paymentMethodNonce my event listener createdListener to capture nonce doesn't get called using vault, but everything works fine using checkout. I can't charge customer without a paymentMethodNonce, please can anyone assist me.
mBraintreeFragment = BraintreeFragment.newInstance(this,"TOKEN_FROM_SERVER");
PayPalRequest request = new PayPalRequest().localeCode("US").billingAgreementDescription("Your agreement description");
PayPal.requestBillingAgreement(mBraintreeFragment, request);
mBraintreeFragment.addListener(createdListener);
mBraintreeFragment.addListener(cancelListener);
mBraintreeFragment.addListener(errorListener);
DataCollector.collectDeviceData(mBraintreeFragment, new BraintreeResponseListener<String>() {
#Override
public void onResponse(String deviceData) {
Log.e("PayPal", deviceData);
try {
JSONObject json = new JSONObject(deviceData);
deviceDataInfo = json.getString("correlation_id");
Log.e("PayPal", deviceDataInfo);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
My Listeners
PaymentMethodNonceCreatedListener createdListener = new PaymentMethodNonceCreatedListener() {
#Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
String nonce = paymentMethodNonce.getNonce();
Log.d("PayPal", "nonce id " + nonce);
}
};
BraintreeCancelListener cancelListener = new BraintreeCancelListener() {
#Override
public void onCancel(int requestCode) {
Log.d("CreditCard", "Braintree Error Code " + requestCode);
}
};
BraintreeErrorListener errorListener = new BraintreeErrorListener() {
#Override
public void onError(Exception error) {
if (error instanceof ErrorWithResponse) {
ErrorWithResponse errorWithResponse = (ErrorWithResponse) error;
BraintreeError cardErrors = errorWithResponse.errorFor("creditCard");
if (cardErrors != null) {
List<BraintreeError> errors = cardErrors.getFieldErrors();
String err = Objects.requireNonNull(errors.get(0).getMessage());
Log.d("CreditCard", errors.toString());
}
}
}
};
Instead of adding manually your listeners to that request, it's better to just implement the interface from braintree.
For example, if you want to use the onPaymentMethodNonceCreated() just add "implements PaymentMethodNonceCreatedListener" after your class name.
public class "YourClass" implements PaymentMethodNonceCreatedListener {
//...
}
And then override the method that now the Android Studio is warning you:
#Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
String nonce = paymentMethodNonce.getNonce();
//...
}
This way you can go for everyone of your listeners! Good luck!
Inside the onConsentFormLoaded method it says for “variable ‘form’ is accessed from within inner class must be declared final” but then when I declare it final it then shows a error “variable ‘form’ might not have been initialized” I tried declaring 'private static ConsentForm form" at the top of my class but then it gives a error saying about placing android context classes inside a static field will result in a memory leak so im not sure where to go from here ?
public static void settings()
{
final AppActivity activity = ((AppActivity) Cocos2dxHelper.getActivity());
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
URL privacyUrl = null;
try {
// TODO: Replace with your app’s privacy policy URL.
privacyUrl = new URL(“https://privacy-policy”);
} catch (MalformedURLException e) {
e.printStackTrace();
}
ConsentForm form = new ConsentForm.Builder(getContext(), privacyUrl).withListener(new ConsentFormListener() {
#Override
public void onConsentFormLoaded() {
// Consent form loaded successfully.
Log.i(“consent”, “consent loaded”);
form.show();
}
#Override
public void onConsentFormOpened() {
// Consent form was displayed.
}
#Override
public void onConsentFormClosed(ConsentStatus consentStatus, Boolean userPrefersAdFree) {
}
#Override
public void onConsentFormError(String errorDescription) {
// Consent form error.
Log.i(“consent”, errorDescription);
}
})
.withPersonalizedAdsOption().withNonPersonalizedAdsOption().build();
form.load();
}
});
}
I have added the latest ACRA:
compile 'ch.acra:acra:4.8.5'
Configured my App class according to docs:
#ReportsCrashes(
reportSenderFactoryClasses = {com.github.dht.screenger.crash.ParseSenderfactory.class}
)
...
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// The following line triggers the initialization of ACRA
ACRA.init(this);
}
Defined the Sender factory:
public class ParseSenderfactory implements ReportSenderFactory {
// NB requires a no arg constructor.
public ReportSender create(Context context, ACRAConfiguration config){
return new ParseSender();
}
}
The sender:
public class ParseSender implements ReportSender {
#Override
public void send(Context context, CrashReportData report) throws ReportSenderException {
// Get the ParseObject to be send to Parse
CrashReportParseObject crashReport = getParseObject(report);
// Associate the current logged user with the crash report
ParseUser currentUser = ParseUser.getCurrentUser();
crashReport.setUser(currentUser);
// Send crash report to Parse
crashReport.saveInBackground();
}
/**
* Get a custom ParseObject for data collected by ACRA.
* #param report
* Report data collected by ACRA.
* #return
* A custom ParseObject containing relevant data.
*/
private CrashReportParseObject getParseObject(Map<ReportField, String> report) {
ReportField[] fields = ACRA.getConfig().customReportContent();
if (fields.length == 0) {
fields = ACRAConstants.DEFAULT_REPORT_FIELDS;
}
CrashReportParseObject finalReport = new CrashReportParseObject();
for (ReportField field : fields) {
finalReport.put(field.toString(), report.get(field));
}
return finalReport;
}
}
And the ParseObject:
#ParseClassName("CrashReport")
public class CrashReportParseObject extends ParseObject {
public String getAndroidVersion(){
return this.getString("ANDROID_VERSION");
}
public String getAppVersionName(){
return this.getString("APP_VERSION_NAME");
}
public String getPhoneModel(){
return this.getString("PHONE_MODEL");
}
public String getProduct(){
return this.getString("PRODUCT");
}
public void setUser(ParseUser user){
this.put("user", user);
}
}
And yet ACRA does not catch an exception I send from the activity:
#Override
public void onStart() {
super.onStart();
throw new RuntimeException("This is a crash");
}
Did I forget something?
UPDATE
Made some progress. Saw the CrashReportParseObject was not being created as Parse wanted the syntax to be ParseObject.create("CrashReport");
Changed the ParseSender to :
public class ParseSender implements ReportSender {
#Override
public void send(Context context, CrashReportData report) throws ReportSenderException {
Log.d("ACRA", "Sending log");
// Get the ParseObject to be send to Parse
ParseObject crashReport = getParseObject(report);
// Associate the current logged user with the crash report
ParseUser currentUser = ParseUser.getCurrentUser();
crashReport.put("user", currentUser);
Log.d("ACRA", crashReport.toString());
// Send crash report to Parse
crashReport.saveInBackground();
}
/**
* Get a custom ParseObject for data collected by ACRA.
*
* #param report Report data collected by ACRA.
* #return A custom ParseObject containing relevant data.
*/
private ParseObject getParseObject(Map<ReportField, String> report) {
ReportField[] fields = ACRA.getConfig().customReportContent();
if (fields.length == 0) {
fields = ACRAConstants.DEFAULT_REPORT_FIELDS;
}
ParseObject finalReport = new ParseObject("CrashReport");
for (ReportField field : fields) {
if (field.toString() != null && report.get(field) != null) {
finalReport.put(field.toString(), report.get(field));
}
}
return finalReport;
}
}
and removed CrashReportParseObject all together. Now I am getting "ACRA caught a RuntimeException for com.github.dht.screenger" but still no object is being created on parse.com. Is it a timing thing? does the app crash before it gets the time save the object?
I am trying to use the Android SDK to "invite friends', however my code is giving the following error...
"failed to find provider info for
com.facebook.katana.provider.attributionid"
Could you please review my code below and help me understand what I am doing wrong.
String appLinkUrl, previewImageUrl;
appLinkUrl = "your app link url";
previewImageUrl = "https://www.example.com/my_invite_image.jpg";
if (AppInviteDialog.canShow())
{
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(appLinkUrl)
.setPreviewImageUrl(previewImageUrl)
.build();
AppInviteDialog appInviteDialog = new AppInviteDialog(MainActivity.this);
appInviteDialog.registerCallback(callbackManager, new FacebookCallback<AppInviteDialog.Result>()
{
#Override
public void onSuccess(AppInviteDialog.Result result)
{
}
#Override
public void onCancel()
{
}
#Override
public void onError(FacebookException e)
{
}
});
appInviteDialog.show(content);
}
I am new to android and java and am trying to setup a login page that posts to a webpage that verifies the credentials and returns a cookie.
I am using the login template included with eclipse. I am not sure what to put for the
// TODO: attempt authentication against a network service.
All I need it so post to my page like this: www.mywebsite.com/login?userid=john&password=test
and if the credentials are correct I get a json success string and cookie back. How can I incorporate this into this template or what do i need to put in place of the authentication against a network service
public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
#Override
protected Boolean doInBackground(Void... params) {
// TODO: attempt authentication against a network service.
try {
// Simulate network access.
Thread.sleep(2000);
} catch (InterruptedException e) {
return false;
}
for (String credential : DUMMY_CREDENTIALS) {
String[] pieces = credential.split(":");
if (pieces[0].equals(mEmail)) {
// Account exists, return true if the password matches.
return pieces[1].equals(mPassword);
}
}
// TODO: register the new account here.
return true;
}
#Override
protected void onPostExecute(final Boolean success) {
mAuthTask = null;
showProgress(false);
if (success) {
finish();
} else {
mPasswordView
.setError(getString(R.string.error_incorrect_password));
mPasswordView.requestFocus();
}
}
#Override
protected void onCancelled() {
mAuthTask = null;
showProgress(false);
}
}
}
edit: I tried searching for an example of this but did not find one that fit my case. Any links to a solution or example of what im trying to do are appreciated.