Auto open application only once [duplicate] - java

This question already has answers here:
Log in screen on first start
(4 answers)
Closed 10 years ago.
I want to make an app similar to SetupWizard. My app should initialize ONLY ONCE when the phone is turned on for the first time and after that it is never displayed. I got the way to autorun it on every boot as a service but how to make it run only once?
I HAVE RESEARCHED

You can store some value in SharedPreferences. And place a check on the value, if it exists and, then it means the app has already initialized.
SharedPreferences can be cleared by the user(just like web-session). If you want to ensure that your solution works even if user clears his phone, then you can get the device IMEI(example here) and send it to some server, which checks whether this device has already initialized or not?

Related

Saving permanently user input for later use and expanding your program [duplicate]

This question already has answers here:
Best way to save data in a Java application?
(4 answers)
Closed 2 years ago.
EDITED QUESTION
I made a small sequential program in Java which can calculate my daily bonus for my job. It's not the most beautiful or optimized bit of code but hey it works!
Now it would be cool to have this actually save my input for that day somehow and even when I terminate the program the next time I open it should still have stored that end value somewhere. Maybe even go back to that specific day and check my PPH (productive hours) and maybe even calculate the whole month (which is actually the end goal and track my performance).
Any suggestions?
***** Answers I found ******
This is the first one i found but is not super useful if you would like that your colleagues also use your application. For single use and store a file locally it would work. https://attacomsian.com/blog/gson-read-write-json#
Using an SQL data base: https://www.ntu.edu.sg/home/ehchua/programming/java/JDBC_Basic.html

Java Android call requires permission which may be rejected by user [duplicate]

This question already has answers here:
Android M - check runtime permission - how to determine if the user checked "Never ask again"?
(29 answers)
Closed 5 years ago.
When I call the getLastKnownLocation () method I get an error "Java Android call requires permission which may be rejected by user...". Apparently it's due to API23.
I can't find a valid solution yet.
You can use shouldShowRequestPermissionRationale() to check if you need to show the reason why you need this permission (and if it returns true - show the reason), and, of course, you need to request permissions with requestPermissions() method.
So, you can't do anything if user rejected the permission. It is meant to give error if user reject the request. You can do one thing if user deny then give a dialog to user asking to accept it otherwise the functionality will not work and redirect him to that permission dialog.

Restrict the If block [duplicate]

This question already has answers here:
Run a piece of code only once when an application is installed [duplicate]
(4 answers)
Closed 5 years ago.
I have an if condition in my Java code in Android and I want to enter the block it's the first time the user has run the app. But for the second time and thereafter, they ignore the conditions.
How can I restrict the if block in my Java code?
This is my if block condition:
if(AppSharedPrefs.getInstance(SplashActivity.this)
.readPrefs‌​(SplashActivity.this‌​, "language").isEmpty())
{
AppSharedPrefs.getInstance(SplashActivity.this)
.writePrefs(S‌​plashActivity.this, "language","English");
}
You need to have shared preference for your purpose. On first time store value true to shared preference and when next time user comes to the app get value from shared preference if that is true you dont need to call your code
"Simple": you pick one of the options for storing data on the device.
And then, your code reads that data back every time the application starts.
See here for an overview of options, and there for the option you should pick (shared preferences).
In other words: the whole idea is that you have to enable yourself to store data; so that your code can later make decisions based on that data. That is all there is to this.

How to programatically clear a diffrent apps data [duplicate]

This question already has answers here:
How to programmatically clear application data
(10 answers)
Closed 8 years ago.
am making a app that clears the internet cache when you click a button. In which i want it to have the permission you clear other app data. I have tried many different codes and cant find a one that is used for this purpose. Is there a special permission i need or is it even possible.
I have tried this code in MainActivity.java but cant seem to get it to work:
private void clearPreferences() {
try {
// clearing app data
Runtime runtime = Runtime.getRuntime();
runtime.exec("pm clear com.android.browser");
} catch (Exception e) {
e.printStackTrace();
}
}
Any help would be great. Thanks!
To clear it you simply delete the contents of it's data directory. There are 2 locations one on the SD, and another internally. You can clear the one on SD no problem, just use Apache FileUtils from Apache Commons, it has a function to delete a directory recursively. The internal dir requires root access. Or to be of same user. If you made both apps then it should be no problem just make sure they are the same user by setting sharedUserId parameter. If not, then your app could only work as root. See this answer to get data directory.
An alternative to rooting, you can open up the app info page for the app in question and tell the user to clear the app data manually by tapping on the clear data & clear cache buttons.

How to implement keystroke logging by java [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do you record keystrokes when operating on another window in Java?
Try to get all keystroke on the OS. any ideas?
Yeah possibly u should get the keystrokes of the users through the use of currentTimeMillis method or so in java in any of the keyPressed() or keyReleased() methods in java.Then save those time recordings in any variable get the time difference and then compare it with the keystrokes stored in database with a particular threshold.It should work then.During the recording phase make the user type the intended filed 5-6 times, take the keystrokes recording of the user and then save its mean in the database and compare it with the current keystrokes of the user while he tries to log in.

Categories

Resources