I am using timer(triggers every 2 hours) to check for any update in my app. If there is any update available, it will automatically download the latest .apk and pro grammatically starts the installation activity. (window with OK and CANCEL button)
Now the problem is :
If the user doesn't click "OK" or "CANCEL". Then the popup still exists. So, in the next timer hit (after 2 hours). It is downloading latest .apk, popups another installation activity.so now 2 activity window is displayed. Then for the next timer hit, it will 3 popup activity window (if the user still doesn't chooses OK or CANCEL)
Is there any better way to avoid displaying multiple window.
Please find my code below :
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if (requestCode == 3)
{
isUpdating = false;
}
}
private void fnCheckforUpdate()
{
........
.......
if(false==isUpdating)
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(outputFile), "application/vnd.android.package-archive");
isUpdating = true;
startActivityForResult(intent, 3);
}
}
You can check showing dialog:
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
Related
Google Immediate app update, as far as I understand, shouldn't be cancelable, but the dialog as an X icon that cancels the update process.
Is there a way to remove the cancel option?
I'm using the latest play core version, 1.10.2
Thanks
At the beginning, I had the same understanding, but looking up in documentation, I wasn't able to find this information.
Both InApp update types are cancelable, and the only way to prevent the user to update before uses your app will be finish the app if onActivityResult() returns something diffrent than OK
The difference between Flexible and Immediate update is:
In Flexible update, if the user decide to update, it can uses the app during the download and when the download is finished, you need show some U.I to call the completeUpdate().
In Immediate update, if the user decide to update, it can't use uses the app, because a fullscreen progress dialog will be show. After the download is completed, the Android will install the new version even if your app is in background.
InAppUpdate Doc
You can handle the cancel button and back button click listener.
If the user clicks cancel or back button then
onActivityResult
callback is executed and you can reopen the app update screen if
resultcode == RESULT_CANCELED
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == APP_UPDATE_REQ_CODE) {
if (resultCode == RESULT_CANCELED) {
// App update is canceled by the user so re-open the in-app update screen.
// This block of code is executed if user clicks cancel button from the in-app update screen or press the hardware back button.
checkForAppUpdate();
} else if (resultCode == RESULT_OK) {
// App successfully updated to the latest version.
finish();
} else {
// Update fails then re-open the in-app update screen.
checkForAppUpdate();
}
}
}
private void checkForAppUpdate(){
if (this instanceof SplashActivity){
return;
}
if (appUpdateManager == null){
appUpdateManager = AppUpdateManagerFactory.create(this);
}
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
startUpdateFlow(appUpdateInfo);
}
});
Official android document:
I have a dialog pop up in the middle of the program and the user has to
specify between two options then click confirm
problem arises when the user selects nothing then click the confirm button
so i need a way to notice that user hasnt selected anything
and add that check inside confrim button's click listener
im thinking of
....
.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
if (intent == null)
{ //do nothing or tell the user to select on something }
else
{ getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, i);}}
of course intent == null doesnt work, so what code should I use?
Intent with action name without extras will not be null. if you want to check extras is there with intent then try the following code
if (intent.getExtras() == null) {
// do something if there is not extras.
} else {
}
In my Android app I am giving the possibility to tap on a Google +1 button.
This works fine with the following code from the developpers source material (https://developers.google.com/+/mobile/android/recommend):
mPlusClient = new PlusClient.Builder(this, this, this)
.clearScopes()
.build();
mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);
Now I would like to detect when the user taps on this button, so I tried this:
mPlusOneButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(this, "Thanks for your +1", Toast.LENGTH_LONG).show();
}
});
But it doesn't do anything, it doesn't display the toast message.
As an alternative, I was thinking of having the player tap twice on the button : first being a regular Button object that would make the plus one button visible, second being the plusone button. but it is an awckward user experience
How can I detect user's tap on this button?
Don't use setOnPlusOneClickListener (or any listener) with SDK 13 (and perhaps future versions), it induces a bug (infinite rotation of the progress indicator in the +1 button when you click on it).
Use ActivityForResult to trigger the user choice.
mPlusOneButton.setOnPlusOneClickListener(new PlusOneButton.OnPlusOneClickListener() {
#Override
public void onPlusOneClick(Intent intent) {
startActivityForResult(intent, 0);
}
});
Check the result code
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == -1) {
// OK or SHARE
} else {
//UNDO
}
}
Plus one button provides a listener function to detect button click. Here is the code.
mPlusOneButton.setOnPlusOneClickListener(new PlusOneButton.OnPlusOneClickListener() {
#Override
public void onPlusOneClick(Intent intent) {
Log.w(tag,"plus one click");
}
});
First post, so please go easy.
I have an app with a handful of tabs, the first is opened on running the app.
One of the tabs is 'My Account' (a ListActivity) showing account options. I switch to this and if the user is not logged in, it, in turn, runs a UserLogon activity using the following:
Intent logonActivity = new Intent(getBaseContext(), UserLogon.class);
startActivityForResult(logonActivity, 0);
To catch the result, I use the following code:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 0){
MainBlock ta = (MainBlock) this.getParent();
TabHost th = ta.getMyTabHost();
th.setCurrentTab(0);
finish();
}
if (requestCode == 100)
{
showAccountOptions();
}
}
In the UserLogon class, I have the usual fare; TextView's and Button's. The intention is that if the user cancels the login, it will revert to the initial tab, or if login is successful, it will show the Account Options. And this is indeed what does happen.
All good so far.
The problem I'm having is that if I cancel the login and return to the first tab, when I select the Accounts tab again, I'm not presented with the UserLogon activity. I was under the impression that finish() would close the UserLogon activity, and the Accounts activity but it would appear not.
So, my question is simply, how do I, in effect, restart the Accounts activity so that the user would be presented with the option to login once more.
We're good people and all willing to help ;-) I'll give it a shot. Still, I'm not quite sure I get that all right.
Basically you have an TabActivity which you setup and where you do something like that:
myTabHost.setOnTabChangedListener(new OnTabChangeListener(){
#Override
public void onTabChanged(String tabId) {
if (tabId.equals("account") && !loggedIn) {
Intent logonActivity = new Intent(getBaseContext(), UserLogon.class);
startActivityForResult(logonActivity, 0);
}
}});
You're basically saying that the first Activity start of UserLogon works, but the second one doesn't, right? Did you debugged to that point to check whether you reach the code which starts the activity again?
Update based on comment
Your UserLogon should always provide a result information, here's a blueprint:
public class UserLogon extends Activity {
public void onCreate(Bundle bundle) {
// ... do something ...
// if activity is canceled this will be the "last" result
setResult(RESULT_CANCELED);
}
public void checkLoginOrSomethingLikeThat() {
Intent result = new Intent();
// put your results in this intent
setResult(RESULT_OK, intent);
// close activity since we have the information we need
finish();
}
}
The parent activity which is waiting for the result should do it like that:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// it's good practice to use a constant for 0 like LOGIN_REQUEST
// otherwise you will ask yourself later "What the hell did 0 stand for?"
if(requestCode == 0){
if (resultCode == RESULT_OK) {
// get needed data from data intent and react on that
} else {
// no success, react on that
}
}
// ... I don't know what your resultCode 100 is but handle itwith the same pattern
}
I need help in geting results back from intent launched from
preference screen
// Intent preference
DevicePref =
getPreferenceManager().createPreferenceScreen(this);
// Show a Screen with list of Devices Discovered
Intent i = new Intent(this,getDevice.class);
DevicePref.setIntent(i);
DevicePref.setTitle("Select Device");
DevicePref.setSummary(mSelectedDevice);
deviceOptionsCat.addPreference(DevicePref);
I want user to select device... In preference screeen I show "Select
Device" .. when user clicks that, another screen is launched by intent
where all devices are listed. User selects the device.
Now how do I know user selected which device? And I want to update
that in the summary.
Pls. let me know
Thanks
I got the answer, Hope it will help someone like me...
Do not mention intent while creating preference like I did in above code.. Mention intent on OnPreferenceClickListener and then do StartActivityForResult()
// Intent preference
DevicePref = getPreferenceManager().createPreferenceScreen(this);
// Show a Screen with list of Devices Discovered
DevicePref.setOnPreferenceClickListener(onPreferenceClick);
DevicePref.setTitle("Select Device");
DevicePref.setSummary(mSelectedDevice);
deviceOptionsCat.addPreference(DevicePref);
Then create OnPreferenceClickListner and here do StartActivityFromResult()
OnPreferenceClickListener onPreferenceClick = new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
if (preference ==DevicePref )
{
Intent i = new Intent(DevuiceOptions.this,getDevice.class);
DevicePref.setIntent(i);
startActivityForResult(i,CHOOSE_DEVICE);
}
return true;
}
};
Finally to get the result handle onActivityResult and update Summary field.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch (requestCode) {
case Constants.CHOOSE_DEVICE:
{
if (data!=null )
{
Bundle b = data.getExtras();
mSelectedDevice = (String) b.get("Name");
UpdatePreferences();
}
}
}
}
Thanks