我有一个GCM注册用户列表及其在数据库表中的相应注册ID,我实际上想要在从表中删除用户时取消注册用户.我在Stackoverflow中找到了很多示例,但其中大多数都基于旧的GCMRegistrar API,现在已弃用.我正在使用GoogleCloudMessaging API并通过以下方法注册用户:
private void registerUser(){
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getBaseContext());
String regId = "";
try {
regId = gcm.register(getString(R.string.project_number));
Log.i("registrationId", regId);
}
catch (IOException e) {
Log.i("Registration Error", e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个管理员应用程序,它充当第三方应用程序服务器,因为它将通知推送给所有用户.我想通过以下方法从此管理员应用中取消注册特定用户:
private void unRegister(String regId) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getBaseContext());
try {
gcm.unregister();
}
catch (IOException e) {
System.out.println("Error Message: " + e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
但令我困惑的是,unregister()方法没有将注册ID作为参数,这使得无法注销特定设备.有没有办法通过注册ID从GCM取消注册特定设备?
android push-notification google-cloud-messaging google-play-services
我只是对 Winsock 中使用 send() 函数感到困惑。这段代码实际上是否通过 TCP 发送字符串“Hello”?我设法在 LabVIEW 中与 TCP 客户端建立连接,但该 TCP 服务器似乎没有发送任何内容。
#define DEFAULT_BUFLEN 1024
#include<stdio.h>
#include<winsock2.h>
#include<Ws2tcpip.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stddef.h>
#pragma comment(lib,"ws2_32.lib") //Winsock Library
int main(int argc , char *argv[])
{
WSADATA wsa;
SOCKET s , new_socket;
struct sockaddr_in server , client;
int c;
int iResult;
char *sendbuf = "Hello";
printf("\nInitialising Winsock...");
if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
{
printf("Failed. Error Code : %d",WSAGetLastError());
return 1;
}
printf("Initialised.\n");
//Create a socket
if((s = socket(AF_INET , SOCK_STREAM , 0 )) …Run Code Online (Sandbox Code Playgroud) 我有一些基于在NetBeans中添加Guava的StopWatch的问题.
我需要导入秒表类:import com.google.common.base.Stopwatch;,但此类不包含在"base"之后的不同商机中.其他类如CharMatcher也包括在内.我添加了guava-r09.jar和guava-r09-gwt.jar文件.