Location Opt-In Prompt - flutter

void _handleSetLocationShared() {
print("Paylaşılan konumu true olarak ayarlama");
OneSignal.shared.setLocationShared(true);
}
TableRow(children: [
OneSignalButton("Paylaşılan Konumu Ayarla",
_handleSetLocationShared, !_enableConsentButton)
])
My OneSignal Inapp message image
*
I Get Error In Apply The Error I Get: "Location Unavailable It seems there are no location services configured in this app. Please refer to the OneSignal documentation for more information.*
Picture of the Error I Get

Add the following code to debug/AndroidManifest.xml and profile/AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Add the following code to the main.dart file
OneSignal.shared.addTrigger("location_prompt", "true");
and then set the image from OneSignal
OneSignal image

Related

path of the saved recorded voice by flutter record package

I want to record audio by clicking a button in my flutter application. I use the record flutter package.
What should I use for the below path? Is where my voice is saved? I tested some directories like temp directory plus the name of the desired file but got error.
// Import package
import 'package:record/record.dart';
Record record = Record();
// Check and request permission
if (await record.hasPermission()) {
// Start recording
await record.start(
path: ???,
encoder: AudioEncoder.aacLc, // by default
bitRate: 128000, // by default
sampleRate: 44100, // by default
);
}
I also added permissions in the manifest:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Location Permission Status - always getting as denied in Flutter

I have created below method to check the location permission status in my flutter application:
Future<void> checkLocationPermission(
BuildContext context, UserCredential userCredential) async {
locationPermissionStatus = await permission_status.Permission.location
.request()
.then((value) async {
if (locationPermissionStatus.isGranted) {
displayToast("granted");
await getCurrentLocation(context, userCredential);
} else {
displayToast("not granted");
}
return locationPermissionStatus;
});
}
Where, PermissionStatus is declared as below:
permission_status.PermissionStatus locationPermissionStatus =
permission_status.PermissionStatus.denied;
Imports as below:
import 'package:location/location.dart';
import 'package:permission_handler/permission_handler.dart' as permission_status;
Used below plugins:
permission_handler: ^10.2.0
location: ^4.4.0
But In App, When Location Permission pops up, I am tapping on option "While Using the App"
But I am always getting the toast display as "not granted"
What might be the issue? Thanks in Advance.
EDIT:
Already added below permissions for Android:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
</manifest>
Adding to the #Romil Mavani answer, you first have to add permissions in AndroidManifest:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
But it also seems that you are using async/await with the combination of then which is very error-prone. You should either use one or the other.
Future<void> checkLocationPermission(
BuildContext context, UserCredential userCredential) async {
locationPermissionStatus =
await permission_status.Permission.location.request();
if (locationPermissionStatus.isGranted) {
displayToast("granted");
await getCurrentLocation(context, userCredential);
} else {
displayToast("not granted");
}
}
You have to add permission in manifest.
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Like this : https://i.stack.imgur.com/PgdNF.png
Also permission status is not working correctly for only location permission so you have check and request permission using location package and it will works fine.
I Hope this things are solve your issue.
If you're using a Windows Emulator
I've faced the same issue before, but when I opened the application setting of my mobile's emulator to confirm, the location permission was not granted (off).
So, I granted it manually from the app settings.
Emulator: Setting/apps/allApps/myApp/permisson
This solution works for me.

How can Flutter get the SSID of WIFI in Android 12 or 13?

I use network_info_plus plug -in to obtain WIFI information. The models of the 12th -pm can be obtained. The SSID obtained by the 12 and above models is NULL. Please help me tell me how to solve this problem.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Future<void> setNetwork() async {
final info = NetworkInfo();
var locationStatus = await Permission.location.status;
if (locationStatus.isDenied) {
await Permission.locationWhenInUse.request();
}
if (await Permission.location.isRestricted) {
openAppSettings();
}
if (await Permission.location.isGranted) {
var wifiName = await info.getWifiName();
log('wifiName $wifiName');
}
}
What method needs to be implemented
You can use the network_info_plus package to get all the network info wi-fi-related information.
just install it with
flutter pub add network_info_plus
And use below code snippet to get SSID 👍
var wifiBSSID = await info.getWifiBSSID(); // 11:22:33:44:55:66

How can I dial the phone from Flutter?

