Is there any way to prevent copying data from an Android application? - android

I would like to prevent the users of my Android application to copy and paste data from my application to anywhere else but within the application itself. Given that the clipboard is one of the more common ways for exposing sensitive data, I am wondering if there is any way to limit the scope of the clipboard, so that it can only be used within the application?
I've already created a solution to prevent copy/paste in the application's text components (TextView, EditText...), but I am looking for a more efficient approach to this problem. I've been thinking about clearing the clipboard on exiting the application, but I don't want to do that, since the user might have important information he/she wants to keep in the clipboard.
Has anyone else faced a similar situation before? Do you have any ideas on how to do this?
Thanks!

This is not a full solution but you could limit the use of the copy and paste to one time use.
This way the sensitive data is not lingering.
public Class ClipboardUtils{
public static clear(Context context){
ClipboardManager clipBoard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
ClipData data = ClipData.newPlainText("", "");
clipBoard.setPrimaryClip(data);
}
}
With an edit text you could do something like this
EditText et = (EditText) mView.findViewById(R.id.yourEditText);
et.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (count > 2)
ClipboardUtils.clear(getContext());
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void afterTextChanged(Editable s) {}
});
sources
Clearing Clipboard Data in Android
Android intercept paste\copy\cut on editText

Related

Update a specific row in a Room Database of Android

I am new to Android and need some help.
I have a listView with some edittext fields and buttons and store the information of the edittext in a room database.
Looks like this: https://imgur.com/a/NTpMUmY
Now, when I change the input of field A to, let's say AAAA, and click on the "button", the room database has to update the row.
My question is when exactly do I call the update command, and how does room know which row has changed? I don't want to update to whole table.
Let me know if I should explain it in another way.
Ok, I found a solution which works for me.
TextWatcher textWatcher = new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
Dao_db.update(s.toString());
}
};
viewHolder.bearbeiten_et.addTextChangedListener(textWatcher);
I use this Textwatcher (didn't know that something like this exist) and update my db when the text changed. :)

How to create a class that creates onTextChangedListener and allows the programmer to set different behaviors

I'm programming on Android and I want an easy way to do the things below without having to have a bunch of overrides and ugly code:
These are all examples:
When editText1 is changed I want a TextView to be updated with copy of what the user typed
Same thing for editText2 up to editText10.
When editText11 is changed I want to multiply the number in it by 10 and put it In some TextView.
When editText12 becomes 0 I want some LinearLayouts to hide
Basically I want to be able to easily set up a listener and modify what kind of method the listener will trigger, without having a bunch of anonymous inner classes and other nasty stuff. Having many derivatives that each do their own predefined thing is OK, but I want to avoid repeating code and make it utilize polymorphism.
I tried really hard using interfaces, abstract methods, and other similar techniques but it just made my head go crazy.
What you probably want is a TextWatcher
How to use the TextWatcher class in Android?
Here's an example:
http://www.learn-android-easily.com/2013/06/using-textwatcher-in-android.html
You can pass TextView objects into it and monitor the text text as it is input by the user. However, even this is probably pretty complex based on the requirements you are describing and the general unpredictable behavior of users in general.
Why don't you try something like this for a custom TextWatcher with an event-listener callback you can use for after the text has changed:
public class CustomTextWatcher implements TextWatcher {
public interface TextChangedEventListener{
public void afterTextChanged(String newText);
}
private TextChangedEventListener eventListener;
public CustomTextWatcher(TextChangedEventListener eventListener){
this.eventListener = eventListener;
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
eventListener.afterTextChanged(s.toString());
}
}
Now for the Implementation...
EditText editText = (EditText)findViewById(R.id.my_et);
editText.addTextChangedListener(new CustomTextWatcher(new CustomTextWatcher.TextChangedEventListener() {
public void afterTextChanged(String newText) {
// set the text of the next EditText, which will trigger the next TextWatcher in the chain
}
}));
You're still going to have to deal with an anonymous inner class, but there's not really a way around that if you want customization for each EditText. At least this will cut down on the number of inner classes from 3 to 1 and clean up the code you have to look at a bit.

Filter ListView in real time

I want to filter a ListView in real time. I have an EditText in the ActionBar, and each time the user writes a character I want to update the cursor of the ListView filtering the information.
I have done an AsyncTask to perform the query but I have two questions:
1º) If the user types three characters I'm creating three AsyncTasks (one to search the first character, one to search the two first characters, and finally one to search the three characters). Is there a simple way to say to the AsyncTask to replace the previous task with the new one?
2º) How can I put a small delay to start the AsyncTask? So if the user types three characters without stopping, I will not create the AsyncTask until the end.
Thanks!
Hmmm...Not totally sure why your using AsyncTask for search in real-time. Here's how I would(and have successfully) do it.
Add a TextChangeListener to your Edittext:
editText.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
searchResults = myDbHelper.searchAll(s.toString());
searchAdapter.notifyDataSetChanged();
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
#Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
I am searching through a sqlite database everytime a user presses a key. My searchResults is used to populate the ListView, and so after I set the get the search results, tell the list adapter that the data set changed.
Hope this helps.

Validating edittext in Android

I'm new to android & I'm trying to write an application for a project.
I need to check whether the user has entered 7 numbers followed by one alphabet in edittext.
Example: 0000000x
How should I do that? TIA! :)
Probably the best approach would be to use a TextWatcher passed into the addTextChangedListener() method of the EditText. Here is an example use:
editText.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable e) {
String textFromEditView = e.toString();
validateText(textFromEditView);
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//nothing needed here...
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//nothing needed here...
}
});
I will leave the implementation of the validateText(String) method as an exercise for the reader, but I imagine it should be easy enough. I would either use:
A simple Regular Expression.
Or since this case is easy enough, checking that the length of the string is 8, and reviewing each character. There is a simple utility class to inspect the characteristics of characters. Character.isDigit(char) and Character.isLetter(char)
OnKeyListener listens to every key stroke in the view. you can use that to check whether the user has entered what he is supposed.
eg : if the no of char entered is 7 then
check if it follows the reqd expression format.
There is a Class called Pattern in Android in that you can give Regular Expression to match your Requirements try this follwoing code i think it may work
Pattern p = Pattern.compile( "{7}" );
Matcher m = p.matcher(String.valueOf(edittext));
This will be true only if 7 characters are there in the Text box and then you can use some menthods like "Character.isDigit(char) and Character.isLetter(char)"

show data in listview from webservice according to keypress in android

I am developing an android app for a Korean client. I have to search a data according to key press, like, if I press A then all the data who started from A show in listview where data come from a web service in listview. Is it possible?
If yes, then how to do it. If possible give me some code or link which I can use?
Thanks.
Yes its possible.You can add TextChangedListener on your edittext and in the onTextChanged event get the date from the webserver as json or xml and parse that data and show the data in a listview.
edittext.addTextChangedListener(textWacther);
final TextWatcher textWacther = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
getdata();
}
};
Getting the data from webserver this question might be helpful for you
How to connect to a Remote Database with Webservices?
At the area where getData() is called in #Syam's code, fetch the new data according to the text entered in the edit text, put it in the array that has the source of ListView, don't forget to call setDataSetChanged() on the adapter in the end.

Categories

Resources