This question already has an answer here:
Not getting correct value when retrieving current outgoing phone number in android
(1 answer)
Closed 9 years ago.
I am trying to get outgoing call number with intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER), but every time I try it returns null. I did put needed permissions and action in Androidmanifest. Can someone tell me what I am doing wrong or how to retrive number another way?
Ok, I found out what was wrong.
First of all intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER) gives you outgoing number while phone state is idle and turns to "null" while phone status changes to OFF_HOOK.
The easiest way was to save the number before another onRecive happens.
Related
This question already has answers here:
android-firebase childEventListener in service
(2 answers)
Android: Firebase realtime database updated when app destroyed
(1 answer)
Closed 10 months ago.
My Arduino-Uno(this chip is not related to this question) sends either one of two values to firebase, 1 or 0, I want it so that every time the value in the database is updated, it gets detected in android studio and it checks if the value updated is one
I don't particularly require a block of code, I just need to know the concept of this part. I want my app to check for the value even if the app is closed, for which which I did find something on stack overflow.
I want my app to check for the value even if the app is closed
That does not seem hard. You can use a Service class and then do the event listener task there. Since you haven't asked for any code, I won't share it.
This is a good post on it
SmsRetrieverClient.startSmsUserConsent (senderPhoneNumber /* or null */)
This senderPhoneNumber is the number I know I will be receiving OTP from. My question is if I pass null, it can extract OTP from any number as documentation says (pass null so that it will consider any number would be allowed.). How will I know that my sender is correct? What happens if I receive two OTPs?
If this is not possible can I somehow pass two sender numbers that I am sure that either would be sending my OTP?
Anyone have any knowledge regarding this, please let know.
I did my research and writing my answer with my best. Coming to your questions
What happens if I receive two OTPs?
The answer to this question is you will not receive two messages in most of the cases which contain an OTP within a span of 5 minutes.
Even though let's consider a worse situation. Suppose you receive 2 SMS containing OTP back to back in that case SMS user consent API will only show the consent for the first received SMS (Assuming you have mentioned null as sender phone number).
So basically what happens is the user consent api will stop listning for sms once it detects and show a consent.
If this is not possible can I somehow pass two sender numbers that I
am sure that either would be sending my OTP?
Answer : Yes you can. if you know the senders possible names i.e say AD-Something, BC-Something, CC-Something then you can register the listners for all 3 of them one by one like this
val task1 = SmsRetriever.getClient(applicationContext).startSmsUserConsent("AD-Something")
val task2 = SmsRetriever.getClient(applicationContext).startSmsUserConsent("CC-Something")
val task3 = SmsRetriever.getClient(applicationContext).startSmsUserConsent("BC-Something")
once you declare like this your device will listen for all of those. Make sure you also check for a callback on these to know whether they are successful or not
How do I know these?
There is no official source/documentation for this. (I looked for the documentation but I didn't find any mentions regarding this) Then I tried it for myself and found it.
Honestly, I have a feeling like this question is just another version of pre-mature optimization at this time
Thank you.
This question already has an answer here:
Query for nearby locations
(1 answer)
Closed 2 years ago.
I linked firebase realtime database with my app and added login with email. I want to be able to see other users that are nearby(about 1 km). My original idea was to get my own location based on latitude and longitude and send it to firebase. Then when I log in I would scan all user's location and compare it to mine to show only those around me. It seems to me like a very bad idea to do it this way. My concerns are I would need to scan a lot of users and having all their location data in the app seems like a high security issue. I need a better way to do this. Any suggestions please?
Maybe store each person location in "chunks" that are about 2km x 2km in size.
When a client need to see other users nearby, send him the location of users in his chunk + adjacents chunks and let the client do the final math to determine if they are in the 1km radius.
To avoid security issues, limit the number of chunks a client can request per minute/hour/day.
This question already has answers here:
Programmatically obtain the phone number of the Android phone
(22 answers)
Closed 9 years ago.
I want to get mobile number of own mobile, for add this part to my application .
I'm searching about this question ,
code is correct on emulator but in device show empty.
public String getMyPhoneNumber()
{
return ((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
.getLine1Number();
}
and :
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
But is it returning empty value. So How can I fetch the phone number detail ?
The method you are using is the only one part of the SDK to do this, and only works on devices where the number is stored on the SIM card, which only some carriers do. For all other carriers, you will have to ask the user to enter the phone number manually, as the number is simply not stored anywhere on the device from where you can retrieve it.
Answer from: Programmatically obtain the phone number of the Android phone
"There is no guaranteed solution to this problem because the phone number is not physically stored on all SIM-cards, or broadcasted from the network to the phone. This is especially true in some countries which requires physical address verification, with number assignment only happening afterwards. Phone number assignment happens on the network - and can be changed without changing the SIM card or device (e.g. this is how porting is supported).
I know it is pain, but most likely the best solution is just to ask the user to enter his/her phone number once and store it."
Your code should be fine, but you need the SIM card to be inserted in the phone. Also, as autocrat noted, if the number is not stored on sim card, you will get an empty string.
EDIT: Also, please check the link provided by Pontus Backlund, there's some good info there.
Go to setting -> about device -> status -> my phone number if my phone number is unknown u won't get mobile number.. because some of the mobile network won't give mobile number..
if my mobile number has number u can get mobile through following code
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
phoneNumber = tManager.getLine1Number();
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Android: Redirect outgoing calls
The requirement is to replace newly dialed number with another one. I have captured the ACTION_NEW_OUTGOING_CALL event and used Intent.EXTRA_PHONE_NUMBER to get the current outgoing number and then I have used setResultData inside my class(which extends BroadcastReceiver) to replace the dialed number. Basically code is,
if (Intent.ACTION_NEW_OUTGOING_CALL.equals(action)) {
String phonenbr =
intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.d("OutGoingNum", "phonenbr is " + phonenbr);
if (phonenbr.startsWith("00")) {
setResultData("12345678");
}
}
My code works fine in Android emulator but on the device the code works only on Redial. It doesnt work when you dial the number via dialpad. Please help.
I am guessing that Android won't allow the interception and replacement of a dialed number. It would be far too easy for someone to abuse this.