How can I get the mobile phone number of the current phone where the application is running?
For example for this plugin? It would be cool to get the mobile phone number directly.
https://github.com/flutter/plugins/pull/329
this library in dart pub seem to do what you are looking for. check the package linked below:
https://pub.dev/packages/sms_autofill
PhoneFieldHint [Android only]
final SmsAutoFill _autoFill = SmsAutoFill();
final completePhoneNumber = await _autoFill.hint;
There is no way to do this with native Android/iOS code, so also not in Flutter. For example WhatsApp just ask the user to type their number and then sends an SMS with a verification code.
Edit: It is indeed now possible to ask for a phonenumber which makes it easier for the user on Android: https://pub.dev/packages/sms_autofill
However, these are phone numbers known by Google and not necessarily the phone number that is of the phone itself. Also, the user still has to select one themselves and you can't just get the info from the device.
Important: Note that mobile_number plugin asks a very special permission to make phone calls.
sms_autofill do not ask any permissions at all.
Use it like this:
#override
void initState() {
super.initState();
Future<void>.delayed(const Duration(milliseconds: 300), _tryPasteCurrentPhone);
}
Future _tryPasteCurrentPhone() async {
if (!mounted) return;
try {
final autoFill = SmsAutoFill();
final phone = await autoFill.hint;
if (phone == null) return;
if (!mounted) return;
_textController.value = phone;
} on PlatformException catch (e) {
print('Failed to get mobile number because of: ${e.message}');
}
}
There's another package now mobile_number
Its as simple as
mobileNumber = (await MobileNumber.mobileNumber)
Note: It works for Android only, because getting the mobile number of a sim card is not supported in iOS.
Related
I had used the health package in flutter for steps and running data in android the google fit and physical activity permission are set perfectly but in iOS, it is not asking for health kit permission all other permissions are working perfectly fine here is the code which I had written for permission request
Future<void> requestActivityPermission() async {
if (Platform.isAndroid) {
final permissionStatus = await Permission.activityRecognition.request();
if (permissionStatus.isDenied || permissionStatus.isPermanentlyDenied) {
_activityPermanenetlyDeniedCase();
return;
} else {
permissionStatus.isGranted;
fetchTotalStepData();
}
} else {
final permissionStatus = await Permission.activityRecognition.request();
if (permissionStatus.isDenied || permissionStatus.isPermanentlyDenied) {
_activityPermanenetlyDeniedCase();
return;
} else {
permissionStatus.isGranted;
fetchTotalStepData();
}
}
}
The requestActivityPermission function is called in the initState Method.
The _activityPermanenetlyDeniedCase function directly opens up, in that function i had a dialog box showing open setting, but in the setting there is no healthkit permission.
I am expecting a popup permission for healthKit
You need to specify which permission you are using in Info.plist file under ios/ directory.
<key>NSHealthShareUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>
<key>NSHealthUpdateUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>
Refer here
Check that the healthkit is activated in both the debug and release tabs
I am working on a flutter application that uses Firebase Phone Number Authentication (SMS OTP). It is working perfectly on Android but having issues with the iPhone. I am testing with a real device. I am able to login with the phone number several times after installing the application. But after some time, I am not able to login with the same mobile number and it asks me to check the number correctly. The sim is on the same phone that I am testing in. The phone login is not working in a simulator or real device while debugging and hence I am having trouble figuring out this issue. Has anybody experienced such weird behaviour before? I am using flutter 1.12.13+hotfix.9 and firebase_auth 0.15.3+1 version. Any help would be appreciated. Thank you.
_verifyPhoneNumber(BuildContext context) async {
final FirebaseAuth _auth = FirebaseAuth.instance;
await _auth.verifyPhoneNumber(
phoneNumber: phoneNumber,
timeout: Duration(seconds: 0),
verificationCompleted: (authCredential) =>
_verificationComplete(authCredential, context),
verificationFailed: (authException) =>
_verificationFailed(authException, context),
codeAutoRetrievalTimeout: (verificationId) =>
_codeAutoRetrievalTimeout(verificationId),
// called when the SMS code is sent
codeSent: (verificationId, [code]) =>
_smsCodeSent(verificationId, [code])); }
_verificationComplete(AuthCredential authCredential, BuildContext context) {
FirebaseAuth.instance.signInWithCredential(authCredential);
if (!smsCodeSent) handleLogin(authCredential);}
_verificationFailed(AuthException authException, BuildContext context) {
showDialog(
context: context,
builder: (_) => AnimatedDialog(), // SHows diaglog box with check your number error message);}
_smsCodeSent(String verificationId, List<int> code) {
smsCodeSent = true;
_smsVerificationCode = verificationId;
smsOTPDialog(context) }
_codeAutoRetrievalTimeout(String verificationId) {
// set the verification code so that we can use it to log the user in
_smsVerificationCode = verificationId;}
smsOTPDialog(BuildContext context) {
Navigator.of(context).push(
_createRoute(userPhoneNumber, _smsVerificationCode, _fullname.text));}
You should get your number setup inside the phone authentication sign method as a test phone number. Firebase Auth will block your phone number from using the services when it detects that your phone number is calling the services repeatedly. They flag it then block it for almost 4hours. Phone authentication has a rate limit of around 5 calls per hour for every phone number.
Try checking that out.
I am developing a PWA that requires Push-Notifications. Sadly IOS/Safari does not support https://w3c.github.io/push-api/#pushmanager-interface for now, so I think i might have to wrap a native APP around in some way.
In Android (before their "Trusted Web Activities" was a thing) you could use a WebView to basically display a headless Chrome-View in your App. Whats the equivalent in IOS and how does the interaction between push-notifications and the Webapp (the browser need to jump to a specific page) work?
One more thing I need is integration with our companys Mobile Device Management, which is Microsoft Intune. Having integrated MDMs in Android in the past i Know that this might be a major pain in the a**, so i'm considering to build the wrapper myself, for maximum flexibility. Another option would be something like Ionic, not sure now.
This may not necessarily work in your situation, but I had the exact same issue with a PWA for Safari and I solved it by just using long polling. It will allow you to get around all of the limitations with Safari and I was able to redirect and load sections within our SPA.
async function subscribe() {
let response = await fetch("/subscribe");
if (response.status == 502) {
// Status 502 is a connection timeout error,
// may happen when the connection was pending for too long,
// and the remote server or a proxy closed it
// let's reconnect
await subscribe();
} else if (response.status != 200) {
// An error - let's show it
showMessage(response.statusText);
// Reconnect in one second
await new Promise(resolve => setTimeout(resolve, 1000));
await subscribe();
} else {
// Get and show the message
let message = await response.text();
showMessage(message);
// Call subscribe() again to get the next message
await subscribe();
}
}
subscribe();
https://javascript.info/long-polling
I would like to know how many people are currently connected to a room when using Twilio Video.
Twilio has a REST API to get a room resource, but it does not return current number of participants.
https://www.twilio.com/docs/api/video/rooms-resource#get-by-sid
Only way i see is to subscribe to status callback to "participant connected" and disconnected events and manually keep track of how many participants are connected or left the room.
Is there a better way to do this ?
You can use twilio server side sdk, Let me share NodeJS example so you get better idea on implementation.
First lets define function that init twilio client and fetch connected participants of room.
async function getConnectedParticipants(roomName) {
var Twilio = require('twilio');
var apiKeySid = "YOUR_TWILIO_API_KEY_SID_HERE";
var apiKeySecret = "YOUR_TWILIO_API_SECRET_HERE";
var accountSid = "YOUR_TWILIO_ACCOUNT_SID_HERE";
var client = new Twilio(apiKeySid, apiKeySecret, {accountSid: accountSid});
var list = await client.video.rooms(roomName)
.participants
.list({status: 'connected'});
return list;
}
Now let's use our function that return you connected participants.
var connectedParticipants = await getConnectedParticipants("YourRoomName");
// print all connected participants
console.log('connectedParticipants', connectedParticipants);
Note: I have used async and await in this example, please check more on that before implementation.
Twilio developer evangelist here.
Keeping a server side list of the participants' identities based on the participant connected and disconnected events is probably the best way to work this out right now.
One alternative is to get this information from the front end. The JavaScript library allows you to query the participants in a room. You could periodically, or based on events, query that property and send it to your server via Ajax too.
Let me know if that helps.
Update
The Rooms API now allows you to retrieve information on participants that have connected to a room. To get the currently connected users in a room using Node.js, for example, the code would look like:
var client = new Twilio(apiKeySid, apiKeySecret, {accountSid: accountSid});
client.video.rooms(roomSid).participants
.list({status: 'connected'}, (err, participants) => {
if (err) { console.error(err); return; }
console.log(participants.length);
});
In one of my application i need to share link via sms. I am using blackberry OS 5.0. Here is code for sharing message via SMS.
MessageConnection mc = null;
try {
mc = (MessageConnection) Connector.open("sms://");
} catch (IOException e) {
e.printStackTrace();
}
TextMessage textMessage = (TextMessage) mc.newMessage(MessageConnection.TEXT_MESSAGE);
textMessage.setAddress("sms://");
System.out.println("======1====");
textMessage.setPayloadText("afasdfadsfsdaf");
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,
new MessageArguments(textMessage));
In case of 9810 it shows message box with text. Following is image.
I am using same code for 8520. But image is as follows:-
Please help me out whether it is feasible, if not please share me any specific link for this feature is not feasible.
Thanks