-2
我按照教程中的所有步驟操作。 tutorial android Push notificationAndroid如何使用drupal服務器接收推送通知
我的設備是利用GCM標識Drupal的服務器上成功註冊。
我的問題是,從服務器發送推送通知時,它顯示'成功發送通知',但這個通知沒有在手機上接收。
任何一個可以請建議我該怎麼辦....
我按照教程中的所有步驟操作。 tutorial android Push notificationAndroid如何使用drupal服務器接收推送通知
我的設備是利用GCM標識Drupal的服務器上成功註冊。
我的問題是,從服務器發送推送通知時,它顯示'成功發送通知',但這個通知沒有在手機上接收。
任何一個可以請建議我該怎麼辦....
最後我發現我的錯誤。
我試圖在廣播接收器中獲取通知消息,但是它錯了我在這個服務onMessage(上下文上下文,意圖數據)中獲取消息。
public class GCMIntentService extends GCMBaseIntentService{
private static final String TAG = "GCMIntentService";
public GCMIntentService() {
super(SENDER_ID);
}
@Override
protected void onError(Context arg0, String arg1) {
// TODO Auto-generated method stub
}
@Override
protected void onMessage(Context context, Intent data) {
Log.i(TAG, "new message= ");
String message = data.getExtras().getString("message");
/*if (message.equals("")) {
//message="hellow senha , this is vc circle notification. You can check how it display long or short...";
generateNotification(context, message);
}else{
generateNotification(context, message);
}*/
//message="hellow senha , this is vc circle notification. You can check how it display long or short...";
generateNotification(context, message);
}
private void generateNotification(Context context, String message) {
int icon = R.drawable.vc_placeholder;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, SplashScreenActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context);
Notification notification = mBuilder.setSmallIcon(icon).setTicker("VCCircle").setWhen(when)
.setContentTitle(context.getString(R.string.app_name))
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setContentIntent(resultPendingIntent)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.vc_placeholder))
.setContentText(message).build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
{
// Wake Android Device when notification received
PowerManager pm = (PowerManager) context
.getSystemService(Context.POWER_SERVICE);
final PowerManager.WakeLock mWakelock = pm.newWakeLock(
PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH");
mWakelock.acquire();
// Timer before putting Android Device to sleep mode.
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
mWakelock.release();
}
};
timer.schedule(task, 5000);
}
}
@Override
protected void onRegistered(Context context, String registrationId) {
Log.i(TAG, "Device registered: regId = " + registrationId);
displayMessage(context, getString(R.string.gcm_registered));
boolean te=ServerUtilities.register(context, registrationId);
System.out.println("Device Register : "+te);
}
@Override
protected void onUnregistered(Context arg0, String arg1) {
// TODO Auto-generated method stub
}
}
結賬的node.js與Drupal的推送通知。 –