I am integrating an Android ad SDK that implements a number of listeners. Some of these listeners are not firing within my app. For example onAdLoaded will fire, but onAdDisplayed will not. This works perfectly fine in the sample app that's provided with the SDK, which leads to thinking it's an issue with integration. However, I can't find anything that's causing this snag. It's absolutely bizarre behaviour that I've never come across before. I know I'm grasping at straws over here, but hypothetically speaking what could be the causes for some listeners not registering while others are? How can I debug this?
Here's some code:
ad = new InterstitialAd(lastActivity, placementId);
ad.setAdListener(new InterstitialAdListener() {
//doesn't fire
#Override
public void onInterstitialDisplayed(Ad ad) {
Log.e(TAG, "INTERSTITIAL DISPLAYED");
Toast.makeText(lastActivity, "onInterstitialDisplayed", Toast.LENGTH_SHORT).show();
}
//doesn't fire
#Override
public void onInterstitialDismissed(Ad ad) {
Log.e(TAG, "INTERSTITIAL DISMISSED");
Toast.makeText(lastActivity, "onInterstitialDismissed", Toast.LENGTH_SHORT).show();
}
#Override
public void onError(Ad ad, AdError adError) {
Log.e(TAG, "ERROR! " + adError.getErrorMessage());
Toast.makeText(lastActivity, "onError", Toast.LENGTH_SHORT).show();
}
#Override
public void onAdLoaded(Ad ad) {
Log.e(TAG, "AD LOADED!");
AdAdapter.this.ad.show();
Toast.makeText(lastActivity, "onAdLoaded", Toast.LENGTH_SHORT).show();
}
//doesn't fire
#Override
public void onAdClicked(Ad ad) {
Log.e(TAG, "AD CLICKED!");
Toast.makeText(lastActivity, "onAdClicked", Toast.LENGTH_SHORT).show();
}
});
ad.loadAd();
I finally figured out why. I decompiled the SDK to have a closer look. The package name was hardcoded into some of the conditions that relate to the non-firing listeners. I refactor their package name within my build script, but the script ignores strings. So naturally they wouldn't fire because the package name has changed.
Related
I am making a quiz app. And I want that if the user kills the app their performance be uploaded on the firestore. When he clicks submit Button everything works fine but when I call submitbutton.callOnClick();
in onDestroy() some code is executed but the data is not uploaded.
this is my onDestroy() code
protected void onDestroy() {
Log.d(TAG, "onDestroy: ------");
if (clicked) { }
else
{
clicked = false;
submitButton.callOnClick();
}
Log.d(TAG, "onDestroy: done");
super.onDestroy();
And this is some code of submitButton 's onClickListener
Log.d(TAG, "onClick: ----------------------");
Result result=new Result(new String(ansString),new String(officialAnsString),correct,incorrect,not_attempted,marks);
FireBase_Variables.db.collection(tName+"_result").document(currentUser.getUid()).set(result);
Log.d(TAG, "onClick: ----------------------");
I can see the upper log in the logcat but not the lower one. Which means the line for uploading data is not executed.
What should I do?
You'll want to wait until the write operation is completed, before calling super.onDestroy().
If we unroll the code into a single block, that'd be something like:
protected void onDestroy() {
Log.d(TAG, "onDestroy: ------");
if (clicked) { }
else
{
clicked = false;
Log.d(TAG, "onClick: ----------------------");
Result result=new Result(new String(ansString),new String(officialAnsString),correct,incorrect,not_attempted,marks);
FireBase_Variables.db.collection(tName+"_result").document(currentUser.getUid()).set(result).addOnCompleteListener(new new OnCompleteListener<Void>() {
#Override
public void onComplete(Void aVoid) {
Log.d(TAG, "onDestroy: done");
super.onDestroy();
}
});
}
Also see: How to check a certain data already exists in firestore or not
Note: I didn't compile/run this code, so there may be syntactic problems with it. If you encounter such problems, please try to solve them for yourself and use the edit link under the answer to fix them for folks who come here after you.
In general you'll want to do the above somewhere else than in an onDestroy handler though, as that method is fairly unlikely to be called.
I picked someone android project up and I'm working on updating it and adding some new features for a future rerelease on the Play Store.
My issue right now is with dialogs. When the app was done three years ago, the guy who coded it used already deprecated methods. I've been able to fix them all except for one... here:
#Override
protected void onPrepareDialog(int id, Dialog dialog) {
super.onPrepareDialog(id, dialog); // call super
switch (id) {
case DATE_DIALOG_ID:
((DatePickerDialog) dialog).setOnDismissListener(new OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialog) {
dialog.dismiss();
}
});
break;
case TIME_DIALOG_ID:
((TimePickerDialog) dialog).setOnDismissListener(new OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialog) {
dialog.dismiss();
}
});
break;
}
}
problem is onPrepareDialog is deprecated and I want to fix it without having to change the whole class and its parents. Do you have any idea? I know that I need to use DialogFragment but I can't figure out how to do it efficiently without, like I said, doing the whole class again.
The class containing the code I posted extends a class that extends Activity. It also implements OnCheckedChangeListener.
Thanks
I am working on a android application in which I need to open a Facebook login window and then after logging successfully, I need to move to another intent (or new screen).
So as soon as user is logged in successfully, it should go to another screen in my app. I am having a very hard time making this thing to work. I have got the sample examples from the Facebook SDK so I was testing it out on those examples, I created another screen named Screen2.java(new xml file) having only a single button just to test it out.
So in my case what it should do is as soon as you are logged in successfully it should go to .Screen2 intent. So I made some changes in the Main.java class mentioned here in this tutorial but it is not working for me. Meaning as soon as I am logged in to Facebook, it doesn't goes to .Screen2 intent that I have created. Can anyone help me out here?
I made changes only in Main.java class as below by adding new Intent in the method onAuthSucceed()-
public class SampleAuthListener implements AuthListener {
#Override
public void onAuthSucceed() {
mText.setText("You have logged in! ");
// mRequestButton.setVisibility(View.VISIBLE);
// mUploadButton.setVisibility(View.VISIBLE);
// mPostButton.setVisibility(View.VISIBLE);
Intent i = new Intent(Main.this, Screen2.class);
startActivity(i);
}
#Override
public void onAuthFail(String error) {
mText.setText("Login Failed: " + error);
}
}
NOTE:- I am able to login into Facebook but after logging successfully, it doesn't goes to my new Intent.
Any help will be appreciated.
I was under the impression you needed something like this
private Session.StatusCallback callback = new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.d(TAG, "Logged in...");
//fire intent
} else if (state.isClosed()) {
Log.d(TAG, "Logged out...");
}
}
ImageView connect = (ImageView) findViewById(R.id.fconnect);
connect.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
facebook.authorize(SignIn.this, new String[] {"offline_access", "email", "read_friendlists","publish_stream" },new DialogListener() {
#Override
public void onComplete(Bundle values) {
String AccessToken = facebook.getAccessToken();
LoginDirect = "Loading Home....";
LoginProcessChkUserStatus();
}
#Override
public void onFacebookError(FacebookError error) {
}
#Override
public void onError(DialogError e) {
}
#Override
public void onCancel() {
}
});
}else{
progress = true;
LoginProcessChkUserStatus();
}
}
});
this the facebook api....that i use for loading in my application...this works fine...when i click login button...after authorizing it comes to oncomplete stage... now the problem comes when i installed separtely Facebook.apk in my phone taken from Facebook SDK....the view becomes this....also when i click login button it never excutes the above code....what shall i do...???
I have also faced some similar issue when I have integrated facebook with my application. when I am clicking the facebook icon in my application native facebook app was launched and when I uninstalled that native facebook app all were working correctly. I figured a way out to overcome this issue by the following method and I have posted it on below link on stackoverflow: "An error's occurred" when authenticating with Facebook's android sdk . Actually my problem was, when I used the debug key, the Key Hash value I entered was wrong in the facebook app register. When I corrected the key hash according to what I have posted in the above link my issue was solved. Please try this also.
The changing of screens is normal. If you have the Facebook app installed, the SDK uses this to log in. If not, it uses a WebView for authentication (as seen on your first screenshot).
And why does this not work? The Facebook app uses result codes from Androids activity mechanism.
I dont see onActivityResult() in your code. Make sure to have that implemented in your activity. It should look like this:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
After that, your code should work as intended. :)
I'm trying to implement the LVL (Licensing Verification Library for Android), but running into a problem when the license check fails. I pop up a Dialog which explains that the license check failed and presents them with two buttons. One button is "Retry" which I want to immediately do another check or "Purchase App" which redirects them to buy the app on the App Market.
When I tap the Retry button, I can see from logging messages that my licensing check is called, I receive another "dont allow" callback and I try to show the above failure dialog again (I see onPrepareDialog() get called again).
The problem is the second dialog doesn't actually show. So the user can use the app even though the license check failed. Why isn't the dialog popping up again and again?
I believe this is all of the relevant code:
private void checkLicense() {
Log.d(TAG, "Checking License...");
this.licenseChecker.checkAccess(this.licenseCheckerCallback);
}
private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
public void allow() { }
public void dontAllow() {
Log.d(TAG, "License resposne: Don't Allow");
if (isFinishing())
return; // Don't update UI if Activity is finishing.
// Should not allow access. In most cases, the app should assume
// the user has access unless it encounters this. If it does,
// the app should inform the user of their unlicensed ways
// and then either shut down the app or limit the user to a
// restricted set of features.
// In this example, we show a dialog that takes the user to Market.
Log.d(TAG, "Showing No License Dialog");
showDialog(DIALOG_NO_LICENSE_ID);
}
public void applicationError(ApplicationErrorCode errorCode) {
if (isFinishing())
return; // Don't update UI if Activity is finishing.
// This is a polite way of saying the developer made a mistake
// while setting up or calling the license checker library.
showDialog(DIALOG_APPLICATION_ERROR_ID);
}
}
protected Dialog onCreateDialog(int id) {
Log.d(TAG, "Creating Dialog "+id);
switch(id) {
case DIALOG_NO_LICENSE_ID:
return this.makeRetryPurchaseDialog(getString(R.string.no_license));
case DIALOG_APPLICATION_ERROR_ID:
return this.makeRetryPurchaseDialog(this.applicationErrorMessageForDialog);
}
return null;
}
private Dialog makeRetryPurchaseDialog(String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(CalculatorTabActivity.this);
builder.setMessage(message).setCancelable(false)
.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
CalculatorTabActivity.this.checkLicense();
}
}).setNegativeButton("Purchase App", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
CalculatorTabActivity.this.openAppMarket();
}
});
return builder.create();
}
Just as an idea, try to explicitly call for dialog dismissing:
...
.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dissmissDialog(DIALOG_NO_LICENSE_ID);
CalculatorTabActivity.this.checkLicense();
}
})
Also, if that will not work, try using removeDialog(DIALOG_NO_LICENSE_ID) instead of dissmissDialog(DIALOG_NO_LICENSE_ID).
Finally what code (if at all) do you have in onPrepareDialog() ?