I have an android app, I integrated a flutter module into it based on https://docs.flutter.dev/development/add-to-app/android/project-setup.
I managed to get calling flutter activity working, even sending extra data with intent and getting response data from flutter too.
What I want to do is the equivalent of calling startActivity(intent), just from my flutter module.
How could I achieve this? Is my only way is deeplinking?
I managed to make this work by using the package "android_intent_plus". From there, all I had to do was use this code:
var intent = AndroidIntent(
package: "my.custom.package",
componentName: "my.custom.package.MyAndroidActivity",
arguments: {
"DATA_KEY": "Data to send",
},
);
await intent.launch();
However, this solution is not perfect as of date, because I cannot receive result this way.
Related
I have the current workflow for my authentication
User signs in via google OAuth2
User is then given a server_auth_code which they send to my backend authentication
The auth code is validated on the back end and users is sent a JWT
I had this all working in raw Java with the Android SDK, but Flutter seemed a lot nicer. But now when using the google_sign_in plugin on android, I am unable to retrieve the serverAuthCore anymore, this plugin just wants to return null the entire time.
I Am using the client ID that's specified for Android, however, I tested the WebApplication that's auto-generated by google too but that's the same issue (Null serverAutHCode)
This is the code that I am currently using:
/// Provides the `GoogleSignIn` class
import 'package:google_sign_in/google_sign_in.dart';
class GoogleLoginPage extends StatefulWidget {
final String name = "Logging in with google.";
late GoogleSignIn _googleSignIn;
GoogleLoginPage() : super() {
_googleSignIn = GoogleSignIn(
scopes: ['https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'],
serverClientId: "XX-XXX.apps.googleusercontent.com"
);
}
Future<void> fetchAuthToken() async {
try {
var response = await _googleSignIn.signIn();
log(response?.serverAuthCode ?? "No server auth code");
_googleSignIn.signOut();
} catch (error) {
print("ERR");
print(error);
}
}
#override
State<GoogleLoginPage> createState() => GoogleLoginState();
}
The output of this code is: [log] No server auth code
The question:
Am I doing something wrong? As mentioned this works 100% on my java project using the google play services SDK so I know it's nothing to do with my google console configurations.
Okay so I figured out the issues:
It appears that by default the google login plugin for flutter comes on an older version (If I remember correctly it was 20.0.5)
I Simply changed the version to the latest version:
'com.google.android.gms:play-services-auth:20.2.0'
You can do this by editing the project's build.gradle (In IntelliJ you open build.gradle and click "Open for editing in the android studio" in the top right, from there you need to find the gradle file for google_sign_in, and change the import there, remember to click sync in the top right of android studio before you close out of it)
And I began to receive my serverAuthCode as normal, cheers!
I have added flutter to a native iOS code. I have UIButton and on pressing this button, I am presenting a FlutterViewController. I have been following this.
Here's my code for presenting the FlutterViewController:
#objc
#IBAction func openProfile() {
print("open profile")
lazy var flutterEngine = FlutterEngine(name: "patient_profile_engine")
flutterEngine.run(withEntrypoint: "", libraryURI: "");
let profileVC =
FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
present(profileVC, animated: true, completion: nil)
}
This code is working fine and the flutter view is opening and since I haven't specified and entry point yet so it using the main.dart.
The problem is that I need to pass some information to the Flutter dart code. e.g. a dictionary ["patient_id": "123456"] during the initialization.
I will have to do the same in Android native Java code as well.
Is there any easy way?
You will probably want to write a platform channel to communicate between the native code and the flutter engine.
An alternative, for this purpose, would be to use runWithEntrypoint:initialRoute: method to start the engine, encode the data into the initial route, and parse it on the flutter side.
I created an app with expo where some report in xlsx is generated in a server and then downloaded to the Download folder in Android. I want to "open" the file after it was downloaded by using another app with the open with native modal. I tried the following:
static openFile = async (asset, contentType) => {
return IntentLauncher.startActivityAsync('android.intent.action.VIEW', {
data: asset.uri,
type: contentType,
});
};
(contentType is currently receiving '*/*') but it fails everytime with the following error:
Encountered an exception while calling native method: Exception occurred while executing exported method startActivity on module ExpoIntentLauncher: file:///storage/emulated/0/Download/report-10010654-20210304061930069176.xlsx exposed beyond app through Intent.getData()
One solution is using the Sharing library, but I'm not overjoyed with it. Is there any way to make it work without ejecting from the managed flow?
I had a similar problem a month ago, I think it happens when startActivityAsync is called multiple times, my solution was to wrap my code in a try statement:
const data = await getContentUriAsync(uri)
try {
await startActivityAsync('android.intent.action.VIEW', { data, flags: 1 })
} catch (error) {}
I am using expo react native on a project and I am using the expo-notifications package within the project.
I have added "useNextNotificationsApi": true, to my app.json file
under the android object which is under the expo object so expo.android.useNextNotificationsApi : true.
I also have the experienceId set on the message I am sending to expo's server from my server, I am using the https://github.com/expo/expo-server-sdk-node package to do the sending.
messages.push({
to: red_user.fcm_token,
sound: 'default',
title: "Stylist Response",
body: "Stylist has agreed to fulfill the request",
data: {
experienceId: "#glamcentralng/GlamCentral",
order: order._id,
stylist_response: "agreed"
},
})
In my expo react native app I am using the expo-notifications package as I mentioned and I have the following setup in my class component.
import * as Notifications from 'expo-notifications';
.
.
.
.
componentDidMount() {
//Not working at all
Notifications.addNotificationReceivedListener( notification => {
console.log(notification);
this._handleNotification(notification)
});
//Working well
Notifications.addNotificationResponseReceivedListener(response => {
console.log(response);
});
this.registerForPushNotificationsAsyncNew();
}
The addNotificationReceivedListener does not receive the notification when it comes in, but I see it as a normal notification on my real Android device (I am NOT using an emulator). AS per the documentation when i click on the notification the addNotificationResponseReceivedListener should handle it and it does. So addNotificationReceivedListener does NOT work but addNotificationResponseReceivedListener works well.
One more thing to add is that I am getting a token in the function that does the registration as per the documentation.
Not sure how to fix this as I have checked other threads on here and github. Any help is appreciated.
I have an android native application with a flutter module.
I need to open an activity from java and send some arguments to flutter. Here is my code where I call my flutter "activity":
startActivity(
FlutterActivity
.withCachedEngine(flutterNameEngine)
.build(this)
);
I can do this:
..build(this).putExtra("arg_1","Hello world")
But I don't know how to receive the data on my flutter / dart code. Any idea?