"Firebase App named '[DEFAULT]' already exists." - android

So I was trying to use Firebase in an Android service which is in a seperate process and this error came up while doing:
FirebaseDatabase.getInstance()....
or
FirebaseAuth.getInstance()....
I wrote this check snippet to overcome the problem:
boolean hasBeenInitialized=false;
List<FirebaseApp> firebaseApps = FirebaseApp.getApps(this);
for(FirebaseApp app : firebaseApps){
if(app.getName().equals("[DEFAULT]")){
hasBeenInitialized=true;
}
}
if(!hasBeenInitialized) {
FirebaseApp.initializeApp(this, FirebaseOptions.fromResource(this));
}
// Only then getInstance() will work
And IT WORKS pretty good BUT I'm not sure this is the right way to do it (it's the hardcoded [DEFAULT] that bothers me...).
Does anyone knows a proper way to do this ?

You can compare to FirebaseApp.DEFAULT_APP_NAME instead. See the reference docs.

Related

firebase.messaging().getInitialNotification() does not work on android(when app is killed)

So, I have migrated Firebase on my project from v#5 to v#14 because push-notifications did not work on android API31+(v12) at all.
NOTE: we use react-native-splash-screen. Folk pointed out on some problems react-native-firebase/issues/4005 and react-native-firebase/issues/2768 and react-native-splash-screen/issues/289 and suggested to move from older splash approach to react-native-bootsplash as an alternatiove, which was not really the solution for us.
PS. any comments inside links above did not help
firebase.messaging().onNotificationOpenedApp - Unlike initial pushes, in background mode push service was performing well as expected.
My problem was resolved by using API from 3d-party library such react-native-push-notification instead of firebase.messaging().getInitialNotification().
const getAndroidInitialNotification = (remoteMessage: ReceivedNotification | null): void => {
const data = remoteMessage?.data;
if (data) {
// Your code such deep links implementation, dispatch to reducer etc...
}
};
PushService.popInitialNotification(handleInitialNotifications);
Hope this will help for somebody like me, who do not understand what is the affection of splash approach on firebase service and all related confusing stuff.

Kotlin-android: Unresolved reference

I have received this project from the previous developer, and he said everything is working fine on his end. But on my end, when I try to sync the project I get a lot of errors, and I don't know where to even start. One of them is this:
Here's that code:
private fun setupScrollDirection() {
val allowHorizontalScroll = config.scrollHorizontally && config.viewTypeFolders == VIEW_TYPE_GRID
excluded_vertical_fastscroller.isHorizontal = false
excluded_vertical_fastscroller.beGoneIf(allowHorizontalScroll)
excluded_vertical_fastscroller.allowBubbleDisplay = config.showInfoBubble
excluded_vertical_fastscroller.setViews(manage_folders_list) {
excluded_vertical_fastscroller.updateBubbleText(getBubbleTextItem(it))
}
}
I have a lot more errors of the same type, like this one for example:
Please have a call with the other developer and ask him/her to share his screen on call.
When the screen is being shared, ask the developer to Ctrl+ Click on beGoneIf variable/function and then check where the beGoneIf is defined in the project. This way you can check whether the required library/dependencies used by other developer is present in your local project or not.

How to trigger / debug backdoor functionality in Xamarin.Forms.UITesting?

I'm trying to add a BackdoorMethod to a Xamarin.Forms application to bypass the login (IDP - opened in chrome browser) step. I have the feeling that the method is not getting triggered, but not sure, and I don't know how could I make sure about it.
I've read the documentation here: https://learn.microsoft.com/en-us/appcenter/test-cloud/uitest/working-with-backdoors
Check this thread: https://forums.xamarin.com/discussion/85821/xamarin-uitest-backdoor-on-droid-with-splash-screen-how-do-i-access-my-mainactivity
Checked this example: https://github.com/brminnick/UITestSampleApp/tree/master/Src
In the MainActivity.cs file I've defined the BackdoorMethod:
[Preserve, Export(nameof(BypassLoginScreen))]
public string BypassLoginScreen()
{
// some additional code here. the code is working, when I called it
// directly from OnCreate it was executed without any error
return "called";
}
From the test case i'm trying to invoke it like:
public constructorMethod(Platform platform)
{
this.platform = platform;
app = AppInitializer.StartApp(platform);
var result = app.Invoke("BypassLoginScreen"); // result == "<VOID>"
}
I'm not getting any error message, the method simply not called, or not returns anything. (or i don't know what's happening there with it, because breakpoint also not working as the app started from the device)
This should be already working. I have similar code and it works for me.
you can add inside your function
Android.Util.Log.WriteLine(Android.Util.LogPriority.Info, "BypassLoginScreen", $"Some text as info");
And observe the result in Device Logs, Filter by BypassLoginScreen to see if there is any log created with the tag BypassLoginScreen

