Example usage for android.app Notification CATEGORY_CALL

List of usage examples for android.app Notification CATEGORY_CALL

Introduction

In this page you can find the example usage for android.app Notification CATEGORY_CALL.

Prototype

String CATEGORY_CALL

To view the source code for android.app Notification CATEGORY_CALL.

Click Source Link

Document

Notification category: incoming call (voice or video) or similar synchronous communication request.

Usage

From source file:org.linphone.compatibility.ApiTwentyOnePlus.java

public static Notification createInCallNotification(Context context, String title, String msg, int iconID,
        Bitmap contactIcon, String contactName, PendingIntent intent) {

    Notification notif = new NotificationCompat.Builder(context).setContentTitle(contactName)
            .setContentText(msg).setSmallIcon(iconID).setAutoCancel(false).setContentIntent(intent)
            .setLargeIcon(contactIcon).setCategory(Notification.CATEGORY_CALL)
            .setVisibility(Notification.VISIBILITY_PUBLIC).setPriority(Notification.PRIORITY_HIGH).build();

    return notif;
}

From source file:com.ferdi2005.secondgram.voip.VoIPService.java

private void showIncomingNotification() {
    Intent intent = new Intent(this, VoIPActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    Notification.Builder builder = new Notification.Builder(this)
            .setContentTitle(LocaleController.getString("VoipInCallBranding", R.string.VoipInCallBranding))
            .setContentText(ContactsController.formatName(user.first_name, user.last_name))
            .setSmallIcon(R.drawable.notification)
            .setContentIntent(PendingIntent.getActivity(this, 0, intent, 0));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        endHash = Utilities.random.nextInt();
        Intent endIntent = new Intent();
        endIntent.setAction(getPackageName() + ".DECLINE_CALL");
        endIntent.putExtra("end_hash", endHash);
        CharSequence endTitle = LocaleController.getString("VoipDeclineCall", R.string.VoipDeclineCall);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            endTitle = new SpannableString(endTitle);
            ((SpannableString) endTitle).setSpan(new ForegroundColorSpan(0xFFF44336), 0, endTitle.length(), 0);
        }/*  w  ww. j a va  2s.c  o m*/
        builder.addAction(R.drawable.ic_call_end_white_24dp, endTitle,
                PendingIntent.getBroadcast(this, 0, endIntent, PendingIntent.FLAG_UPDATE_CURRENT));
        Intent answerIntent = new Intent();
        answerIntent.setAction(getPackageName() + ".ANSWER_CALL");
        answerIntent.putExtra("end_hash", endHash);
        CharSequence answerTitle = LocaleController.getString("VoipAnswerCall", R.string.VoipAnswerCall);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            answerTitle = new SpannableString(answerTitle);
            ((SpannableString) answerTitle).setSpan(new ForegroundColorSpan(0xFF00AA00), 0,
                    answerTitle.length(), 0);
        }
        builder.addAction(R.drawable.ic_call_white_24dp, answerTitle,
                PendingIntent.getBroadcast(this, 0, answerIntent, PendingIntent.FLAG_UPDATE_CURRENT));
        builder.setPriority(Notification.PRIORITY_MAX);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        builder.setShowWhen(false);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setColor(0xff2ca5e0);
        builder.setVibrate(new long[0]);
        builder.setCategory(Notification.CATEGORY_CALL);
        builder.setFullScreenIntent(PendingIntent.getActivity(this, 0, intent, 0), true);
    }
    if (user.photo != null) {
        TLRPC.FileLocation photoPath = user.photo.photo_small;
        if (photoPath != null) {
            BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50");
            if (img != null) {
                builder.setLargeIcon(img.getBitmap());
            } else {
                try {
                    float scaleFactor = 160.0f / AndroidUtilities.dp(50);
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor;
                    Bitmap bitmap = BitmapFactory
                            .decodeFile(FileLoader.getPathToAttach(photoPath, true).toString(), options);
                    if (bitmap != null) {
                        builder.setLargeIcon(bitmap);
                    }
                } catch (Throwable e) {
                    FileLog.e(e);
                }
            }
        }
    }
    Notification incomingNotification = builder.getNotification();
    startForeground(ID_INCOMING_CALL_NOTIFICATION, incomingNotification);
}