Cannot accomplish to add a xamarin.froms.android app to firebase - xamarin.forms

I don't know what to do anymore, I am trying to connect my Xamarin.Forms App to Firebase.
I cannot find any suitable tutorials. I have downloaded the Google-Service.json and added it to my Android root Directory, I also set the build Option for the file on GoogleServicesJson. I made sure the file has the Name from my packagename & I also added the Android App on firebase and installed the Nugget Package xamarin.firebase.Auth.
When I start the App, Firebase tells me that the app doesn't communicate with the firebase Server. Any suggestions where the Problem could be?
That's the changes in Code:
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
FirebaseApp.InitializeApp(Application.Context);
LoadApplication(new App());
}
FirebaseApp.InitializeApp(Application.Context); was added by me.

Related

Xamarin Forms, Android 11+, Access music folder in root

Hi i searched and searched.
How do i access the music folder in android? Not the music folder of the app.
Android.OS is not available.
I even tried System.IO.Directory.GetFiles("/"); no permissions.
I checked every permission in the manifest that states storage or read.
I need the filepath to each audio file to be able to play it. I don't need a file dialog where the user chooses a file.
I need a string[] of all audio files in the root music dir not the app dir.
There has to be a way, cause audio players exist that access my root music folder.
NOT sdCard Storage
May be you can try to grant your app the permission about accessing all the files.
At first, add the permission into the AndroidManifest.xml:
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
And then add the following code into the OnCreate method of the main activity to request the permission.
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
if (!Android.OS.Environment.IsExternalStorageManager)
{
Intent intent = new Intent();
intent.SetAction(Android.Provider.Settings.ActionManageAppAllFilesAccessPermission);
Android.Net.Uri uri = Android.Net.Uri.FromParts("package", this.PackageName, null);
intent.SetData(uri);
StartActivity(intent);
}
}

Java.Lang.NullPointerException: Attempt to invoke virtual method 'void com.google.firebase.auth.FirebaseAuth.zza

I'm trying to implement Authenticate with Firebase on Android using a Phone Number by following the Google official documentation on Xamarin Android. But I am getting this error:
Java.Lang.NullPointerException: 'Attempt to invoke virtual method 'void com.google.firebase.auth.FirebaseAuth.zza(java.lang.String, long, java.util.concurrent.TimeUnit, com.google.firebase.auth.PhoneAuthProvider$OnVerificationStateChangedCallbacks, android.app.Activity, java.util.concurrent.Executor, boolean)' on a null object reference'
I created an Android studio project And I got no error sending sms. I was supposed to publish the app yesterday but I'm stuck here.
Note: I have already a reference to Xamarin.GooglePlayServices.Base, Xamarin.Firebase.Auth:71.1605.0 and I have a code with push notification FCM which is working fine.
Here is my MainActivity.OnCreate code:
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
Xamarin.FormsMaps.Init(this, savedInstanceState);
FirebaseApp firebaseApp = FirebaseApp.InitializeApp(this);
var firebaseAuthInstance = FirebaseAuth.GetInstance(firebaseApp);
if(firebaseAuthInstance == null)
{
firebaseAuthInstance = new FirebaseAuth(firebaseApp);
}
verificationStateChangedCallbacks = new VerificationStateChangedCallbacks(); //This class is below.
PhoneAuthProvider.Instance.VerifyPhoneNumber("+16505559999", 60, TimeUnit.Seconds, this //The activity, verificationStateChangedCallbacks); // I got the error here
Class VerificationStateChangedCallbacks:
public class VerificationStateChangedCallbacks : OnVerificationStateChangedCallbacks
{
public override void OnVerificationCompleted(PhoneAuthCredential p0)
{
}
public override void OnVerificationFailed(FirebaseException p0)
{
}
public override void OnCodeSent(string p0, ForceResendingToken p1)
{
base.OnCodeSent(p0, p1);
}
}
I just fixed it by changing
PhoneAuthProvider.Instance.VerifyPhoneNumber("+16505559999", 60, TimeUnit.Seconds, this, verificationStateChangedCallbacks);
to
PhoneAuthProvider.GetInstance(firebaseAuthInstance).VerifyPhoneNumber("+16505559999", 60, TimeUnit.Seconds, this, verificationStateChangedCallbacks);
2 days and I didn't think about changing it.
can you check whether "PhoneAuthProvider.Instance" a null object. If yes then please check your file "google-services.json". Normally "FirebaseAuth.GetInstance(firebaseApp)" will not return a null.

Background Service in Xamarin.Forms, iOS, Android

I have a background service in android.
My code is as follows:
[Service]
public class PeriodicService : Service
{
public override IBinder OnBind(Intent intent)
{
return null;
}
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
Device.StartTimer(TimeSpan.FromSeconds(5), () =>
{
// code
});
return StartCommandResult.Sticky;
}
}
The MainActivity class:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
StartService(new Intent(this, typeof(PeriodicService)));
}
Permission AndroidManifest.xml:
<uses-permission android:name="android.permission.PeriodicService" />
The problem is that my service only works in the background when the app is active or in the foreground but when I close the app it doesn't run in the background.
A possible solution is to follow along with what Fabio has written in his post about how to create The Never Ending Background Task.
The idea behind this is to create a BroadcastReceiver and Android Service in the manifest. The BroadcastReceiver will then activate the service with foreground priority as the application is being closed. If you are dealing with post Android 7 then he created an update to his blog showing The Fix.
Just to get a better understanding of how basic Android services operate, I'd recommend taking a look at this Android Services Tutorial
I also saw this other StackOverflow post that seems to be pretty similar so maybe there will be some useful info over there too.
I'm not too acclimated in this stuff, but I was able to follow along with the blog posts pretty easily so I hope this ends up helping :). If anyone finds a better solution I'd love to hear about it so tag be (if you would be so kind) so I can stay updated!

The type initializer for 'BBDXamarinForms.Droid.Library.Config.BBDXamarinConfig' threw an exception

I am creating a Xamarin forms app using blackberry dynamics SDK in it. While I am initializing blackberry dynamics, I get an error in function
BBDXamarinConfig.Initialize();
I added the SDK (dll files) of blackberry dynamics in Xamarin form app for Android and iOS.
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this,
savedInstanceState);
BBDXamarinConfig.Initialize();
LoadApplication(new App());
}
The error message (obtained while initializing blackberry dynamics for Xamarin in xamarin.android) reads:
The type initializer for 'BBDXamarinForms.Droid.Library.Config.BBDXamarinConfig' threw an exception
Can someone help me?

No device yet in pushbots

I am new to pushbots and have done push notification as it given in tutorial, but when I click on Dashboard and then push it display an alert box which messaged "No devices Yet" I am not getting how to add device while I have installed apps in Android mobile.
Please help me out...
I had the same problem, and made sure more than once that everything is right
Then tried to uninstall the app and install it again with taking instance from MyApplication in my MainActivity
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new MyApplication();
}
}
And This worked for me, but when i tried again to delete the instance and delete uninstall the app it still registered on pushbots website!!

Resources