Parse for Android : ParseUser.logOut() doesn't log user out

I've been playing around with Parse on Android for a few days, I have a problem with ParseUser.logOut() => it actually doesn't log the current user out.
Here's what I do :
private void onClickOnDisconnect() {
ParseUser.logOut();
currentUser = ParseUser.getCurrentUser(); // should be null but isn't...
invalidateOptionsMenu();
Toast.makeText(getApplicationContext(), "Disconnected...", Toast.LENGTH_LONG).show();
}
After the call to ParseUser.logOut(), ParseUser.getCurrentUser() should return null (says the documentation). Still it returns the previously logged in user.
Even though I restart the app the user is still considered as connected.
I use parse framework v1.3.8 (downloaded a 3 days ago). I don't use Facebook SDK, as I've seen a few questions for that specific case.
Thanks in advance
Somewhere in your app, probably the appDelegate you most likely send this message to the PFUserClass
[PFUser enableAutomaticUser];
in this case the
[PFUser currentUser];
will never return nil;
I had the same issue while incorporating logout functionality with facebook login. The error turned out to quite simple and a basic mistake on my part. I had written the following piece of code in my Application class
ParseUser.enableAutomaticUser();
This creates the user every time you run your application even if you have logged out the last time around. Removing this solved my problem.
As I said in the comments above, I got it to work by :
uninstalling the app
deleting the user on the Parse dashboard
reinstalling the app and signing up again
Then the signout/signin mechanism worked miraculously :|
The only reason I can imagine is that I had previously signed up with this user having Automatic user creation enabled, and it somehow stuck to the user entity in Parse.
Experiencing same bug. Now instead of only checking ParseUser as null, I check username too:
ParseUser currentUser=ParseUser.getCurrentUser()
if(currentUser==null)
{
//user doesn't exist
}
else
{
if(currentUser.getUserName()==null)
{
//user oesn't exist
}
}
Try
ParseUser.getCurrentUser().logOut();
I had the same problem. Actually it was a bug in parse sdk and the problem was solved without changing any of my code, just by installing the latest parse android sdk(1.8.1 at the time of writing).
I had the same issue it was because i has automatic user enabled which causes a new anonymous user to be created, it is also explained here
https://www.parse.com/questions/issues-with-parseuserlogout-on-android
Try to logout the current user object, not the class.
ParseUser.getCurrentUser().logout();
and make sure to delete
ParseUser.enableAutomaticUser();
Edit:
When you logout, the User instance will still available, but with null fields. Parse changes all the user's fields into nulls.
So, if you want to check whether the user is logged in or out, just do the following
if(ParseUser.getCurrentUser().getUsername() == null)
{ // user is out
} else {
// user is in }

make getSystemService() recognize our new system service

I'm using the book "Embedded Android".
I'm making a new System Service using AOSP(4.0.3_r1).
I want my system service to be registered in frameworks/base/core/java/android/content/app/ContextImpl.java so that I can use it through getSystemService() method.
The problem is, I can't find the app folder under content:androidroot/frameworks/base/core/java/android/content/app/ContextImpl.java
But, I found it in:androidroot/frameworks/base/core/java/android/app/ContextImpl.java
Are these 2 files the same? or is it just missing(the content/app folder)?
Any idea on what to do?
Karim wrote his book mostly orienting on Android 2.3.4 version. Something can be changed from this time. This is an example what has been changed.
Are these 2 files the same? or is it just missing(the content/app folder)?
These are the same files.
Any idea on what to do?
As I said the implementation has been changed. I looked into the code and here what you can change to make your code working (I can only suppose because I did not actually build my code). In the static block of ContextImpl class you need to add the following code:
registerService(ACCOUNT_SERVICE, new ServiceFetcher() {
public Object createService(ContextImpl ctx) {
IBinder b = ServiceManager.getService(OPERSYS_SERVICE);
IOpersysService service = IOpersysService.Stub.asInterface(b);
return new OpersysManager(service);
}});
You need to use SystemServer which holds all system services' names.
You should check this link out:
http://processors.wiki.ti.com/index.php/Android-Adding_SystemService

Categories

Resources