如我所见,您已经获得了 deviceID 和 registrationID,您必须将其存储在您的服务器上。现在可以创建一个按钮,它将执行以下 onclick。$ public void sendRegistrationIdToServer(String deviceId, String registrationId) {
HttpClient client = new DefaultHttpClient();
Log.d("GCM","sending to server");
HttpPost post = new HttpPost("YOur URL.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
// Get the deviceID
nameValuePairs.add(new BasicNameValuePair("deviceid", deviceId));
nameValuePairs.add(new BasicNameValuePair("registrationid", registrationId));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
Log.d("GCM","sent to server");
} catch (IOException e) {
e.printStackTrace();
}
}
在服务器端,您可以接收 ID 并将其存储在您的数据库中。希望你能明白。