GoogleApiClient for multiple Api's - location-services

I am using GooglePlayServices for my android application . I will be using Google+ Api & LocationServices Api. So from Google's documentation , I build the GoogleApiClient with addApi(Auth.GOOGLE_SIGN_IN_API), addApi(LocationServices.API). Every time user launches the application , I use Google+ api , but I use the LocationServices in rare cases (once in 100 launches). So what is the best way to implement.
Creating a single GoogleApiClient by adding two Api's ? or
Creating two GoogleApiClient's individually for those two api's?

add More Api if needed
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
// Add more APIs, as needed
.build();

Related

Push Notification in Xamarin using AWS SNS

I provide various rental space, and my app provides the feature to rent this space to people. Let's say a user with higher priority/ memebrship in my app trying to book a space that is being used up by lower priority user. As soon as the higher priority user press the book button I want a notification to pop up in the lower priority users mobile.
My app is build using Xamarin Forms. And I want to push notification using AWS SNS, but as I see SNS requires device token to send the notification. I am planning to store the device token in the database for ever user, but I am not entirely sure how to get device token depending upon both IOS and Android environment. I am thinking of using a dependency interface that
public interface INotificationService
{
Task<string> GetDeviceToken();
}
And I have not find a good source which I can use to get device token.
Can anyone help me, and correct me if it is correct to save device token in database?
I am working on this right at this moment. This is for iOS only and what's working for me.
Put this into your AppDelegate.
public async override void RegisteredForRemoteNotifications(UIApplication application, NSData token)
{
if (application.IsRegisteredForRemoteNotifications == true)
{
var snsClient = new AmazonSimpleNotificationServiceClient("your aws key id", "your aws secret key", Amazon.RegionEndpoint.YourRegion);
/* In the AWS SNS example here - https://docs.aws.amazon.com/mobile/sdkforxamarin/developerguide/getting-started-sns-ios.html
token.Description is used, for me the line below triggers an exception, so I used token.DebugDescription instead.
*/
var deviceToken = token.DebugDescription.Replace("<", "").Replace(">", "").Replace(" ", "");
if (!string.IsNullOrEmpty(deviceToken))
{
//register with SNS to create an endpoint ARN
var response = await snsClient.CreatePlatformEndpointAsync(
new CreatePlatformEndpointRequest
{
Token = deviceToken,
PlatformApplicationArn = "your aws platform application arn"
});
}
}
}
As for storing it in a database, I haven't got that far, but I am think of using DynamoDb for my specific purpose.
When/if I have Android working, I will update my answer.

Relationship between Teams Messaging Extension with action command, the underlying bot and access via Graph API

I want to call a messaging extension (with action command) and access Graph API via a bot for getting different resources of the channel (e.g. retrieve all messages or get replies for my message).
In the examples from Microsoft it is stated as a prerequisite that I have to do the "Bot channels registration" so that the access of the bot to the Graph API via OAuth2 works.
Do I really need this channel registration? Or is there another way?
As a test, I had created a azure free trial, with which I performed the "Bot channels registration" and could also save the ID and secret for the Graph Api access in the registration. With this I had success. Now the 30 days testing period is over and I'm interested in whether it would work without.
Thanks for your help
Update:
Thats my code to initialize graph api:
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(AppId)
.WithClientSecret(AppSecret)
.WithAuthority(new Uri($"https://login.microsoftonline.com/{Tenant}"))
.Build();
string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
AuthenticationResult authenticationResult = await app.AcquireTokenForClient(scopes).ExecuteAsync();
var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage
.Headers
.Authorization = new AuthenticationHeaderValue("Bearer", authenticationResult.AccessToken);
return Task.FromResult(0);
}));
For OAuth authentication, you need to register the bot with azure for sure.

oauthCard login opens empty window

I have the following code:
import { ActivityTypes, CardFactory, TurnContext } from "botbuilder";
export class MyBot {
/**
* Handles incoming activity, received from a user, processes it, and replies as needed
* #param {TurnContext} context on turn context object.
*/
public onTurn = async (turnContext: TurnContext) => {
const oauthCard = CardFactory.oauthCard("ms-graph", "Login", "Please sign in so I know who you are");
return await turnContext.sendActivity({ attachments: [oauthCard] });
}
}
When I run the bot in bot emulator framework, I see the login button. When I click on it however, it just opens an empty signin window that's all white.
I've also configured authentication in Azure:
Edit: I've also configured the app id and password in my .bot file.
There is an option to use Azure Service Bus in place of ngrok which may work for you. It functions much the same but gives you control over where your data is traveling when "tunneling", among other benefits. As it's an Azure service, it can live in the same subscription you already access.
In short, you'll create a local client application that connects your bot via a relay to the Azure Service Bus service. The service bus namespace/relay replaces the messaging endpoint in the bot settings in Azure (for testing). In this way your bot running on localhost can connect to external services. Just be sure to use the same endpoint in Emulator that you use in the Azure bot settings, including the "/api/messages".
The instructions found here can guide you thru the process of setting up and running. The steps are a little long looking but the process itself is fairly simple. There are two options to build: a .NET Framework and a .NET Core. I would recommend the "Framework" version unless you need to run this on a Mac. This isn't an official MS blog (yet) but expect it to show up there.
Hope of help!

