Как создать уведомление как входящий звонок? [закрыто]Android

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 Как создать уведомление как входящий звонок? [закрыто]

Сообщение Anonymous »

Я хочу создать как это:

Но я имею только в лоте:

my code:

Код: Выделить всё

public static final String CHANNEL_ID_NOTIFICATION = "intercom_channel_id";
public static final String CHANNEL_ID_NEW_CALL = "intercom_channel_id_new_call";

private static final String CHANNEL_NAME = "My Channel";
private static final String CHANNEL_DESCRIPTION = "Channel for general notifications";

private static final int NOTIFICATION_ID_NOTIFICATION = 1;
private static final int NOTIFICATION_ID_NEW_CALL = 2;

public static final String INTENT_ACTION_CALL_INCOMING = "tindroidx.intent.action.call.INCOMING";
public static final String INTENT_ACTION_CALL_CLOSE = "tindroidx.intent.action.call.CLOSE";
public static final String INTENT_EXTRA_TOPIC = "co.tinode.tindroid.TOPIC";
public static final String INTENT_EXTRA_SEQ = "co.tinode.tindroid.SEQ";
public static final String INTENT_EXTRA_CALL_DIRECTION = "co.tinode.tindroid.CALL_DIRECTION";
public static final String INTENT_EXTRA_CALL_ACCEPTED = "co.tinode.tindroid.CALL_ACCEPTED";
public static final String INTENT_EXTRA_CALL_AUDIO_ONLY = "co.tinode.tindroid.CALL_AUDIO_ONLY";

public static Intent answerCallIntent(Context context, String topicName, int seq, boolean audioOnly) {
Intent intent = new Intent(INTENT_ACTION_CALL_INCOMING, null);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION
| Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(INTENT_EXTRA_TOPIC, topicName)
.putExtra(INTENT_EXTRA_SEQ, seq)
.putExtra(INTENT_EXTRA_CALL_ACCEPTED, true)
.putExtra(INTENT_EXTRA_CALL_AUDIO_ONLY, audioOnly);
intent.setClass(context, PythonActivity.class);
return intent;
}

private static PendingIntent answerIntent(Context context, String topicName, int seq, boolean audioOnly) {
return PendingIntent.getActivity(context, 102,
answerCallIntent(context, topicName, seq, audioOnly),
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}

private static PendingIntent declineIntent(Context context, String topicName, int seq) {
final Intent intent = new Intent(context, PythonActivity.class);
intent.setAction(INTENT_ACTION_CALL_CLOSE);
intent.putExtra(INTENT_EXTRA_TOPIC, topicName);
intent.putExtra(INTENT_EXTRA_SEQ, seq);
return PendingIntent.getBroadcast(context, 103, intent,
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}

public static void showNotificationNewCall(Context context, String title, String message) {
Log.v(Settings.T(new Throwable(), new Object(){}), "");

try {

Person caller = new Person.Builder()
.setName("Jane Doe")
.setImportant(true)
.build();
int seq = 0;
boolean audioOnly = false;

// 2. Create an Intent for the activity to open when the notification is tapped
Intent intent = new Intent(context, PythonActivity.class); // Replace PythonActivity.class with your desired activity
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(
context,
101,
intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
//PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE // Use FLAG_IMMUTABLE for security
);

// 3.  Build the Notification
Notification.Builder builder = new Notification.Builder(context, CHANNEL_ID_NEW_CALL);
builder.setSmallIcon(android.R.drawable.ic_dialog_info) // Replace with your own icon
.setContentTitle(title)
.setContentText(message)
.setPriority(Notification.PRIORITY_HIGH)
.setFullScreenIntent(pendingIntent, true) // Set the PendingIntent
.setAutoCancel(true) // Dismisses the notification when tapped
.setUsesChronometer(true)
.setCategory(Notification.CATEGORY_CALL)
//.setOngoing(true)
.setContentIntent(pendingIntent)
.setTimeoutAfter(30000)
.setVisibility(Notification.VISIBILITY_PUBLIC);

builder.setStyle(Notification.CallStyle.forScreeningCall(caller,
declineIntent(context, title, seq), answerIntent(context, title, seq, audioOnly)));

// 4. Show the Notification
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.notify(NOTIFICATION_ID_NEW_CALL, builder.build()); // Use a unique ID for each notification
}
} catch (Exception e) {
Log.v(Settings.T(new Throwable(), new Object(){}), e.toString() + " " + e.getMessage());
}
}
Я использовал:

[*]https://www.forasoft.com/blog/article/h ... a302281677,> />https://www.forasoft.com/blog/article/h ... cation-455? />https://github.com/tinode/tindroid/blob ... nager.java#> /> Я не знаю, что делаю не так. < /p>

Подробнее здесь: https://stackoverflow.com/questions/797 ... oming-call
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Как создать уведомление как входящий звонок? [закрыто]
    Anonymous » » в форуме JAVA
    0 Ответы
    1 Просмотры
    Последнее сообщение Anonymous
  • Как завершить входящий звонок на уровне приложения Android?
    Гость » » в форуме Android
    0 Ответы
    61 Просмотры
    Последнее сообщение Гость
  • Как использовать CallScreeningService в Android, чтобы отклонить входящий звонок
    Anonymous » » в форуме Android
    0 Ответы
    30 Просмотры
    Последнее сообщение Anonymous
  • Минимизированный входящий звонок
    Anonymous » » в форуме Android
    0 Ответы
    31 Просмотры
    Последнее сообщение Anonymous
  • Отмените входящий звонок, когда звонящий остановит его
    Anonymous » » в форуме IOS
    0 Ответы
    2 Просмотры
    Последнее сообщение Anonymous

Вернуться в «Android»