2016-08-16 2 views
0

GCM 및 quickBlox를 사용하여 푸시 알림을 구현하려고하므로 quickblox를 사용하여 푸시 알림을 구독 할 수 있으며 메시지를 보내는 중에 알림을받지 못합니다.푸시 알림, quickblox, android가 수신되지 않습니다.

는 기본적으로 내가 여기에 가이드를 따라 : http://quickblox.com/developers/SimpleSample-messages_users-android#Send_Push_Notifications_from_Application

여기에 내 코드

public class MainActivity extends AppCompatActivity { 

static final String APP_ID = "45535"; 
static final String AUTH_KEY = "L-kz28SrxuSrn23"; 
static final String AUTH_SECRET = "zJX63sgj9Nm3qMB"; 
static final String ACCOUNT_KEY = "sor71FWvtVnx7d9JdTyd"; 

private GoogleCloudMessaging googleCloudMessaging; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 



    QBSettings.getInstance().init(getApplicationContext(), APP_ID, AUTH_KEY, AUTH_SECRET); 
    QBSettings.getInstance().setAccountKey(ACCOUNT_KEY); 

    if (checkPlayServices()) { 
     // Start IntentService to register this application with GCM. 
     Intent intent = new Intent(this, RegistrationIntentService.class); 
     startService(intent); 
    } 


    // Create quickblox session with user 
    QBAuth.createSession("laddu", "chowmein", new QBEntityCallback<QBSession>() { 
     @Override 
     public void onSuccess(QBSession session, Bundle params) { 
      //request Registration ID 
      String registrationId = "16441570"; 

      // Subscribe to Push Notifications 
      subscribeToPushNotifications(registrationId); 

     } 

     @Override 
     public void onError(QBResponseException errors) { 

     } 
    }); 


    EditText text; 
    text = (EditText) findViewById(R.id.editText); 

    Button send; 
    send = (Button) findViewById(R.id.button); 
    send.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View view) { 
      StringifyArrayList<Integer> userIds = new StringifyArrayList<Integer>(); 
      //add different user ID 
      userIds.add(16335930); 
      userIds.add(16441570); 

      QBEvent event = new QBEvent(); 
      event.setUserIds(userIds); 
      event.setEnvironment(QBEnvironment.DEVELOPMENT); 
      event.setNotificationType(QBNotificationType.PUSH); 
      event.setPushType(QBPushType.GCM); 

      //HashMap<String, String> data = new HashMap<String, String>(); 
      //data.put("data.message", "Hello"); 
      //data.put("data.type", "welcome message"); 

      event.setMessage("Hello"); 

      QBPushNotifications.createEvent(event, new QBEntityCallback<QBEvent>() { 
       @Override 
       public void onSuccess(QBEvent qbEvent, Bundle args) { 
        // sent 
       } 

       @Override 
       public void onError(QBResponseException errors) { 

       } 
      }); 
     } 
    }); 
} 

/** 
* Check the device to make sure it has the Google Play Services APK. If 
* it doesn't, display a dialog that allows users to download the APK from 
* the Google Play Store or enable it in the device's system settings. 
*/ 
private boolean checkPlayServices() { 
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance(); 
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this); 
    if (resultCode != ConnectionResult.SUCCESS) { 
     if (apiAvailability.isUserResolvableError(resultCode)) { 
      //apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST) 
        //.show(); 
     } else { 
      //Log.i(TAG, "This device is not supported."); 
      finish(); 
     } 
     return false; 
    } 
    return true; 
} 


public void subscribeToPushNotifications(String registrationID) { 
    QBSubscription subscription = new QBSubscription(QBNotificationChannel.GCM); 
    subscription.setEnvironment(QBEnvironment.DEVELOPMENT); 
    // 
    String deviceId; 
    final TelephonyManager mTelephony = (TelephonyManager) getSystemService(
      Context.TELEPHONY_SERVICE); 
    if (mTelephony.getDeviceId() != null) { 
     deviceId = mTelephony.getDeviceId(); //*** use for mobiles 
    } else { 
     deviceId = mTelephony.getDeviceId(); 
     //deviceId = Settings.Secure.getString(activity.getContentResolver(), 
      //  Settings.Secure.ANDROID_ID); //*** use for tablets 
    } 
    subscription.setDeviceUdid(deviceId); 
    Toast.makeText(MainActivity.this, deviceId, Toast.LENGTH_SHORT).show(); 
    // 
    subscription.setRegistrationID(registrationID); 
    // 
    QBPushNotifications.createSubscription(subscription, new QBEntityCallback<ArrayList<QBSubscription>>() { 

     @Override 
     public void onSuccess(ArrayList<QBSubscription> subscriptions, Bundle args) { 

     } 

     @Override 
     public void onError(QBResponseException error) { 

     } 
    }); 
} 

}

공용 클래스 MyGcmListenerService가 {

private static final String TAG = "MyGcmListenerService"; 

@Override 
public void onMessageReceived(String from, Bundle data) { 
    String message = data.toString(); 
    Log.d(TAG, "From: " + from); 
    Log.d(TAG, "Message: " + message); 

    if (from.startsWith("/topics/")) { 
     // message received from some topic. 
    } else { 
     // normal downstream message. 
    } 

    sendNotification(message); 
    // [END_EXCLUDE] 
} 

private void sendNotification(String message) { 
    Intent intent = new Intent(this, MainActivity.class); 
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, 
      PendingIntent.FLAG_ONE_SHOT); 

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
      .setContentTitle("GCM Message") 
      .setContentText(message) 
      .setAutoCancel(true) 
      .setSound(defaultSoundUri) 
      .setContentIntent(pendingIntent); 

    NotificationManager notificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); 
} 

}

GcmListenerService을 확장입니다 691,363,210
+0

보냅니다. 이 QBEnvironment.DEVELOPMENT를 QBEnvironment로 변경하면 차이가 있습니까? – dazza5000

+0

아니요,하지만 실제로 제 동료 중 한 명이 문제를 해결했습니다. – lykan

답변

0

당신은 다음 확인할 수 있습니다

  1. 확인 푸시 인증서 : 관리자 패널 -> 푸시 알림 -> 설정 -> APNS, GCM 등
  2. 확인 구독 : 관리자 패널 -> 푸시 알림 -> 가입 . 또한이 사용자에 대한 구독을 확인할 수 있습니다 : 관리자 패널 -> 사용자 - 관리자 패널에서> "당신의"사용자
  3. 보내기 푸시 -> 푸시 알림 -> 우리는 유사한 문제가 발생하는 http://quickblox.com/developers/SimpleSample-messages_users-android#Send_Push_Notifications_from_Admin_panel
관련 문제