How to remove User data from my app through Ionic? - android

I have an Ionic 4 App that use IonicStorage with IndexDb .
The user will take some photos that will be saved in the storage. After the process is done, if the user will take a look into app settings will see something like this:
Problem:
When the user will attempt to perform another login the user data must be erased, cleared. I tried to delete the data by calling the clear method from the storage.
/**
* Clear the entire key value store. WARNING: HOT!
* #returns {Promise} Returns a promise that resolves when the store is cleared
*/
public ClearStorage(): Promise<any> {
return this.ionicStorage.clear();
}
Also I added these flags in the config.xml ...but without success. I can't erase it
...
<application android:allowBackup="false" />
<application android:fullBackupContent="false" />
...
Can you suggest me something. Ty

I understand whats happens with the storage and with the user's data. The problem is not the clear function, it's working perfectly fine. The problem is that the methods from the storage object are logged into a specific file. Basically when I save a base-64 photo into a storage object it automatically add a new entry to the log file (eg: One base64 string image has around 500kb so the log file size will increase with 500kb).
The file is also private. The problem that also remains, so how can I delete the log file from Ionic?

Try this.ionicStorage.remove('yourStorageKey') for each of your storage keys to remove all data in IndexedDB or sqlLite.

Yes, this is working just on the app storage (saw it through chrome inspector). The user data are not cleared.

Related

Firebase StorageReference getActiveUploadTasks return 0 results

I am uploading files in the background in Android. And and to cancel it I store the reference. Now when cancel is clicked and I try to get that upload task from the reference it gives 0 results.
Heres my code:
// Storing the reference
StorageReference storeRef = FirebaseStorage.getInstance().getReference().child("Folder1").child("Folder2").child("Filename")
UploadTask task = storeRef.putFile(file);
intent.putExtra("reference", storeRef.toString());
// Retrieving the UploadTask
final String ref = intent.getStringExtra("reference");
if (ref == null) {
return;
}
StorageReference sRef = FirebaseStorage.getInstance().getReferenceFromUrl(ref);
List<UploadTask> taskList = sRef.getActiveUploadTasks(); // taskList.size() ---> 0
You may want to start verifying your database connection and see if the reference is done correctly.
If you can discard that, moving to the next step would be to check the upload method is working, maybe a screenshot or simply checking your database in the console inside Firestore is enough if your files are in the cloud.
As you described, you are uploading files in the background. Following the Handle Activity Lifecycle Changes and using your own implementation would be the best option to correct this behaviour.
If you want to check the full example, it is at the end of the same page. Please be aware this example is for uploading from a stream or data in memory apparently, so you need to add the appropriate “uploading from a file” methods.
Continuing with the downloading of the reference, I would redirect to this page for downloads that continue in the background. In both pages, for uploading and downloading the files, you should add the missing code; this is only compared with the code that you already provided, as many parts are still missing. You should read the guide very carefully to avoid skipping any step. And also check the methods are for the correct data type you are using.
Finally, adding a method for handling errors would be great. As in this case you haven’t found the origin of the issue or got any logs to help us debug your code, this could help you save a lot of time and effort in case you encountered yourself with an issue like this one.

Save Data before Auto Update

