How to open add contact page on android platform in flutter? - android

I'm making an app using flutter that uses the contacts(using contact_services plugin) from user's phone. Thus it needs as well to give the ability to add a new contact using the system default add contact page. However there isn't such functionality in contacts_services. What is the way using plugin or existing contact_services plugin to open the add new contact page?
void openAddContacts() async{
if (Platform.isAndroid) {
final AndroidIntent intent = AndroidIntent(
action: 'ContactsContract.Intents.Insert.ACTION',
category: 'ContactsContract.RawContacts.CONTENT_TYPE',
);
await intent.launch();
}
}

This may help you : https://github.com/differenz-system/Addressbook.Flutter
Or if you xant to dive deeper and want to understand the mechanism under the hood, I suggestion you to use Platform Channel to communicate with native codes. Here is an example proposed by Google for address-book : https://developers.google.com/protocol-buffers/docs/darttutorial

if you use this plugin https://pub.dev/packages/contacts_service you can look full working example here https://github.com/lukasgit/flutter_contacts/blob/master/example/lib/main.dart
Add permissions
Android #
Add the following permissions to your AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
iOS #
Set the NSContactsUsageDescription in your Info.plist file
<key>NSContactsUsageDescription</key>
<string>This app requires contacts access to function properly.</string>
And after you can use code from the example by link above.

Related

Expo Media Library permissions error on Android [React Native]

Hi I'm working on a react native app and I'm using expo-media-library to get user's photos but, only on android, when I try to ask for permissions using the following command I get the status as never_ask_again even if it's the first time I'm asking for permissions and I don't event refuse them because the popup didn't show up.
MediaLibrary.requestPermissionsAsync()
Then I tried to manually give permissions to the app, through settings, but when expo try to access to media library, here's the error that occurs.
Error: Missing MEDIA_LIBRARY permissions.
I also tried to use react-native-permissions to ask for permissions, but the result is the same.
Maybe someone has had this problem before and can help me, thanks.
=> Do you add this in your manifest file or not..?
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
const permission = await Permissions.getAsync(Permissions.CAMERA_ROLL);
if (permission.status !== 'granted') {
const newPermission = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (newPermission.status === 'granted') {
//its granted.
}
} else {
....your code
}

How do i add permissions to AndroidManifest via expo plugins?

My expo react native application comunicates with a zebra printer via a HTTP post request this works just fine in web , however on android and I suspect also iOS this isnt the case, from what i gather i need to add something along the lines of :
<uses-permission android:name="android.permission.INTERNET" />
Into androidmanifest.xml however expo doesnt give you direct access to that file , so i need to make a expo plugin that puts the permission into androidmanifest via expo.
I found this post teaching how to remove permissions however my current case requires me to add permissions ill still link the code from the post down here:
const { withAndroidManifest } = require("#expo/config-plugins")
module.exports = function androiManifestPlugin(config) {
return withAndroidManifest(config, async config => {
let androidManifest = config.modResults.manifest
// add the tools to apply permission remove
androidManifest.$ = {
...androidManifest.$,
"xmlns:tools": "http://schemas.android.com/tools",
}
// add remove property to the audio record permission
androidManifest["uses-permission"] = androidManifest["uses-permission"].map(
perm => {
if (perm.$["android:name"] === "android.permission.RECORD_AUDIO") {
perm.$["tools:node"] = "remove"
}
return perm
}
)
return config
})
}
Does anyone know how to add http permissions to my expo app? Thanks.
To add permissions you do not need expo-plugins.
You simply need to add the permission in your app.json (or app.config.js if you have dynamic configuration)
On Android, permissions are little bit simpler than iOS. In the managed workflow, permissions are controlled via the android.permissions property in your app.json file.
https://docs.expo.dev/guides/permissions/

Firebase dynamic link not working as expected with custom domain

