Is it possible to set the file modified date on Android 11 without the all files access permission?
I tried using the createWriteRequest from the mediastore api. But that does not let you use the File API to call setLastModified. It only allows to update some data via ContentResolver.
updating the last_modified column is not permitted:
https://android.googlesource.com/platform/packages/providers/MediaProvider/+/master/src/com/android/providers/media/MediaProvider.java#6361
you will run into a warning: "Ignoring mutation of last_modified..."
Reason is commented in above inked source code:
Column values controlled by media scanner aren't writable by
apps, since any edits here don't reflect the metadata on
disk, and they'd be overwritten during a rescan.
..which makes sense.
Using the DocumentContract to update the last modified date does not work either
via ContentResolver and DocumentsContract.Document.COLUMN_LAST_MODIFIED
Related
I am trying to use the network to file plugin. Since the images come from my Firebase Storage, it speeks for itself that I do not want to overload my available bandwith so I want to use this pluging to save files locally as to not re-load them everytime.
The problem is, the Widget requires a File to store it (of course).
NetworkToFileImage(
url: "http://example.com/someFile.png",
file: myFile)
But I cannot specify a path, because the only way to get a writable location is through getApplicationSupportDirectory() which is an async method. A huge workaround would be to make tons of things asynchronous, but it seems weird that getting this location (which is not an IO operation, merely returning a constant String) is asynchronous. In Android Studio with Java for example, getting the folder can be done through synchronously through context.getFilesDir(). So why not with Flutter?
The user scenario is as the user use the application to request the files in the router, the router would send back a file string.(like JASON file but not)
It contains files or directories information. After parsing the string, it will create an object array so that I can push it to the adapter of a listview. As the user press on the directory icon, it would send an http request to request the file string again even if the files or directories information remains the same.
I just wonder whether I can hash the files and directories information to judge if the data has been changed or not. If it's not changed, I won't have to send another request.
But what information should be hashed and how to do so?
Is there any available plugin?
Please suggest some strategy to reduce the httpoverhead in this scenario.
If you write the files, then yes - you could create a checksum and write it at a known location, only reading entire file if the checksum's changed. That known location could be inside each file, or in a separate file per directory - pros and cons depending on your needs and how files may be changed.
If you don't write the files, you'll have to dig a bit deeper to work out how to do this with whatever insight the router's providing you. If the router-provided directory information includes any time stamps, checksums etc then you may be able to compare to the last time you downloaded the info and deduce which files have changed.
If not, you've no way of knowing if something's changed without downloading the files again, but you could take an attitude like "if it's been less than 10 seconds then who cares if it's changed - just show them the old data"... depends on your app whether that's sane.
If you want a pre-written checksum/hash - perhaps try MD5 - it's often used for file checksums on UNIX/Linux.
I am integrating dropbox in my android application. The requirement is to get all file metadata. I have downloaded dropbox sdk and I am able to authenticate user's credentials as well.
I am unable to get all files using this. this provides metadata of only root folder contents
mDBApi.metadata("/", 0, null, true, null);
I need to chain the api calls to get metadata of all files and folders. Now I want to do it lazily, like get 100 files, dump the metadata in local cache and get next 100 files metadata (irrespective of file location, i.e. no matter where the file is, in root or under 10 folders)
I am using "AccessType.DROPBOX" access to get all the contents. I know that there is a parameter for specifying how many files to fetch in one go ("0" in the above statement) but I want to keep fetching metadata till all data has been received in my client. Is there a way for this or a sample code may be.
Thanks.
The Dropbox API metadata call is meant only for retrieving a single file or folder's metadata. The best practices page indicates that you should not recursively call this endpoint:
https://www.dropbox.com/developers/reference/bestpractice
You may instead be interested in using the delta call to build and maintain your local state:
https://www.dropbox.com/developers/core/api#delta
I have a lite version of an application that uses a SQLite database. I want to copy that database over to the full version of the application when the user installs the full version.
I have written some code to perform the file copy, but the lite database file always comes up as unreadable. The file is there and I can point to it, but I can't read it to perform the copy.
In the Android documentation, we read:
You can save files directly on the
device's internal storage. By default,
files saved to the internal storage
are private to your application and
other applications cannot access them
(nor can the user).
Note the words, "by default".
Is there a way that I can override that default and make the SQLite file readable by my other application?
Thank you.
I believe you have 2 options.
Set the sql database to be world readable on creation. You can do this by setting the appropriate mode parameter in the call to openFileOutput() or openOrCreateDatabase().
Set the sharedUserId attribute in the manifest of both of your applications so that they have the same user ID. This treats both applications as the same user, giving both applications access to the same private set of files.
I have been battling with an issue in my Android app. I have been reading Android docs, my book on Android (Andriod Pro 2) and have looked at almost each and every example I could get my hands on but could not figure out how to implement storing of files (images, binary data) against records in Sqlite table exposed by the content provider.
Here is what I have done (almost similar to Notepad sample app):
Implemented ContentProvider in my provider. It all works for CRUD operations. Internally it uses an implementation SQLiteOpenHelper (pretty standard stuff)
I have added a _data column of type text
I insert a record and get the Uri back
Call openOutputStream on the content provider and start writing the data
This is exactly according to the Android Pro 2 book.Here is the snippet of that part of code:
Uri uri = getContentResolver().insert(MyAuthority.CONTENT_URI, contentValues);
OutputStream s = getContentResolver().openOutputStream(uri);
But I get the error below:
11-29 01:07:30.717:
WARN/System.err(1490):
java.io.FileNotFoundException: No
files supported by provider at
content://myproviderauthority/podcasts/1
What do I need to do? I read Android documentation but they are very vague:
the field that exposes the data to
clients should actually contain a
content: URI string.
1) So does the field type need to be TEXT or is there a special content: URI string data type?
2) At the time of inserting I do not have the URI. Do I need to get the URI after insert and then update that field in the record?
The record should also have another
field, named "_data" that lists the
exact file path on the device for that
file. This field is not intended to be
read by the client, but by the
ContentResolver.
3) So what should be the type of this field be? TEXT - I assume?
The client will call
ContentResolver.openInputStream() on
the user-facing field holding the URI
for the item.
4) This is utter rubbish! How can I call ContentResolver.openInputStream() on the field?? You can only call this on the record and passing the Uri.
Thank you for your time and I hope you can help me. I have also reviewed these SO questions (this and this) and they did not help.
By the way I am building against Level 4 of the API (version 1.6).
To see where "No files supported by provider at..." comes from, have a look here. The situation there seems very similar with the one you've described.
In short, your content provider (or some of its superclasses) needs to override and implement openFile method. That error is raised by the default "not implemented--back off!" code in ContentProvider.java.
I find it helpful to peek at underlying source code of the framework when I get stuck, since documentation is sometimes a bit lacking.