When an automatic update occurs, the old date save in the preferences for my app gets delete.
How can i prevent this deletion?
I want that when my app auto updates , it does not delete my old data saved.
I am not sure whether this will be a good solution but just a suggestion you can try.
step 1: whenever you changeg (add/edit/remove) your data store it in permanent storage, you may try any of the following
a. save the data in file in sd card
b. store the data to your remote server or
c. store in internal memory of the phone.
(I am not sure whether it will persists after update at case c, for reference can check here
Step 2: creae a BroadcastReceiver that listens to the ACTION_PACKAGE_REPLACED Intent. So you know when your application package is updated. NOw read the data again from the storage where you saved the data ( either 1a/1b/1c)
Caution: It is not a good thing to save user data without his concern.
Android save your SharedPreference under /data/data/your package name/shared_prefs
Generally, update application won't delete your sharedPreference.
private void replaceNonSystemPackageLI(PackageParser.Package deletedPackage,
PackageParser.Package pkg, int parseFlags, int scanMode, UserHandle user,
String installerPackageName, PackageInstalledInfo res) {
...
// First delete the existing package while retaining the data directory
if (!deletePackageLI(pkgName, null, true, PackageManager.DELETE_KEEP_DATA,
res.removedInfo, true)) {
// If the existing package wasn't successfully deleted
res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE;
deletedPkg = false;
} else {
....
}
....
}
I think you need to check the following:
Is your device a rooted device? Apps on a rooted device can delete anything they want.
Did you use a different package name in that updated apk?

Get an image URI in a preference screen!

So, what I'm actually looking for is this solution: Get/pick an image from Android's built-in Gallery app programmatically but working in a preference and not in an activity.
I created a class that I put in my setting and I want to use that class to be able to find the URI of an image selected by the user on its phone. I couldn't use the code in that link because of "startActivityForResult". Which is not available in a preference.
Any idea how to bypass this ?
PROGRESS REPORT:
So, I tried some stuff in the mean time. Instead, in my settings, I added the following:
<Preference
android:key="test"
android:title="open image"
android:persistent="true">
<intent android:action="android.intent.action.GET_CONTENT"
android:value="image/*"/>
</Preference>
First, instead of "GET_CONTENT", it was "PICK", but with it, I can only go with Google Docs and the Sim Card Tool Kit, which is far from the gallery or any thing to browse the file system.
With "GET_CONTENT", it crashes.
I also added the "android.permission.WRITE_EXTERNAL_STORAGE" premission, even if I just want to read. But I didn't found any (let put this as a sub question, if there's a way to just ask to read and not write).
PROGRESS REPORT #2
I replaced android:value by android:mimeType and I goes directly to the gallery. Now, just need to know if I really got the URI and it's solved.
PROGRESS REPORT #3
At this point, here's the real problem. When I go through my SharedPreferences, the value stays empty, even after selecting an images. So, I guess there a little hack to do. So now, that's the question. Based on the example of my preference screen above, how can I retrieve the value of "test", assuming that when the intent is called, it put it somewhere ?
I finally found a solution... it's not as feng shui as I would like, but it works.
I simply code the preference screen by hand and then I was able to access the "startActivityForResult" function.
From this point, it took 3 to 5 minutes to solve it and finalize all the details.
Hope it helps some people.
You have an example there: http://www.anddev.org/code-snippets-for-android-f33/preference-screen-with-custom-views-t8472.html
But the one I used was on google, but I couldn't find the link.

Android - Saving state of dynamically changed layout

I have a layout where users can add buttons and place them where they want.
I want to allow the user to save their layout so that it is loaded the next time they open the app.
Does anyone know if I can save the file on the sdcard? Alternatively I could use some kind of layout.getXml() method and put it in the database my app uses.
Thanks in advance
There is no file to save when you are generating a layout via code. You will have to create your own file format, which could be saved to the SD card or inserted into a database.
You can us savedInstaceState() method with the same type object as parameter .
there load the ui you want at the time of reloading.
In onCreate() method put a condition whethere that savedInstaceState obj is null or not . if not then call the LoadUI().
If I were you, I would create a class holding all the information about this layout and buttons. And write every information of the class to a file with JSONWriter. When the app has opened I just read the file and recreate the arrays using JSONObjects.

How do I store a JPG in Android, for later use?

I have an app that is "skinned" at launch. The idea being that it looks to the server and loads several graphics for display. It then moves through a sequence of Activities. I don't want it to have to keep visiting the server for the art, however, every time it comes to Activity 1. I want to be able to store the images until such time as the user manually clicks a "refresh art" button.
I have every part of this worked out (the downloading, display, storing bits of other data in SharedPreferences), but I can't figure out where to save these images. They don't need to be available to any other application, I just want to have access to them from one running of the app to the next, until the user manually refreshes them.
TIA.
You could cache them on the sdcard.
you can save your images as static Bitmap objects in an extension of Application class, and referencing it from manifest:
manifest.xml
YourApp.java
public class YourApp extends Application{
public static BitMap[] myImages = new BitMap[someSize];
YourActivity.java
in somewhere..
YourApp.myImages[position]= myImage;
I think it can work.
But use this only if your images are small and few ones.
The right thing is to save them in the disk, I prefer to use the internal storage against the sd card, take a look of this http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

Categories

Resources