Firebase notification in Xamarin

I'm implementing Firebase in a Xamarin Forms application.
I use the Rest API for the database.
Is there a way to register the notification token using the REST API?
Write code for both iOS and Android that extracts the token and posts to a REST API endpoint?
Or perhaps there is a better solution for Firebase notifications in Xamarin?
Is there a way to register the notification token using the REST API? Write code for both iOS and Android that extracts the token and posts to a REST API endpoint?
In Xamarin.form it does not provide the cross platform API to push notification. But you can achieve push notification in each platform. Take android as an example :
[Service]
[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class MyFirebaseInstanceIDService : FirebaseInstanceIdService {
public override void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.Instance.Token;
// send Instance ID token to your app server.
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(String token) {
//implement this method to send token to your app server
}
}
In the sendRegistrationToServerfunction you can posts the token to a REST API endpoint.
Do not forget to register the service to android manifest.
Android firebase guide
For IOS platform please refer this document guide

Send push notifications using Registration ID through Azure Notification Hubs

I am trying to use Azure Notification Hubs to send push notifications to a client. I read this article which uses tags to identify each user.
https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-aspnet-backend-windows-dotnet-notify-users/
It does the work, but the number of tags is limited. I was thinking to store and use the Registration ID that the Hub returns.
Is there any way to send notifications using this ID?
Another way would be using the Channel.URI that is returned by WNS. Can this be implemented somehow?
Actually NH limits only number of tags per single registration but per hub you may have as many registrations as you need and each registration may have unique tag which you can use to route the notifications.
Also there is new Installation API for Notification Hubs which I believe fits better for you. It is still not well-documented but well-done and ready to use. Here you can find short description of how to use that API. Readme is about Java but .NET SDK has pretty much the same capabilities (in the end both call same REST API).
Keyword is TAG ! If you use any spesific tag for any registered device which is Android,IOS,Windows OS etc, you can send notification to any specific device.
To do these, you should follow below steps one by one ;
As Client side, register device using a spesific tag to selected Azure Notification Hub
Client Example for Android :
`/*you don't have to use Firebase infrastructure.
You may use other ways. It doesn't matter.*/`
String FCM_token = FirebaseInstanceId.getInstance().getToken();
NotificationHub hub = new NotificationHub(NotificationSettings.HubName,
NotificationSettings.HubListenConnectionString, context);
String registrationID = hub.register(FCM_token, "UniqueTagForThisDevice").getRegistrationId();
Like you see, we have used a unique tag call "UniqueTagForThisDevice" for selected Android device.
As Server Side, you should send notification using that TAG call "UniqueTagForThisDevice".
Server Example using Web API to send push selected Android device :
[HttpGet]
[Route("api/sendnotification/{deviceTag}")]
public async Task<IHttpActionResult> sendNotification(string deviceTag)
{
//deviceTag must be "UniqueTagForThisDevice" !!!
NotificationHubClient Hub = NotificationHubClient.CreateClientFromConnectionString("<DefaultFullSharedAccessSignature>");
var notif = "{ \"data\" : {\"message\":\"Hello Push\"}}";
NotificationOutcome outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif,deviceTag);
if (outcome != null)
{
if (!((outcome.State == NotificationOutcomeState.Abandoned) ||
(outcome.State == NotificationOutcomeState.Unknown)))
{
return Ok("Push sent successfully.");
}
}
//Push sending is failed.
return InternalServerError();
}
As last, you should call above Web API Service method using "UniqueTagForThisDevice" tag from any helper platform (Postman, Fiddler or anothers.).
Note : TAG doesn't have to be deviceToken or similar things. It just have to spesific for each devices. But I suggest you that, if you use WebAPI and it is related with Owin midlleware, you may prefer username as unique tag. I think, this is more available for application scenarios. In this way, you can carry sending notifications from unique devices to unique users ;)
That's all.

Resources