I have implemented the below given code to let user share my app. It works fine, but how can I know if the user actually shared my app or not? Because my app unlocks a certain feature if the user shares the app.
[Package used:- share_plus 3.0.4 ]
onTap: () async {
const _textShareUrl =
'https://www.youtube.com/watch?v=CNUBhb_cM6E&list=PLk6qkmrzOcdx5R4-UqI_jDPYsLWNnZ1dq&index=2';
await Share.share(
'Social share test\n\n$_textShareUrl');
Future.delayed(const Duration(seconds: 10), () {
setState(() => _share = true);
});
},
There is already an open issue:
https://github.com/fluttercommunity/plus_plugins/issues/386
Related
I recently updated several lines of code in a managed expo project, unrelated to the camera functionality. It still works fine on iOS, only Android does not work. I had released a previous version one month ago that worked well. When I revert back to the old commit from then, though, it also does not work on Android (iOS fine).
expo 44.0.6
expo-camera 12.1.2
react 17.0.1
react-native 0.64.3
There is no issue launching the camera, etc. Rather, the issue occurs at takePictureAsync, which hangs and then does not return anything.
const snapPic = async () => {
const { status } = await Camera.getCameraPermissionsAsync();
if (status != 'granted') {
alert('Please grant access to camera and retry.');
await Camera.requestCameraPermissionsAsync();
return;
}
const options = { quality: 0.1 };
const photo = await this.camera.takePictureAsync(options);
this.camera.pausePreview();
this.setState({imageSource: photo.uri});
};
<Camera style={styles.cameraBox} ref={ref => {this.camera = ref}} />
Please let me know what other information I can provide, if necessary. Thanks in advance!
Instead of pause preview method. Try it with skipProcessing to false inside option object
I have a bussness app that count time, set macros and show notification and alerts.
I have a problem when app goes to background and Android stop my counting tasks.
I tried many things to keep these tasks alive, but I failed. This notification need to work offline, so FCM not a good solution.
How can I work arround it?
Obs.: When app goes to foreground, all tasks work and show all notifications... But I need to alert user just in time, not only in foreground.
I founded a solution!
Searching the site https://dontkillmyapp.com/ I saw many apps with the same problem and some solution ideas for differets brands and models.
After checking some of them, I saw that many installed apps has this config for default, so I search how can I do it programactlly.
Here the solution:
pubspec.yaml
android_power_manager: ^0.1.6
permission_handler: ^5.0.1+1
Function:
void init() async {
var status = await Permission.ignoreBatteryOptimizations.status;
print("status: $status");
if (status.isGranted) {
print(
"isIgnoring: ${(await AndroidPowerManager.isIgnoringBatteryOptimizations)}");
if (!(await AndroidPowerManager.isIgnoringBatteryOptimizations)) {
AndroidPowerManager.requestIgnoreBatteryOptimizations();
}
} else {
Map<Permission, PermissionStatus> statuses = await [
Permission.ignoreBatteryOptimizations,
].request();
print(
"permission value: ${statuses[Permission.ignoreBatteryOptimizations]}");
if (statuses[Permission.ignoreBatteryOptimizations].isGranted) {
AndroidPowerManager.requestIgnoreBatteryOptimizations();
} else {
exit(0);
}
}
}
AppWidget.dart (main)
#override
Widget build(BuildContext context) {
init();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
DataTransferService().initTimerTask();
return MaterialApp(
navigatorKey: Modular.navigatorKey,
title: APP_NAME,
theme: ThemeData(
primarySwatch: Colors.green,
),
initialRoute: '/',
routes: {
'/': (context) => LoginPage(),
'/home': (context) => HomePage(),
'/notification': (context) => NotificationPage(),
'/alerts': (context) => AlertsPage(),
},
onGenerateRoute: Modular.generateRoute,
);
}
So, the app ask permission (if needed) and, if permission is granted, ask user to set app to ignore battery optimization.
Now the notifications are working all rigt! =]
You probably want an Android service to run these tasks (foreground or background depending on your specific requirements).
It looks like there are some Flutter packages that have already been built to help with this, but I'd pay close attention to what they offer in terms of support for different Android versions.
I use flutter to save a widget as an image in flutter. I have no problem with downloading the image but im having troubke with sharing the image. Is there a way i way share the downlaoded image without leaving the application?
Here's my present code
onPressed: () async {
if (await Permission.storage.request().isGranted) {
screenshotController.capture(pixelRatio: 1.5);
screenshotController.capture().then((File image) async {
await ImageGallerySaver.saveImage(image.readAsBytesSync());
Navigator.of(context, rootNavigator: true).pop();
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text("Image Saved to Gallery"),
duration: const Duration(seconds: 1),
),
);
}).catchError((onError) {
// print(onError);
});
} else {
await Permission.storage.request();
}
}
You need to handle the image as any other file.
If you do not intend to use a server between the two users, its a bit tricky because one of them must act as one, but if you will use a server, i suggest you to follow this post:
https://dev.to/carminezacc/advanced-flutter-networking-part-1-uploading-a-file-to-a-rest-api-from-flutter-using-a-multi-part-form-data-post-request-2ekm
It's pretty recent and will help you with the app code and even with a server sample writen in nodejs. The next parts of the post teach you to do what you want.
After registering a new user with email and password using firebase flutter. Is there any way to verify his phone number without a firebase phone authentication so the same user will not be registered with email/password and phone number (I want to register him once using his email and password and verify his phone number)?
(Currently this package is outdated.It does not support Null Safety).
You can try flutter_otp package I think it's the best option,
You can visit https://pub.dev/packages/flutter_otp for more info,
try the bellow example
import 'package:flutter/material.dart';
import 'package:flutter_otp/flutter_otp.dart';
// Now instantiate FlutterOtp class in order to call sendOtp function
FlutterOtp otp = FlutterOtp();
class SendOtp extends StatelessWidget {
String phoneNumber = "93XXXXXXXX"; //enter your 10 digit number
int minNumber = 1000;
int maxNumber = 6000;
String countryCode ="+91"; // give your country code if not it will take +1 as default
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("send otp using flutter_otp ")),
body: Container(
child: Center(
child: RaisedButton(
child: Text("Send"),
onPressed: () {
// call sentOtp function and pass the parameters
otp.sendOtp(phoneNumber, 'OTP is : pass the generated otp here ',
minNumber, maxNumber, countryCode);
},
)),
),
);
}
}
I think you could try this package: https://pub.dev/packages/flutter_otp
and there are also a lot of websites that providers OTP SMS Services.
Tip: You can even use Firebase Auth since it also suits your case.
In firebase, you can just link (something like merge) the accounts that are created with Email and Phone using like this emailUser.getCurrentUser().linkWithCredential(phoneUserCredential)
In this case, your app will consist of one user with that Email and Phone.
Additional Benefit is that you don't want to store phone numbers in a separate database.
After linking both the accounts, you can just simply use user.displayName and user.phoneNumber to fetch your Email and Phone.
Refer:https://firebase.google.com/docs/auth/android/account-linking
https://firebase.google.com/docs/auth/web/account-linking
How to open other apps (Gmail, Camera) from ReactNative. How can I pass data from current scene to other app?
I found this npm library react-native-app-link which can open other apps. This is based on deep linking, if you have any deep links then this library can help. This doesn't open apps just by giving the android package name or ios app id.
https://github.com/FiberJW/react-native-app-link
you can mange opening other apps using Linking
Code sample for opening the dialer
const urlToOpen = 'tel:1234567890';
Linking.openURL(urlToOpen);
You can refer to the official doc here, it just predefines some applications, which can be opened.
However, if the question is about to open just about any application, I hope there is no solution till now.
react-native-app-link has some redundant config (e.g. appStoreLocale parameter), so I wrote my own realization using their code:
import { Alert, Platform, ToastAndroid } from 'react-native';
const isIos = Platform.OS === 'ios';
const showNotification = (text) => isIos
? Alert.alert(text)
: ToastAndroid.show(text, ToastAndroid.SHORT);
const openApp = ({ url, appStoreId, playMarketId, name }) => {
Linking.openURL(url).catch(err => {
if (err.code === 'EUNSPECIFIED') {
Linking.openURL(
isIos
? `https://apps.apple.com/app/id${appStoreId}`
: `https://play.google.com/store/apps/details?id=${playMarketId}`,
);
} else {
showNotification(`Can't open ${name} app`);
}
});
};
It tries to open the app by the specified link, and if the user doesn't have such one, it opens its page in AppStore or Play Market.