コード例 #1
0
  /** Creates a notification of the specified type for a contact. */
  public void createNotification(NotificationType type, int notificationId, Contact contact) {
    Notification notification = new Notification(-1, null, System.currentTimeMillis());

    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;

    RemoteViews contentView = new RemoteViews(_context.getPackageName(), R.layout.notification);

    // set the photo
    contentView.setImageViewBitmap(
        R.id.notification_contact_photo, ContactsHelper.getPhoto(_context, contact));

    // set the verb, i.e. "call" or "text"
    contentView.setTextViewText(
        R.id.notification_notification_type, _context.getString(type.getVerbStringId()));

    // set the name and type
    contentView.setTextViewText(R.id.notification_contact_name, contact.getDisplayName());
    contentView.setTextViewText(R.id.notification_contact_type, contact.getType());

    // set the number
    contentView.setTextViewText(R.id.notification_contact_number, contact.getNumber());

    notification.contentView = contentView;

    // create the intent that will fire when the contact is selected
    Intent intent = new Intent(type.getAction(), Uri.parse(type.getScheme() + contact.getNumber()));
    PendingIntent contentIntent = PendingIntent.getActivity(_context, 0, intent, 0);
    notification.contentIntent = contentIntent;

    _manager.notify(notificationId, notification);
  }
コード例 #2
0
ファイル: MainActivity.java プロジェクト: c-mars/Contacts
 private void showContacts() {
   ContactsHelper.getContacts()
       .limit(10)
       .subscribeOn(Schedulers.io())
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(
           contact -> {
             String s = contact.toString() + "\n";
             textView.append(s);
             Timber.d(s);
           },
           throwable -> {
             String e = throwable.getLocalizedMessage();
             textView.append(e);
             Timber.e(e);
           });
 }