I am building a Flutter app, and I'd like to dial a phone number in response to a button tap. What's the best way to do this?
Thanks!
This method will open the dialer :
_launchCaller() async {
const url = "tel:1234567";
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
EDIT:
In case anybody facing errors:
Add url_launcher: in the pubspec.yaml & run flutter get
Also import 'package:url_launcher/url_launcher.dart';
Typically, to interact with the underlying platform, you have to write platform specific code and communicate with the same using platform channels. However, Flutter provides some points of integration with the platform out of the box. To dial the phone for instance, you can use the UrlLauncher.launch API with the tel scheme to dial the phone.
Something like UrlLauncher.launch("tel://<phone_number>"); should work fine on all platforms.
Do note that this will not work in the simulators. So make sure you are using an actual device to test this.
You can use the url_launcher widget (https://pub.dev/packages/url_launcher)
Add this to your package's pubspec.yaml file: dependencies: url_launcher: ^5.7.10
Install it: $ flutter pub get
Import it import 'package:url_launcher/url_launcher.dart';
Inside your class, define this method so you can call from any action in your code:
Future<void> _makePhoneCall(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
inside the build widget:
IconButton(icon: new Icon(Icons.phone),
onPressed: ()
{
setState(() {
_makePhoneCall('tel:0597924917');
});
},
),
Note 1: you should write the phone number with prefix 'tel': 'tel:0123456789'
Note 2: sometimes it will not work well until you close the app in your mobile and reopen it, so flutter can inject the code of the new widget successfully.
Its too easy
import 'package:flutter/material.dart';
import 'package:flutter_phone_direct_caller/flutter_phone_direct_caller.dart';
void main() {
runApp(Scaffold(
body: Center(
child: RaisedButton(
onPressed: _callNumber,
child: Text('Call Number'),
),
),
));
}
_callNumber() async{
const number = '08592119XXXX'; //set the number here
bool res = await FlutterPhoneDirectCaller.callNumber(number);
}
URL launcher has updated their dependency so here is the updated way to do the job. it will work for android ios
final Uri launchUri = Uri(
scheme: 'tel',
path: number,
);
await launchUrl(launchUri);
Who has not used this plugin just imoprt this plugin.
UrlLauncher
Use url_launcher.
import 'package:url_launcher/url_launcher.dart';
openDialPad(String phoneNumber) async {
Uri url = Uri(scheme: "tel", path: phoneNumber);
if (await canLaunchUrl(url)) {
await launchUrl(url);
} else {
print("Can't open dial pad.");
}
}
Note: Don't forgot to update info.plist and AndroidManifest.xml as per the documentation.
Follow the below steps:
add the url_launcher: Latest version dependency in your pubspec.yaml
Go to \android\app\src\main\AndroidManifest.xml.
add the queries lines before the <application, like this :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flutter">
<queries>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
</queries>
<application ...
For more queries, follow this more queries
4.Add the dialer function, and set the url, final url ="tel:$phoneNumber"; like this:
Future<void> dialNumber(
{required String phoneNumber, required BuildContext context}) async {
final url = "tel:$phoneNumber";
if (await canLaunch(url)) {
await launch(url);
} else {
ShowSnackBar.showSnackBar(context, "Unable to call $phoneNumber");
}
return;
}
Done
This is what worked for me as of January 2023
NB: The major difference from the other answers above is my #4
ALSO: You can now use test this in Emulator
Steps:
1.Add url_launcher: latest to pubspec.yaml
2.Configuration:
For IOS: Add tel scheme passed to canLaunchUrl as LSApplicationQueriesSchemes entries in your Info.plist file.
Like this:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
</array>
For Android: Add tel scheme passed to canLaunchUrl as queries entries in your AndroidManifest.xml [ie \android\app\src\main\AndroidManifest.xml] file.
Just like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flutApp">
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="tel" />
</intent>
</queries>
<application
3.Import url_launcher to your file: ie import 'package:url_launcher/url_launcher.dart';
4.Code
Future<void> _dialNumber(String phoneNumber) async {
final Uri launchUri = Uri(
scheme: 'tel',
path: phoneNumber,
);
await launchUrl(launchUri);
}
Source: url_launcher

Ionic app doesn't ask permission to access location while installing

I've followed the following steps to create an app:
ionic start ionic-maps blank
cd ionic-maps
ionic setup sass
ionic io init
ionic platform add android
bower install ngCordova
Added the following lines to index.html:
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
Changed app.js to include ngCordova:
angular.module('starter', ['ionic', 'starter.controllers', 'ngCordova'])
Installed the geolocation plugin:
cordova plugin add cordova-plugin-geolocation
app.js:
.state('app.location', {
url: '/location',
views: {
'menuContent': {
templateUrl: 'templates/location.html',
controller: 'LocationCtrl'
}
}
})
location.html:
<ion-view view-title="Search">
<ion-content>
<h1>Location: {{location}}</h1>
</ion-content>
</ion-view>
controllers.js:
.controller('LocationCtrl', function($scope, $state, $cordovaGeolocation) {
$scope.location = 'Waiting';
var options = {timeout: 10000, enableHighAccuracy: true};
$cordovaGeolocation.getCurrentPosition(options).then(function(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
console.log(lat, lng);
$scope.location = lat + ' ' + lng;
}, function(error) {
console.log('Could not get location: ', error);
$scope.location = 'Could not get location: ' + error + ' :: ' + JSON.stringify(error);
});
})
If I open the /location endpoint in my phone's browser (using ionic serve) I'm shown my current location correctly. So far everything works as expected.
/platforms/android/AndroidManifest.xml has the following lines in it:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
I'm building the app using the new cloud package builder using ionic package build android. ionic package list shows that the build was successful.
I expected that I'll be asked for location permission while installing the app from apk. But I'm only asked for full network access. On visiting the /locations screen I get an error [object PositionError. json.stringify(error) is {} and Object.keys(error).length is 0.
Using navigator.geolocation.getCurrentPosition instead of $cordovaGeolocation.getCurrentPosition doesn't help.
alert(error.code) is 2 and alert(error.message) is application does not have sufficient geolocation permisions.
PS: I've ensured that GPS is enabled and it works on other apps.
Run cordova plugin add cordova-plugin-geolocation with --save option i.e. cordova plugin add cordova-plugin-geolocation --save so that the plugin gets added to config.xml.
Alt: adding "cordova-plugin-geolocation" to "cordovaPlugins" in package.json also solves the issue but has been deprecated.