How do I trigger the Apptentive rating prompt reminder? - android

I just updated apptentive in my app to 1.5.0v. The rating prompt dialog is shown successfully when the conditions are true, but if the user clicks on "Remind me later", the rating prompt never is shown again.
I show the dialog, with the next code:
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus
&& this instanceof SongActivity
&& InternalCache.getCounterApptentiveDialog() >= DOWNLOADS_TO_SHOW_APPTENTIVE) {
boolean ret = Apptentive.engage(this, "init");
if (ret) {
System.out.println("GA-APPtentive");
GAHelper.getInstance().apptentiveRateDialog(getClassName(),
getItemId());
}
}
}
Do I need something more in order to show the rating prompt dialog again?

You are reminded to rate the app again according to the value in your Apptentive Rating Prompt interaction's settings:
If it's set to 10 days, you will need to wait 10 days after pressing "Remind Me Later" to be re-prompted. You can simulate this by moving your device clock forward.
The "reminder" interaction will only be triggered if you engage its event. This event is the same as the main event used to trigger the Rating Prompt.
iOS:
[[ATConnect sharedConnection] engage:#"testRatingFlow" fromViewController:self];
Android:
Apptentive.engage(this, "testRatingFlow").

Related

App looses focus after a dialogAlert is shown

I am working on a dialog, and once I call it, there is no focus on it.
I am working on a xamarin app.
Android.App.AlertDialog.Builder alertDialog = new Android.App.AlertDialog.Builder(this);
alertDialog.SetTitle("Special Notification Access");
alertDialog.SetMessage(
"You have no special app access permission for the Notifications!\n" +
"Please go to Settings -> Apps -> Special app access -> Notification access " +
"and give permission to this app."
);
alertDialog.SetPositiveButton("OK", (senderAlert, args) => {
Android.Util.Log.Debug(TAG, "Pressed OK");
});
alertDialog.SetNegativeButton("No", (senderAlert, args) => {
Android.Util.Log.Debug(TAG, "Pressed No");
});
Dialog diag = alertDialog.Create();
diag.Show();
Once I press a button on my remote (I am working on an Android TV, SDK 28) the dialog seems to get focus, but the log shows that the app has lost focus, see here:
09-10 13:37:24.974 12053 12053 W ViewRootImpl[MainActivity]: Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_DPAD_CENTER, scanCode=353, metaState=0, flags=0x8, repeatCount=0, eventTime=13590499, downTime=13590499, deviceId=6, source=0x301 }
After that, the remote stops working, nothing is done by pressing the buttons. Also, once I open the settings (via ADB comand) and go back to the app, the dialog is in focus, and everything works fine.
I found various solutions on the net, including this:
How to set focus to android alert dialog negative button?
Which uses the following code:
diag.getButton(AlertDialog.BUTTON_NEGATIVE).requestFocus();
This method does not exit anymore.
Also, I found this:
alertDialog.setOnShowListener(new DialogInterface.OnShowListener(){
#Override
public void onShow(DialogInterface dialog) {
Button positive= alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
positive.setFocusable(true);
positive.setFocusableInTouchMode(true);
positive.requestFocus();
}
});
But again, the setOnShowListener does not exist anymore.
What should I do?
Please let me know, if you need any more info.
Thank you for your time.
Edit1: Added picture

Android: Load the activity after accessing the notification bar

if there is no internet means I'm not able to load web resources. For this reason I'm giving the toast like "Check internet connectivity". After this toast, user may enable the internet option at notification bar and comes back. When he comes back, i want to reload the activity. For this requirement, i tried
onWindowFocusChanged and onActivityReenter
override methods but these are not working properly
MyCode
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus){
Intent intent = new Intent(CommonActivity.this, OtherActivity.class);
startActivity(intent);
}
}
When I'm using above code, my activity reloading again and again
There is a solution which i know is not perfect but it will work.
Define a activity level veriable like this
Boolean isAlreadyFocused = false;
Then in your onFocusChanged method do like this.
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus && !isAlreadyFocused ){
isAlreadyFocused = true;
Intent intent = new Intent(CommonActivity.this,OtherActivity.class);
startActivity(intent);
}else{
isAlreadyFocused = false;
}
}
Check this and tell me if this does not work.
By fallowing another way (i got this idea when i saw the flipkart app) i solved this internet checking
I'm checking for the internet connection, if there is no internet means i'm redirecting to NoInternetActivity that's design looks like
When user clicks on Retry button means i'm again checking for internet. If internet was accessible means i'm allowing user to home page of my app otherwise i'm redirecting to the NoInternetActivity again

Waiting for Play Games to connect before displaying leaderboard

