OTP detection in an app WebView - android

Is there any way to automatically detect OTP in a webview?
There is a mobile no. to be verified using a an OTP and OTP is to be detected in in app webview.
Thanks in advance

Whenever you get OTP via sms and notify by receiver, then inside webview whichever input text inside you want to add your OTP there you need to do something like this?
String otp = "OTP_FROM_YOUR_RECEIVER";
webview.loadUrl("javascript:document.getElementById('otp_input').value = '"+otp+"';");
Above code is just example you need to change as per your requirements and all.

Here the code in Kotlin:
if (Build.VERSION.SDK_INT >= 19) {
mWebView!!.evaluateJavascript(getString(R.string.fill_otp) + "\"$extractedOTP\";") { Log.e(TAG, it) }
} else {
mWebView!!.loadUrl(getString(R.string.fill_otp) + "\"$extractedOTP\";")
}
Put "fill_otp" in strings file:
<string name="fill_otp">javascript: function getInputs() {
var ary = [];
var inputs = document.getElementsByTagName(\"input\");
for (var i=0; i<inputs.length; i++)
{
if (inputs[i].type.toLowerCase() == \"password\"||
inputs[i].type.toLowerCase() == \"tel\"||
inputs[i].type.toLowerCase() == \"number\"||
inputs[i].type.toLowerCase() == \"text\"){
if(!inputs[i].hidden&&!inputs[i].disabled){
ary.push(inputs[i]);
}
}
}
return ary;
}
var array= getInputs();
array[0].value=</string>

Related

Preventing an android app being cloned by an app cloner

Created an app that used the device's uniqueID which is fetched by the following code snippet
String deviceId = Settings.Secure.getString(getContentResolver(),
Settings.Secure.ANDROID_ID);
When the user tries to clone the app by app cloner, then it creates a different deviceID and the app is not allowed to work
Is there any way to make our app non clonable
or
Any possible way to have the same deviceId even if the app instance is cloned?
Is there any way to find out whether the app is running in a cloned instance?
Applications like Cloner usually change your application's package name so you can retrieve package name and check if it is changed or not.
if (!context.getPackageName().equals("your.package.name")){
// close the app or do whatever
}
Also they usually sign cloned apk so the signature might be different from yours, you can check if signature is changed or not. I usually use this function:
#SuppressLint("PackageManagerGetSignatures")
public static int getCertificateValue(Context ctx){
try {
Signature[] signatures = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
try {
signatures = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNING_CERTIFICATES).signingInfo.getApkContentsSigners();
}catch (Throwable ignored){}
}
if (signatures == null){
signatures = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
}
int value = 1;
for (Signature signature : signatures) {
value *= signature.hashCode();
}
return value;
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
public static boolean checkCertificate(Context ctx, int trustedValue){
return getCertificateValue(ctx) == trustedValue;
}
Before releasing your app call getCertificateValue(context) and write down the value and alongside with package name, check if that value matches the value that you get in runtime.
PS: as #vladyslav-matviienko said hackers will always find a way so try to make cloning harder by running some obfuscations on hardcoded package name and that value. Also try to tangle and spread these kind of logics all around the source code.
I found a story in proandroiddev by Siddhant Panhalkar and with some minor changes it's work perfectly in Mi device I did checked in Mi phones default Dual apps and some third party apps from playstore and it prevents from cloning (means not working properly after clone).
private const val APP_PACKAGE_DOT_COUNT = 3 // number of dots present in package name
private const val DUAL_APP_ID_999 = "999"
private const val DOT = '.'
fun CheckAppCloning(activity: Activity) {
val path: String = activity.filesDir.getPath()
if (path.contains(DUAL_APP_ID_999)) {
killProcess(activity)
} else {
val count: Int = getDotCount(path)
if (count > APP_PACKAGE_DOT_COUNT) {
killProcess(activity)
}
}
}
private fun getDotCount(path: String): Int {
var count = 0
for (element in path) {
if (count > APP_PACKAGE_DOT_COUNT) {
break
}
if (element == DOT) {
count++
}
}
return count
}
private fun killProcess(context: Activity) {
context.finish()
android.os.Process.killProcess( android.os.Process.myPid())
}

Android email client app tracking unread gmail emails

So I've been using javamail API as part of my android app. After a login to a gmail account, the user can write new emails, check the inbox and sent mails. The emails are displayed in a listview with the help of an adapter class. (more accurately the sender, the subject and the sending date is displayed, and if the user clicks on the listview item, then the mail content will be displayed too on a new activity). All this is working well.
I would like to display unread emails differently (unread in the gmail client too), like set the textSyle bold if the mail is unread, but i'm having trouble adding this feature. I've been trying to check the flags of each fetched email message, but for some reason i dont see these flags in the variables.
My code snippet for fetching the mails (display is not here, that's in the adapter class):
protected ArrayList<Email_Message> doInBackground(Void... args) {
try {
Properties properties = new Properties();
properties.put("mail.store.protocol", "imaps");
Session emailSession = Session.getDefaultInstance(properties);
Store store = emailSession.getStore("imaps");
store.connect("imap.gmail.com", username, password);
// create the folder object and open it
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_WRITE);
Flags flags2 = emailFolder.getPermanentFlags(); //has 2 weird user flags in it ($phishing, $notphising) and systemflags = -2147483061 ???
Flags seen = new Flags(Flags.Flag.RECENT);
FlagTerm unseenFlagTerm = new FlagTerm(seen, false);
Message messages2[] = emailFolder.search(unseenFlagTerm); //this will net the same result as getMessages(), only here for testing
int test = emailFolder.getUnreadMessageCount(); //as far as i can tell this is working (i have 5000+ emails and 37 them are unread somewhere) but when i get a new email and the number goes up by 1 (38), and if i run the code again, after i already fetched the mails once, it's gonna be 37 again, and the mail marked as read in my gmail webclient too
// retrieve the messages from the folder in an array and print it
Message[] messages = emailFolder.getMessages();
int j = messages.length - 1;
for (int i = j - startIndex; i > j - startIndex - offset && i > (-1); i--) { //startIndex and offset are for displaying only 10 messages at the start and loading another 10 if the user scrolls to bottom
if (isCancelled()){
break;
}
Email_Message mailMessage = new Email_Message(); //my class for storing email messages
mailMessage.messageType = 1;
//some tricks to get the address in the right format
Address[] email_address = messages[i].getFrom();
String tempAddress = email_address[0].toString();
tempAddress = MimeUtility.decodeText(tempAddress);
//still tempering with address, not important
if(tempAddress.contains("=?")){
String[] AddressParts = tempAddress.split("\\?=");
mailMessage.messageAddress = AddressParts[1].substring(2);
}
else {
mailMessage.messageAddress = tempAddress;
}
Flags flags = messages[i].getFlags(); //user_flags = null, system_flags = 32
Flags.Flag[] systemflags = flags.getSystemFlags(); //has 1 item in it: bit = 32
String str[]= flags.getUserFlags(); //empty, these are all true for all my mails, not just one
mailMessage.messageDate = messages[i].getSentDate().toString();
mailMessage.messageSubject = messages[i].getSubject();
Object msgContent = messages[i].getContent();
String content = ""; //getting the content of the mail with these multipart stuffs
if (msgContent instanceof Multipart) {
Multipart multipart = (Multipart) msgContent;
Log.e("BodyPart", "MultiPartCount: " + multipart.getCount());
for (int k = 0; k < multipart.getCount(); k++) {
BodyPart bodyPart = multipart.getBodyPart(k);
String disposition = bodyPart.getDisposition();
if (disposition != null && (disposition.equalsIgnoreCase("ATTACHMENT"))) {
DataHandler handler = bodyPart.getDataHandler();
content = handler.getName();
} else {
content = bodyPart.getContent().toString();
}
}
} else
content = messages[i].getContent().toString();
mailMessage.messageContent = content;
EmailInbox.add(mailMessage);
}
// close the store and folder objects
emailFolder.close(false);
store.close();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return EmailInbox;
}
I put some comments in the code to explain what i've found in the flags. What can I do to make this work? I already predict problems, like what happens after I read an unread mail in my app only, set its flag to seen, and when I start the activity again and fetch the mails, it's gonna be unread again, since I don't store them locally, but that's a problem after I managed to find a solution for this first.
Thanks for any help!
I'm not clear on how you're looking for the flags. Using messages[i].isSet(Flags.Flag.SEEN) will tell you if the SEEN flag has been set. Note that the SEEN flag will normally be set as soon as you access the content of the message, so you should not have to set it yourself.
Hint: use the InternetAddress.toUnicodeString method, or get the name and address separately using the getPersonal and getAddress methods. This will avoid any need to decode them yourself.

How to check if a incoming message in Android has the correctly Keyword

I am creating a op-out app. I am using Incomming SMS Broadcast Receiver, I need to check if the incoming message contains a specific keyword:
i.e
From: 656565451
msn: I want to op-out news
code .i.e - "this does not work"
String senderNum = phoneNumber;
String message = currentMessage.getDisplayMessageBody();
//check if user message has this keywork
String keyWord_code = "op-out";
Pattern pattern = Pattern.compile("op-out");
if (pattern == keyWord_code ) {
//Do the op-out function here
}
else {
//Send message to user
}
I see that you are trying to use Regex?
Well, you can try something a little simpler first before going on to RegEx:
if( message.contains(keyWord_code) ){
// do something
}else{
// do something else
}
I don't know if you have problems with the receiver or what. If you just want to know if the msg body has the word "op-out" you just need the next code:
if(message.contains(keyWord_code) {
//...
} else {
//...
}

Android asmack how set invisible

in android Asmack i want to set invisible user.
and i used from every mode but it didn't works. after that i used from Type ..
when i set type unavailable, it works . but there is a problem .. my pocket listener doesn't work .. and i cant get any thing from user .. What can i do .. Thanks a lot.
Type type = Presence.Type.available;
Mode OWN = Mode.available;
if (DB_STATUS.avibilaty.toString().equals("")) {
OWN = Mode.available;
} else if (DB_STATUS.avibilaty.toString().equals("away")) {
OWN = Mode.away;
} else if (DB_STATUS.avibilaty.toString().equals(
"available")) {
OWN = Mode.available;
} else if (DB_STATUS.avibilaty.toString().equals(
"unavailable")) {
type = Presence.Type.unavailable;
} else if (DB_STATUS.avibilaty.toString().equals("busy")) {
OWN = Mode.dnd;
}
Presence presence = new Presence(type);
presence.setMode(OWN);

Android make home phone

When I give number="05338830967"; is like it is working but when I give this number number="03926502323"; it is not running, phone tell me that create internet call what is it?
private void makePhoneCall(String number) {
try {
for (int i = 0; i < number.length(); i++) {
if ( number.contains("-")) {
String[] numaraduzelt = number.split("-");
number= numaraduzelt[0]+numaraduzelt[1];
}
}
number="tel:+9"+number;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(number));
}
}
You may want to use the excellent libphonenumber library from Google that is being used everywhere including the Android framework for parsing and formatting phone numbers. This would allow you to validate the phone number before you attempt to send a dialing Intent.

Categories

Resources