Exemplo n.º 1
0
 /**
  * Display notification to accept or reject invitation
  *
  * @param remote remote contact
  */
 private void displayAcceptRejectDialog(ContactId remote) {
   /* Manual accept */
   AlertDialog.Builder builder = new AlertDialog.Builder(this);
   builder.setTitle(R.string.title_group_chat);
   String from = RcsContactUtil.getInstance(this).getDisplayName(remote);
   String topic = (TextUtils.isEmpty(mSubject)) ? getString(R.string.label_no_subject) : mSubject;
   String msg = getString(R.string.label_gc_from_subject, from, topic);
   builder.setMessage(msg);
   builder.setCancelable(false);
   builder.setIcon(R.drawable.ri_notif_chat_icon);
   builder.setPositiveButton(
       R.string.label_accept,
       new android.content.DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int which) {
           try {
             /* Accept the invitation */
             mGroupChat.openChat();
           } catch (RcsServiceException e) {
             showExceptionThenExit(e);
           }
         }
       });
   builder.setNegativeButton(
       R.string.label_decline,
       new android.content.DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int which) {
           /*
            * Let session die by timeout. Exit activity
            */
           finish();
         }
       });
   registerDialog(builder.show());
 }
  private void addSessionInvitationNotification(Intent intent, ContactId contact) {
    /* Create pending intent */
    Intent invitation = new Intent(intent);
    String title;
    if (mMultimediaMessagingSession) {
      invitation.setClass(this, MessagingSessionView.class);
      title = getString(R.string.title_recv_messaging_session);
    } else {
      invitation.setClass(this, StreamingSessionView.class);
      title = getString(R.string.title_recv_streaming_session);
    }
    invitation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    /*
     * If the PendingIntent has the same operation, action, data, categories, components, and
     * flags it will be replaced. Invitation should be notified individually so we use a random
     * generator to provide a unique request code and reuse it for the notification.
     */
    int uniqueId = Utils.getUniqueIdForPendingIntent();
    PendingIntent contentIntent =
        PendingIntent.getActivity(this, uniqueId, invitation, PendingIntent.FLAG_ONE_SHOT);

    String displayName = RcsContactUtil.getInstance(this).getDisplayName(contact);

    /* Create notification */
    NotificationCompat.Builder notif = new NotificationCompat.Builder(this);
    notif.setContentIntent(contentIntent);
    notif.setSmallIcon(R.drawable.ri_notif_mm_session_icon);
    notif.setWhen(System.currentTimeMillis());
    notif.setAutoCancel(true);
    notif.setOnlyAlertOnce(true);
    notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    notif.setDefaults(Notification.DEFAULT_VIBRATE);
    notif.setContentTitle(title);
    notif.setContentText(getString(R.string.label_from_args, displayName));

    /* Send notification */
    NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(uniqueId, notif.build());
  }