Android set last modified time for the file - android

I have been using " public boolean setLastModified (long time) " for setting the file modified time but it always return false. I have seen few similar posts related to this but none of them could work for me. can someone give me solution for this?
Please do not post me any URL's, I have already seen them :
file.lastModified() is never what was set with file.setLastModified()
Is it possible to reset the last modified date of an Android file?
http://www.mkyong.com/java/how-to-change-the-file-last-modified-date-in-java/

setLastModified() is apparently unreliable on Android, perhaps working on some devices and not on others.

You are told to test the return value, false if it is fail.
Disappointed to find out about that...

Related

Ionic2-Calendar now failing on the device

I am developing an Ionic 4 based app with Angular 8 and have a strange situation that has developed. I am using this calendar.
It seems to be similar to this issue... and you will see I have commented there asking how they solved it to no avail.
It works fine on the browser using ionic -serve and WAS working fine on my android device (I haven't gotten to iOS yet).
There was an andoid update to my phone last week and since then, the calendar page doesnt work any longer.
I have stripped out most of the code and simplified it to the extent that it (almost) works now but I have to remove the datasource object.
This leads me to believe there is something wrong with the data in the datasource which I had found before when incorrectly formatted. However, I am uncertain if this is the issue.
The startTime and endTimes come from the server and are converted from ISO strings like this:
fixAppointmentTimesFromServer(appointment: Appointment) {
appointment.startTime = new Date(appointment.StartTimeServer);
appointment.endTime = new Date(appointment.EndTimeServer);
}
If I log out the type of object in the appoinmtents array like this:
this.userService.appointments.forEach( appt => {
console.log(appt.startTime);
console.log(typeof (appt.startTime));
console.log(appt.endTime);
console.log(typeof (appt.endTime));
});
it shows the start/endTimes as strings so I was wondering if this could be the issue, or if thats just more of the mystery that is JS Date objects..?
Or if anyone can tell me how to actually find and get into the Calendar module to debug it, then that might help?
I've added an additional:
this.platform.ready().then( res => {
...
at the start of the ngOninit().
The whole start/end time thing could just be a red herring...
Any thoughts at all? Thanks
I am answering my own question here since I don't want others to have the same issues I had tracking this down.
The way I was fixing up the date for the ionic2 calendar wasn't adequate (apparently) as it needs a millisecond based Date Object to work properly. Different browser versions seem to operate differently.
So, the way I fix up the dates from the server now is as follows:
fixAppointmentTimesFromServer(appointment: Appointment) {
const start = new Date(appointment.StartTimeServer);
const end = new Date(appointment.EndTimeServer);
appointment.startTime = new Date(Date.UTC(start.getFullYear(), start.getMonth(),
start.getDate(), start.getHours(), start.getMinutes()));
appointment.endTime = new Date(Date.UTC(end.getFullYear(), end.getMonth(), end.getDate(), end.getHours(), end.getMinutes()));
}
This converts first to a string and then converts again to get a UTC (millisecond) based Date object. Which does work.
A word of caution however:
I found that when I wasn't getting the data from the server, but using the already converted data from out of Ionic Storage, it broke again. This needing me to reconvert the data when getting it out of storage. So, this wasn't some 'funny date on the server' to JS thing, moreover a perfect example of how completely ******* up Javascript actually is!

Reading parameter field values

This is possibly the noobiest of noob questions, but I can't find the answer anywhere - maybe because I have my terminology wrong, maybe because it's not possible.
What I'm trying to do is determine whether a chronometer widget in Android is running, but the more general question is:
How do I read the field values that I can see in the IDE/debugger programatically?
For example, if I set a breakpoint after my chronometer is started, in the variables list (or when evaluating the chronometer), I can see a load of useful stuff all beginning with the letter 'm'. For example, mVisible, mRunning, mStarted, but I can't for the life of me figure out how to access them.
I'd like to know if this is possible in both Java and Kotlin, please. I've attached a screengrab of what I'm talking about :)
Thanks,
Iain
I think I've worked this out. I've declared an extension function:
fun Chronometer.isRunning(): Boolean {
val f = this::class.java.getDeclaredField("mRunning")
f.isAccessible=true // make it readable
return f.get(this) as Boolean
}
I can then read the value of mRunning with myChronometer.isRunning()
Suggestions for improvements are welcome. :)

Android Realm copyToRealmOrUpdate updates existing fields

When using copyToRealmOrUpdate it also overrides fields with existing values. I would expect it would only update the fields I gave and use the existing values for the other fields.
I saw this issue for createOrUpdateFromJson: https://github.com/realm/realm-java/issues/933
cmelchior says this:
It is impossible to tell the difference between an value not set and
it's default value, so there it should override all properties.
I wanted to create an issue with label enhancement for realm, but instead I ask it here first. Is it really impossible? Because it would be a great improvement to me.
Thanks!
Note there is difference between using Realm.copyToRealmOrupdate(RealmObject) and Realm.createOrUpdateFromJson(Json)
The answer I gave is true for copyToRealmOrUpdate() eg. you cannot tell the difference between the following in Java:
boolean bool1;
boolean bool2 = false;
It is different for JSON where you can tell if a property is missing altogether. However the current implementation doesn't work that way. We are currently in process of merging a Pull Request that actually has the behaviour you are looking for. You can follow the progress here: https://github.com/realm/realm-java/pull/1022

Why does calendar.isSet(field) change to true when calling many of the other methods?

I have a project where the isSet method of a Calendar would be very useful, but between clearing a field and reading the isSet flag for that field I need to call another method of the calendar that is affected by this issue.
Here's a sample to demonstrate what is going on:
Calendar cal = Calendar.getInstance();
Log.d(TAG, Boolean.toString(cal.isSet(Calendar.SECOND))); // true
cal.clear(Calendar.SECOND);
Log.d(TAG, Boolean.toString(cal.isSet(Calendar.SECOND))); // false
cal.getTimeInMillis();
// These other methods I've tried, and I'm sure many more, have the same affect on isSet:
// before(calendar), compareTo(calendar), get(field), add(field, int), set(field, int)
// Note: 'field' in above comment line refers to a field other than Calendar.SECOND
Log.d(TAG, Boolean.toString(cal.isSet(Calendar.SECOND))); // true
I've looked at the source for the Calendar class and I don't see what's causing this. Does anyone know why this is happening? Do I need to track the set fields separately?
Update:
It appears this issue may be Android-specific or perhaps a specific version of Java since a couple answerers said it works for them in standard Java. Just to be clear, the class I'm using is still java.util.Calendar. In case the info might help, I am building against the Android 2.2 platform (API 8).
Update 2:
According to someone in #android-dev on FreeNode and my subsequent research on Wikipedia, this is probably because Dalvik uses a subset of Harmony (a Java implementation) for its class library instead of Java. However, that then gets me wondering why Harmony changes the isSet behavior. Needless to say, this issue sounds like it's way too far upstream for there to be a fix in the Android SDK any time soon, so I'll need to settle for a workaround.
I'll leave the question open since it hasn't been properly answered yet.
Is it bug in Harmony as I suspect or intentional design? If intentional, what is the purpose and is there a way to use it as I'm wanting to use it?
Update 3:
I've posted the issue to the Android issue tracker, now to wait and see if anything happens from it. Please star it if this issue is a problem for you as well. I'm hoping Android has its own fork of Harmony and doesn't need to wait for the fix upstream.
https://code.google.com/p/android/issues/detail?id=16826
Also removed the java tag since this is clearly not a Java issue.
Works as expected for me
Working as expected for me..
Here is the code I have used
import java.util.Calendar;
public class Test {
/**
* #param args
*/
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
System.out.println(Boolean.toString(cal.isSet(Calendar.SECOND)));
cal.clear(Calendar.SECOND);
System.out.println(Boolean.toString(cal.isSet(Calendar.SECOND)));
cal.getTimeInMillis();
System.out.println(Boolean.toString(cal.isSet(Calendar.SECOND)));
}
}
And here is here is the output in console
true
false
false
Thanks,

Robotium: searchText

I have a strange situation I can't explain myself.
The following code works well:
solo.sleep(1000);
assertTrue(solo.searchText("Banking"));
but the following code fails:
assertTrue(solo.waitForText("Banking", 1, 1000));
Can someone can explain me this?
Kind regards,
Alban.
The problem is that '1000' in waitForText isn't setting a delay, it's setting how long to keep looking. If it doesn't find the text within that time, it returns false. See Robotium source
Try the second version like this and see if it doesn't work:
assertTrue(solo.waitForText("Banking", 1, 10000)); // Take up to 10 seconds
Also, the delay before the first one probably doesn't change anything. I think the first example would work just as well if it was only:
assertTrue(solo.searchText("Banking"));
Before robotium-1.7.1 there were some issues with searchText(). It was definetely not always finding the text even when it should. You might want to try again with simple code without timing.

Categories

Resources