I'm not keen on the standard behavior of the Play Games Service to automatically attempt a connection when the app is first launched, so I have disabled this. In my main menu I have a 'display scores' button. What I want to happen when the user presses this button is this:
If the user is connected (logged in), go ahead and display the leaderboard
If the user is not connected, then display the connection dialog. Once connected, display the leaderboard
On the main menu, I will have an extra button "Log out" which will display only if the user is connected / logged in.
When the user clicks the button, I am carrying out the following:
Code
if (buttonPressed()){
//Display connection dialogue and initiate log in
getGameHelper().beginUserInitiatedSignIn();
//Check if the user is signed in before continuing
if (getGameHelper.isSignedIn()){
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), myLeaderBoardID), 1);
}
}
If the user isn't connected: The user is presented with a connection dialogue - this works fine. They can then log in. Once they have done this, nothing else happens (the code has moved on and therefore does not display the leaderboard because the user isn't logged in - if I don't have the check to see if the user is signed in here the app would just crash). If the user then presses the button again, it will display the leaderboard.
How can I do all this with just one button press?
What I want is, if the user isn't logged in, to display the log-in dialogue, then as soon as the user has logged in, display the leaderboard. I need to make startActivityForResult wait until the user has completed sign in.
In short
I need to make my code wait until it's connected to Play before attempting to display the Leaderboard.
Any help would be appreciated
You can be notified of successful/failed sign-in as follows:
getGameHelper().setup(
new GameHelper.GameHelperListener() {
#Override
public void onSignInSucceeded() {
// execute code on successful sign-in
// for example, here you could show your leaderboard
}
#Override
public void onSignInFailed() {
// execute code on failed sign-in
}
};
);
You should of course do this before you attempt to sign-in. You can then show your leaderboard when sign-in succeeds. This code should be placed where you create your game helper (i.e. before the buttonPressed() code is executed).
Once this code is in place, you should change your buttonPressed() code to look as follows:
if ( buttonPressed() ) {
// check if user already signed-in and show leaderboard; otherwise do sign-in
if ( getGameHelper.isSignedIn() ) {
startActivityForResult( Games.Leaderboards.getLeaderboardIntent( getApiClient(), myLeaderBoardID ), 1 );
}
else {
getGameHelper().beginUserInitiatedSignIn();
// NOTE: do nothing further here; show the leaderboard in
// the listener's onSignInSucceeded()
}
}
One final note: the listener you create will be called for all sign-in operations, so if you need to have this functionality in multiple places (for example, if you want to do the same with achievements) then you will need to use some signal as to what needs to happen on successful sign-in and take the correct action in onSignInSucceeded().
Signalling an action for sign-in success:
Add this code to you class (global scope)
public final static int NO_ACTION = 0;
public final static int SHOW_LEADERBOARD = 1;
public final static int SHOW_ACHIEVEMENTS = 2;
public int signInAction = NO_ACTION;
Next set the action just before signing-in (based on where the sign-in occurs):
if ( buttonPressed() ) {
// check if user already signed-in and show leaderboard; otherwise do sign-in
if ( getGameHelper.isSignedIn() ) {
startActivityForResult( Games.Leaderboards.getLeaderboardIntent( getApiClient(), myLeaderBoardID ), 1 );
}
else {
// NEW: request leaderboard to be shown upon sign in
signInAction = SHOW_LEADERBOARD;
// NEW----------------------------------------------
getGameHelper().beginUserInitiatedSignIn();
// NOTE: do nothing further here; show the leaderboard in
// the listener's onSignInSucceeded()
}
}
And finally change the listener to respond the set sign-in action:
getGameHelper().setup(
new GameHelper.GameHelperListener() {
#Override
public void onSignInSucceeded() {
if ( signInAction == SHOW_LEADERBOARD ) {
// show your leaderboard here
}
else if ( signInAction == SHOW_ACHIEVEMENTS ) {
// show achievements here
}
// important! reset the sign-in action so that any subsequent sign-in
// attempts do not re-use the currently set action!
signInAction = NO_ACTION;
}
#Override
public void onSignInFailed() {
// execute code on failed sign-in
// important! it should also be cleared in case of an error
signInAction = NO_ACTION;
}
};
);
Of course, this is just one way to achieve this, but it should work just fine for most purposes. Just be sure to set the signInAction to the appropriate value before you perform the sign-in - and be sure to clear it when sign-in is complete.

Disabling Buttons after launching an application in Android

I currently developing a Content Management app in Kiosk Mode. I pattern this in Surelock Kiosk Lockdown. There's an admin password in order to allow application to run inside the app. The buttons like Home, Back and Recent Task App are disabled in this app. However when I launch a certain app, Back button and Recent Task App are enabled again.
What I'd like to happen is that when the user launch an app, the Recent Task app button and Back button are disabled just like in Content Management App. I am stuck in searching and finding ways on how to do this. Please help me on how to do this. Thank you.
BTW, I'm using this code to disable Buttons:
// Disable Recent Task App
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Log.d("Focus debug", "Focus changed!");
if (!hasFocus) {
Log.d("Focus debug", "Lost focus!");
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
closeDialog.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
sendBroadcast(closeDialog);
}
}
// Disable Volume Buttons and Back Button
private final List hijackKeys = new ArrayList(Arrays.asList(
KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_UP,
KeyEvent.KEYCODE_BACK));
#Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (hijackKeys.contains(event.getKeyCode())) {
return true;
} else {
return super.dispatchKeyEvent(event);
}
}

Freeze activity/method execution until get a response from an dialog

I am trying to implement an administration mode when the user tap 7 times on back button.
Then, A dialog message will be called with editText asking for a password. if the password matches with the one in the database, I set passwordMacthes as TRUE and return it to whatever calls the dialog setTapCount and to start administration mode activity.
However, return passordMatches always return FALSE because it finishes the execution before the dialogMessage verifies the password and be dismissed or canceled by the user.
here is my setTapCount method :
public static boolean setTapCount(Context context){
tapCount = tapCount + 1;
if(tapCount == 7){
tapCount = 0;
dialogMessage(context);
return passwordMatches;
}else{
return false;
}
}
Does anyone know how to call the line below of dialogMessage(context) only once it is finished ?
thanks
Move that line to the handler for the accept button in the dialog, and rewrite your app to be event-driven (e.g., have setTapCount() accept a result listener object that can be notified of what the user did, rather than return a boolean).

Categories

Resources