making GCM notifications configurable in applications - google-cloud-messaging

My question is
How to stop receiving notifications from GCM service with out using
GCMRegistar.unregistar(context).
Is there any method to stop receiving notifications.
I need this because I want to make GCM Push Notification feature configurable by the user if user sets for getting notification he will receive notification otherwise stops receiving notification with out unregistering device
Any links helps me a lot.

I do a similar thing with regards to my applications, if you get the paid version you get notifications, if you get the free version you don't get such updates.
I accomplished this by adding a field to the table where all my registration ID's are called status. When a notification push is done by my server it will only send to those registrations where the status is 'paid'.
So for your case I suggest adding the option to your application to stop receiving notifications. This method will perform a post to your server like follows:
Function updateNotificationStatus(boolean status)
{
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://yourserver/update.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("status", status));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new
}
Handle these posts on your server and just update the status field in you table.
Hope this helps

Related

Create a space with Google Chat REST API

We have a program that uses a service account to manage various thing inside Google Chat.
Now, we have the need to create a new space using the Google Chat REST API (spaces.create).
We already joined the developer preview program, as this endpoint is not yet generally available.
From what we understand, this endpoint is not possible to invoke via service account and so we wanted to ask you… can we invoke this endpoint automatically using “domain delegation”? If yes, how?
We always want to use the service account as it is not possible to show a login prompt to the user.
We enabled the domain delegation but that endpoint returns always status 403. (We are using Google.Apis library for .NET Core
using Google.Apis.Auth.OAuth2;
var credential = GoogleCredential.FromFile("key.json")
.CreateScoped("https://www.googleapis.com/auth/chat.spaces.create")
.CreateWithUser("service-account-email#project.iam.gserviceaccount.com");
var token = await credential.UnderlyingCredential.GetAccessTokenForRequestAsync();
HttpRequestMessage request = new(HttpMethod.Post, "https://chat.googleapis.com/v1/spaces");
request.Headers.Authorization = new("Bearer", token);
var payload = #"
{
""name"": ""testspace-1"",
""spaceType"": ""SPACE"",
""singleUserBotDm"": true,
""displayName"": ""Test Space""
}
";
request.Content = new StringContent(payload, System.Text.Encoding.UTF8, "application/json");
HttpClient client = new();
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
If you check the documentation Auth
You will notice it stats that service account authorization is supported. If you are part of thedeveloper preview program
The reason I asked about your code is that the last time i tried this which notably was a while ago. The google .net client library was not generated the methods that were under preview.
So while it may work yes. The issue your may have is that the client library when loaded will not have the method you need meaning you will have to code the call to the endpoint yourself.
If this is in fact the case let me know if you have any issues peceing it together I may be able to help.
update your code
There is an error in your code
.CreateWithUser("service-account-email#project.iam.gserviceaccount.com");
The email in CreateWithUser should be the user on your domain who you wish to delicate the service account as. Not the service account email address.

push notification IBM MobileFirst 7

I have written IBM Adapter for push notification.I able to fetch device Id from device using 'WL.Device.getID'.I want to send push notification on the device but there is no way to subscribe.and did not find a way to subscribe push notification Event source in java adapter as mentioned in demo javaScript adapter. When I called sendMessage() method through pushApi , I got exception that PushApplication was not found.
Also to handle the challange , we use WorklightProtocolAuthenticator .
Please help how i can send push notification using java based push adapter.
Below is my adapter :-
WLServerAPI api = WLServerAPIProvider.getWLServerAPI();
PushAPI pushApi = api.getPushAPI();
INotification noti = pushApi.buildNotification();
noti.getTarget().setDeviceIds("a5be4b35-b278-3014-b933-ce99a8l87819");
noti.getMessage().setAlert("text to be send on device");
pushApi.sendMessage(noti, "ApplicationId");
And how can i get this ApplicationId.
Please help how i can send push notification using java based push adapter.
You do not find what you are looking for because AFAIK it does not exist. The APIs are available only in JavaScript.

PushSharp "Notification send timed out" issue

I am trying to use PushSharp to send notification to my mobile devices using Google Gcm.
I downloaded the sample application from github depending upon that I have written my sample code. below is my sample code.
var googleKey = CustomConfigurationManager.GetValueFromSection("appSettings", "GoogleServerAccessKey");
AndroidPushBroker.RegisterGcmService(new PushSharp.Android.GcmPushChannelSettings(googleKey));
GcmNotification androidNotifcation = new GcmNotification().WithDryRun()
.WithJson("{\"alert\":\"Hello World!\",\"badge\":7,\"sound\":\"sound.caf\"}");
AndroidPushBroker.QueueNotification(androidNotifcation);
The issue is though I have used WithDryRun() and upon hooking up request it shows json data with "dry_run": true, but still I receive Notification failed error with reason : "Notification send timed out".
Anybody can tell me what am I missing ?
try to run it without WithDryRun(), and see do you get anything in events like NotificationSent, ChannelException, NotificationFailed or ServiceException.

EventNotification in DocuSign SOAP based API

I am using EventNotification with DosuSign SOAP based API. The problem is i am not received any Request on the URL (that i mentioned in the definition of Event Notification) when any event occurs for Envelope.
Following are my code snippet: (here i required notification when envelope is completed)
Dim EnvelopeNotificationURL As String = "https://{my url}"
Dim EventNotifi As New EventNotification
EventNotifi.URL = EnvelopeNotificationURL
EventNotifi.LoggingEnabled = True
'Defining Envelope Events
Dim envEvent(0) As EnvelopeEvent
envEvent(0) = New EnvelopeEvent
envEvent(0).EnvelopeEventStatusCode = EnvelopeEventStatusCode.Completed
EventNotifi.EnvelopeEvents = envEvent
NewEnvelope.EventNotification = EventNotifi
'// Here NewEnvelope is an instance of Envelope Class.
There are at least a couple of possibilities here:
The event notification portion of your XML Request isn't correct/complete. I'd suggest that you update your question to include a trace of the complete XML Request that's being sent to the server (you can easily generate this trace using Fiddler or a similar tool), so that we can examine the full XML request and rule out any issues with its format/contents.
The XML Request format/contents is fine, and Connect is attempting to send the message to your listener when the Envelope is Completed, but there's an issue preventing the message from being delivered to your listener. I'd suggest that you check the DocuSign Connect Logs (in the DocuSign web console) to determine: 1) if messages are being sent and 2) if there are issues with the message reaching the listener endpoint. The Connect Service guide (http://www.docusign.com/sites/default/files/DocuSign_Connect_Service_Guide.pdf) contains information about how to view the logs.
If you can update your question with information about what you're seeing in the Connect log file, and also include a trace of the full XML request that's going to the server, I'll update this answer with additional feedback.

Authentication with SMTP transport using Swiftmailer

I'm using Swiftmailer to send emails in my Yii based application and it works great, so there is no problems with the Swiftmailer extension wrapper. But now I want to use the SMPT transport to authenticate the users in my application against the mail server. The code I'm using:
$SM = Yii::app()->swiftMailer;
$mailHost = 'XXX';
$mailPort = XXX;
// New transport
$transport = $SM->smtpTransport($mailHost, $mailPort);
$transport->setUsername($username);
$transport->setPassword($password);
$transport->start();
if($transport->isStarted()){
// authenticated;
}else{
// error;
}
$transport->stop();
This isn't working. When I set real login credentials instantly logs in. But when I type wrong ones, it spends some time but at last it logs in too. I don't know why this happens because just when using real credentials Swiftmailer can send emails.
I'm using the right API functions? I'm doing something wrong?
Looking at the source, when you call start(), started is always set to True.
I'm not familiar with switfmailer, but it looks like you'll want to check the results of authenticate()