Skip to content

Instantly share code, notes, and snippets.

final class ConnectivityStateManager {
...
private volatile ConnectivityState state = ConnectivityState.IDLE;
...
}
public final class ManagedChannelImplBuilder extends ManagedChannelBuilder<ManagedChannelImplBuilder> {
...
static final long IDLE_MODE_DEFAULT_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(30);
static final long IDLE_MODE_MIN_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(1);
...
}
val channel = AndroidChannelBuilder
.forAddress("127.0.0.1", 9090)
.context(androidContext)
.build()
val channel = AndroidChannelBuilder
.forAddress("127.0.0.1", 9090)
.maxRetryAttempts(10)
.build()
val channelWithKeepAlive = AndroidChannelBuilder
.forAddress("127.0.0.1", 9090)
.keepAliveTime(20, TimeUnit.SECONDS)
.keepAliveTimeout(5, TimeUnit.SECONDS)
.build()
syntax = "proto3";
package com.victorbrandalise;
service Bookstore {
rpc CreateBook(CreateBookRequest) returns (Book) {}
rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) {}
}
message Book {
val scope = CoroutineScope(Dispatchers.IO)
fun main() {
val channel = AndroidChannelBuilder
.forAddress("127.0.0.1", 9090)
.build()
val book = BookOuterClass.Book.newBuilder()
.setId(1)
.setTitle("gRPC In-Depth")
private const val CHANNEL_ID = "heads_up_alerts"
private const val CHANNEL_NAME = "Heads Up Alerts"
private val notificationManager = NotificationManagerCompat.from(context)
private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
val channel = NotificationChannel(
CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH
private fun createNotification(): Notification {
val contentIntent = Intent(context, HomeActivity::class.java)
val contentPendingIntent = PendingIntent.getActivity(context, 0, contentIntent, 0)
return NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.notifications_active_black_24)
.setColor(ResourcesCompat.getColor(context.resources, R.color.purple_200, null))
.setContentTitle(context.getString(R.string.notification_title))
.setAutoCancel(true)
.setContentIntent(contentPendingIntent)
const val NOTIFICATION_ID = 24756
notificationManager.notify(NOTIFICATION_ID, createNotification())