How to take backup for installed packages? - java

I'm trying to develop an application for taking backup for my device. How can I write this? Till now, I've got all the installed packages list and I'm placing 3 buttons for taking the backup(Backup, CheckAll, Cancel).
If I'm going to take backup button it contains one alertdialog it shows 3 options (now, later, cancel). How to take backup the installed packages to one new list and it'll shows by date and time. How can I do this? Any idea?

i don't know if its possible to do that. I remember that i read in an article that in order to access to other packages you need to use the same user that the app does, and from my point of view that means that all the applications that are going to be backed up need to have the same user. I'm not an android expert but i think it wouldn't be possible to gain access to the other packages if you try Java IO to read the files as you normally do.
Good luck, maybe someone knows how to do this.

I don't know what do you mean by backup installed packages.
Generally users keep backup of their database and preferences data.
If you want to take a backup of your database and preference then you can create xml of your database and preferences using xml-serialization.
More information about xml-serialization Click here
And also you can refer inbuilt facility for get backup Click here

Related

Backup and Restore MS SQL Server database through Java Program

I have developed an Java Swing Application with MS-SQL Server database and now i want to provide backup and restore option in my java swing application that is on click of a button it should backup the database and restore the database any possibilities of how can i do it through java. please help
Two ways to do that. Backup and restore are just sql commands so you'd do them just the same as as you'd do any other bit of sql, e.g. a sql insert statement, unfortunately you need to know a fair bit about the the system to just do them, and you'll get no progress indicator. Using SQLSMO is another possibility, not sure about hitting a .net dll from java though. You could use SQLDMO (pre.net), but you'll need to install the backwards compatibility tools, and you'll give yourself an upgrade headache as DMO (while it seems to work) is not supported from SQL2012. Both have an event you can tick a progress bar on, course if the back up is fairly quick you could get away with not bothering with that.
However, some more to think about. You can backup while the system is running, but then you'd don't have a clear point where the system was at when you did.
Restore requires exclusive access and a high level of privilege, so it's not something you hand out and you need to get everybody off the databases.
And last but far from least it would be very bad, if you inadvertently restored a version of the database that no longer matched the application....
Personally I'd say the people who were authorised to do this should be able to do it without your tool. Dumbing it down, means a lot of code to make sure they don't restore a sql2000 back up from the trial you put out eight versions ago.
We did something similar back up restore code is a bout 2% of the application. For instance we do a pre-backup check, using dbcc et al, to make sure they aren't successfully backing up a corrupt db...
You can write a simple script to backup your database and invoke it from java.
You really need to put a little effort in here.
Since you can connect to the database server already and send it SQL commands, read this for backing up using TSQL.
For database restore, read this.
You need to have the appropriate permissions and access to the hardware for this to work.

How can I get Java to get preferences from an alternate location?

I'll preface this with two notes: 1) I know very little about Java. 2) What I am about to ask for is almost certainly a horrible hack.
I have an application I did not write, and I have no control over the code. It runs on (among other things) a Linux machine. It stores its preferences (presumably using the Preferences API, about which I know nothing) in a structure under $HOME/.java/.userPrefs/...
My problem is that I want to run more than one instance of this code, with different preferences in each instance. Is it possible to tell the Java interpreter to use an alternate location to store preferences, either using a command-line argument or an environment variable?
Edit: I'll add the additional stipulation that each of the instances needs to run under the same user, with access to the same (non-preferences) files.
It's Simple. It seems be to be individual's user directory. Try running/execute the same program under different user accounts.
If you dont have access to the code to check how it really is working and it is saving the preference in a user folder I think your best bet is to run it as different users.
That being said, you can always decompile the code and try to find out if there are any options to pass a preference directory.
You could potentially create different chroot's for every instance that you would like to run.
The answer appears to be "it can't be done."

set up database directory

I am working on a Java Desktop program which upon its installation will designate a default database directory and working directory. Where should I save such information so that the next time the user open the program, the program knows where to look for database and working directory?
Things that come to mind:
store everything in the registry (well, did that in MATLAB version and if there is another way, definitely will not go there).
set up another database attached in the jar file to store everything
Is this a so called persistence problem? What are Java Persistence or Java Data Object? Do they have the way to make it working?
any other suggestions?
Take a look at the Java Preferences API. It is a standard Java SE mechanism for storing preferences that does so in a platform specific, but application neutral way. Uses the Registry on Windows, Preferences files on OS X, and I believe ~/.files on Unix.
The Preferences class was created to store things like... preferences in an OS-neutral fashion.
You could also just specify a directory location manually, through a launcher script, or create a default directory in the user's home, and keep both configuration and DB files there.
Your persistent memory is your hard drive, of course, so you need to store data there if you want it to persist from execution to execution. Really, anything goes. You could store the configuration in an XML file -- makes it user-readable outside of the application, which is really nice for debugging, and Java comes with libraries for XML parsing and generation. It would be OS-independent, unlike a registry solution, which is Windows specific. And you could use the XML approach to share information between apps, if that matters. Something to consider.
Update: Preferences are cool! Never saw that one before.

Run SQLite commands on database in one app from another

I have an SQLite database stored in the assets resources of one application used to load UI and other stuff into the app, mainly just holding text nothing out of the ordinary. I want to be able to get a writable version of this database so I can modify it from another application.
Example:
First application is on the market with limited number of enabled features. User gets to a certain point where they need to buy extra content to do more stuff in the app. The original app has these features but they are not enabled in the app using the database. I want the user then to download a second app from the market which is just used to change one field in the database from disabled to enabled thus unlocking the new features.
I have an idea I may need to use content providers but my understanding is once created they are accessible to all applications. I need it, for piracy reasons I guess, to only be able to communicate with apps signed off by my key.
Thanks
Sam,
I understand what you intend to do, but you are going about it the wrong way. Your 'Unlock App' would not be able to modify the Database in the assets folder of your 'Free App'. That's just general android security model stuff.
You may want to look at this question: How can I use the paid version of my app as a "key" to the free version?
It describes how you can create a 'Unlock App' on the market to unlock features of your 'Free app' without needing to actually modify any of the original data in the 'Free App'.
Good luck

What's the best approach to build the same Android apps for different public?

I'm working on an app that is meant to be used by fans of a sport team. In the future, I expect to use the same app but for any different team. So, what changes would be the colors, team logo, app name and the like.
So, is there any technique that allows me to build binaries for different teams without having duplicated resources?
Probably the best way is to depart from the default build system. That typically means writing custom Ant scripts (or you could use some kind of preparatory script that manipulates the resources prior to invoking the default build).
I've previously sketched an outline of how I achieved something similar.
Is it possible to have one binary that contains all the resources and have the user select which team they want from the app itself? Then the app can load whichever resources it needs.
There may be a better way to do this, but here goes:
Build your app for the first team and make all logos / team names / styles / etc resources. Then just write yourself a script that allows you to delete all the items in the res/ folder of your project and replace them with different items. If you are smart, then most of the string's like team names are included in the logos, so all your script has to do is to delete the old ones and copy in the new ones from some other location on your hard drive.
The worst part about this is that you will have to define android-type file for the styles. It might be good to have your script take as parameters a team primary & secondary color, and actually generate all the android-type style files.
Again, there might be a better way, I am just saying that this way could be a solution.
I think build your application which will load the image , colour information from internet / your server. then,
1) ask user for team name which they are following and download image,color information from internet/server and store it as local. don't download next time.
2) attach any global id with each build which will download the image,color information from server first time user installs the application.

Categories