I have example.com custom domain and i want to let invite members to groups inside the app with dynamic links.
I want to use app.example.com/ as prefix.
All libraries installed, team id on firebase for ios is defined and imported with new google services plist.
So my url i prepared to my desire is this (building this as shortlink app.example.com/SOMERANDOMTHING)
https://app.example.com/?link=https://example.com/joingroup?groupid=SOMEGROUPID&apn=com.myorganization.myapp&amv=4&ibi=com.myorganization.myapp&isi=TEAMID&imv=4&ius=myapp
on iOS:
added to info.plist:
<key>FirebaseDynamicLinksCustomDomains</key>
<array>
<string>https://app.example.com</string>
</array>
Also added applinks:app.example.com to associated domains
And to URL Schemes, added com.myorganization.myapp
And my code on component did mount:
componentDidMount() {
var that = this
dynamicLinks().onLink((link) => {
that.handleDynamicLink(link)
})
if(Platform.OS == 'android') {
dynamicLinks().getInitialLink().then((link2) => {
if(link2) {
that.handleDynamicLink(link2)
}
Problems
on Android
When click link re-opening app from start and it calls
getInitialLink, onLink not working (Thats why i selected platform
for getinitiallink because on ios both functions working) .
Also when click link; no option like 'Open with MyApp' so link is
not associated with MyApp, after clicking browser decides link to be
opened with MyApp. (OK, it works but not cool)
If I add this to AndroidManifest:
<data android:host="app.example.com" android:scheme="http"/>
<data android:host="app.example.com" android:scheme="https"/>
this time link opening with my app and android recognizes link
belongs to MyApp but neither getInitialLink nor onLink works.
on iOS
onLink works, but its not transferring result to the app; its just transferring all link
https://app.example.com/?link=https://example.com/joingroup?groupid=SOMEGROUPID&apn=com.myorganization.myapp&amv=4&ibi=com.myorganization.myapp&isi=TEAMID&imv=4&ius=myapp
instead of
https://example.com/joingroup?groupid=SOMEGROUPID
So im stuck on these problems, thanks for your assist
This is possible if you use a link as a parameter of another link. I suggest replacing this with the following
https://app.example.com/?link=https%3A%2F%2Fexample.com%2Fjoingroup%3Fgroupid%3DSOMEGROUPID&apn=com.myorganization.myapp&amv=4&ibi=com.myorganization.myapp&isi=TEAMID&imv=4&ius=myapp
If you use JavaScript to create a link manually, you can use encodeURIComponent
const link = encodeURIComponent('https://example.com/joingroup?groupid=SOMEGROUPID');
const url = `https://app.example.com/?link=${link}&apn=com.myorganization.myapp&amv=4&ibi=com.myorganization.myapp&isi=TEAMID&imv=4&ius=myapp`;
console.log(url)

Get email account into textfield using cordova

Can anyone please show me how to get an email registered to a phone into my cordova application? In my application, there is a registration page which users must register with their emails and instead of them typing it in, I want to use cordova to get the current email on the phone into the textfield of the registration page named "email" and also if possible get the firstname and lastname the user used in registring his email on his phone into a textfield
so you can use the following plugin
[User-Info-Plugin][1]
The way to add would be to use the following command
cordova plugins add https://github.com/xarv/UserInfo-Cordova-Plugin.git
after the adding check your config.xml for proper entries.
Usage:
var success = function(string){
alert(string);
};
var error = function(string){
alert("error");
};
getInfo("email",success,error,"email",[]);`
The getInfo method is the one you should use with action as "email". this should be done after cordova has been loaded i.e. inside onDeviceReady after deviceready has been fired. document.addEventListener('deviceready', onDeviceReady, false);
Also in your manifest you would have to add
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
as a permission.
Hope this helps.

Qt under Android QNetworkReply returns HostNotFoundError

my goal is to run a php script and to GET the values returned. I work under Neccesitas SDK (Qt for Android) To do this I do:
m_NetworkAccessMNGR = new QNetworkAccessManager(this);
QEventLoop loop;
QNetworkReply* m_reply = m_NetworkAccessMNGR->get(QNetworkRequest(url));
connect(m_reply, SIGNAL(finished()),
this, SLOT(slothttpFinished()));
connect(m_reply, SIGNAL(readyRead()),
this, SLOT(slothttpReadyRead()));
connect(m_reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
ONLY on Android I get in this::slothttpReadyRead
m_reply->error() is QNetworkReply::HostNotFoundError
and m_reply->errorString() outputs:
ERROR: Host www.google.com not found
On Windows this works perfectly.
Should I do some adaptations to Android? Maybe AndroidManifest.xml needs some setup made?My AndroidManifest.xml contains, among others :
uses-permission android:name="android.permission.INTERNET"/>
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Thank you

Categories

Resources