Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Nuget used:
FireBaseAdmin v1.9.2
I'm trying to use firebase admin to send push notification to fcm.
I read the documentation but can't find any other good source to figure out how to use it properly.
I can't figure out where to add the serverkey and senderid.
I made a methode for sending push notifications.
Has anyone an example i could follow or any other documentation?
public override async Task<string> Send(List<String> tokens, string title, string body)
{
var message = Message()
{
Tokens = tokens,
Notification = new Notification()
{
Title = title,
Body = body
}
};
return await FirebaseMessaging.DefaultInstance.SendAsync(message).ConfigureAwait(false);
}
When i debug this code the response is null from SendAsync.
It might be because i didn't give it the serverkey and senderId but then i would expect an error like serverKeyNotFound.
Server key and sender ID parameters are not used in the Admin SDK. You just need to instantiate a FirebaseApp with some GoogleCredential as shown in https://firebase.google.com/docs/admin/setup.
On top of that your code seems to be syntactically incorrect. There's no Tokens property available in the Message class. You need MulticastMessage class for that. So I'd expect the above code to fail compilation.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 12 months ago.
Improve this question
I am new to xamarin and swift and I am creating a demo and in that, I have to write down some iOS related code which is mentioned below in code but the code is swift and I want to add that code in my .cs file so that I can use it with my UI page and it is giving errors as mentioned in the below image. It would be great if you can guide me with this and provide me with what code should I need to write and where.
UIApplication.shared.open(redirectUrl, options: [:], completionHandler: { success in
if success {
// Handle success.
} else {
// Handle failure. Most likely app is not present on the user's device. You can redirect to App Store using these links:
}
})
This should work for you. My advise, please refer to the official documentation it's all there.
var param = new NSDictionary();
UIApplication.SharedApplication.OpenUrl(new NSUrl("https://google.com"), param, (completed) =>
{
if (completed)
{
}
else
{
}
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want my android app to listen in all incoming messages and do what it is supposed to do when it receives the intended message. For example, I want to send the location of the phone to a preset number when it receives the message that the phone is missing, I do not care from which number it receives the message, only the message that will sent should be send to the specified number (for example my second number).
I wrote the messaging codes and they are in the program and my only problem is receiving the messages and distinguishing them from each other and separating the correct message.
I apologize if my question is superficial or my explanation is inaccurate. I'm new in Xamarin and I have not become a professional yet. If the explanation is not complete, tell me where the problem is, I will explain more. Thanks
You could try to use BroadcastReceiver(android.provider.Telephony.SMS_RECEIVED) to listener the SMSes.
For more detail information, please refer to the official document: Broadcast Receivers in Xamarin.Android.
Something like:
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { "android.provider.Telephony.SMS_RECEIVED" })]
class SMSBroadcastReceiver: BroadcastReceiver
{
public static string IntentAction = "android.provider.Telephony.SMS_RECEIVED";
public override void OnReceive(Context context, Intent intent)
{
if (intent.Action != SmsRetriever.SmsRetrievedAction)
return;
var extrasBundleundle = intent.Extras;
if (extrasBundleundle == null) return;
var status = (Statuses)extrasBundleundle.Get(SmsRetriever.ExtraStatus);
switch (status.StatusCode)
{
case CommonStatusCodes.Success:
// Get SMS message contents
var messageContent = (string)extrasBundleundle.Get(SmsRetriever.ExtraSmsMessage);
break;
case CommonStatusCodes.Timeout:
break;
}
}
}
don't forget to add the permission
<uses-permission android:name=”android.permission.RECEIVE_SMS”/>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I was reading https://learn.microsoft.com/en-us/aspnet.... about Security to prevent AJAX requests to another domain and makes me wonder, if I enable this, I would be able to make request from my Android Client? Cu'z it seems that anything outside of that domain, can't be requested. Is that it? Thanks!
Would be something like:
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
using (IUserRepository _repository = new UserRepository(new Data.DataContexts.OAuthServerDataContext()))
{
var user = _repository.Authenticate(context.UserName, context.Password);
if (user == null)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
}
If you are making the request from another domain then you will need to set up an Access-Control-Allow-Origin header. You can use * if you aren't concerned about security but it's best to specify only the domains you know will need access.
Non-browser-based clients may not necessarily send the Origin header (e.g. Postman) in which case you likely won't need to worry about setting up CORS.
That documentation you linked is a good start. This post provides a good basic example if you want to set up access globally rather than a per-controller basis.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a desktop application that has some classes, which I want to serialize and send to a webpage when a user clicks a button in the desktop C# application.
The data is too long for an argument. What I want to achieve here is, how do I post it and open the website on the clients PC with the dynamic changes made by the sent data ?
Need some suggestions or guidance to proceed in the right direction.
You can use HttpClient
For example:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://myUrl");
var gizmo = new Product() { Name = "Gizmo", Price = 100, Category = "Widget" };
response = await client.PostAsJsonAsync("api/products", gizmo);
if (response.IsSuccessStatusCode)
{
//do something
}
}
One option would be to generate local page with form that contains data and "action=POST" pointing to your site. Than set script that automatically submit this form and as result you'll have data send by browser and browser will continue as if it is normal POST request.
If you don't like HttpClient you can also use WebClient which is a convenience wrapper for your exact scenario.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
using c#.
I just want to clarify something... I normally work with WCF. Can I call rest apis exactly like I call WCF? Or do I use WebClient and parse the responseStream? If the rest api returns string formatted as JSON would I then somehow format this json in the responseStream?
I have spent sometime Googling but there seems to be different advice for it.
to be specific are there any standards for rest api clients? Is it just down to choice?
You should look into HttpClient (For making REST calls) and Json.NET (For serializing / deserializing your json):
A simple Get request:
var httpClient = new HttpClient();
var response = await httpClient.GetAsync(uri);
//will throw an exception if not successful
response.EnsureSuccessStatusCode();
string content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<SomeType>(content);
Note HttpClient is built with an asynchronous API which preferably should be used with async/await keywords