Skip to content

Commit

Permalink
1.0.1+2
Browse files Browse the repository at this point in the history
  • Loading branch information
hiennguyen92 committed Feb 24, 2022
1 parent ebe1e7d commit 6aa5143
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 62 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.0.1+2

* Fixed issue default ringtone(Android)
* Fixed issue vibration(Android)
* Fixed issue sound play type ringtone volumn system(Android)
* Fixed flow incomming screen(Android)
* Fixed some bugs.

## 1.0.1+1

* Switch using Service for Ringtone(Android)
Expand Down
1 change: 1 addition & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />


<application>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.hiennv.flutter_callkit_incoming

import android.annotation.SuppressLint
import android.app.Activity
import android.app.KeyguardManager
import android.app.KeyguardManager.KeyguardLock
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
Expand Down Expand Up @@ -37,9 +39,8 @@ import kotlin.math.abs
import okhttp3.OkHttpClient
import com.squareup.picasso.OkHttp3Downloader
import android.view.ViewGroup.MarginLayoutParams



import android.os.PowerManager
import android.os.PowerManager.WakeLock


class CallkitIncomingActivity : Activity() {
Expand Down Expand Up @@ -93,9 +94,6 @@ class CallkitIncomingActivity : Activity() {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
setTurnScreenOn(true)
setShowWhenLocked(true)

val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
keyguardManager.requestDismissKeyguard(this, null)
} else {
window.addFlags(
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
Expand All @@ -114,6 +112,16 @@ class CallkitIncomingActivity : Activity() {
)
}

private fun wakeLockRequest(duration: Long) {

val pm = applicationContext.getSystemService(POWER_SERVICE) as PowerManager
val wakeLock = pm.newWakeLock(
PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.FULL_WAKE_LOCK or PowerManager.ACQUIRE_CAUSES_WAKEUP,
"Callkit:PowerManager"
)
wakeLock.acquire(duration)
}

private fun transparentStatusAndNavigation() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
setWindowFlag(
Expand Down Expand Up @@ -174,7 +182,7 @@ class CallkitIncomingActivity : Activity() {
ivAcceptCall.setImageResource(R.drawable.ic_video)
}
val duration = data?.getLong(EXTRA_CALLKIT_DURATION, 0L) ?: 0L

wakeLockRequest(duration)

finishTimeout(data, duration)

Expand Down Expand Up @@ -254,6 +262,10 @@ class CallkitIncomingActivity : Activity() {
val intent =
CallkitIncomingBroadcastReceiver.getIntentAccept(this@CallkitIncomingActivity, data)
sendBroadcast(intent)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
keyguardManager.requestDismissKeyguard(this, null)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
finishAndRemoveTask()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.media.AudioAttributes
import android.media.RingtoneManager
import android.net.Uri
import android.os.*
Expand Down Expand Up @@ -131,18 +130,26 @@ class CallkitNotificationManager(private val context: Context) {
R.id.llAccept,
getAcceptPendingIntent(notificationId, data)
)
val headers = data.getSerializable(CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>
getPicassoInstance(context, headers).load(data.getString(EXTRA_CALLKIT_AVATAR, ""))
.transform(CircleTransform())
.into(targetLoadAvatarCustomize)
val avatarUrl = data.getString(EXTRA_CALLKIT_AVATAR, "")
if (avatarUrl != null && avatarUrl.isNotEmpty()) {
val headers =
data.getSerializable(CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>
getPicassoInstance(context, headers).load(avatarUrl)
.transform(CircleTransform())
.into(targetLoadAvatarCustomize)
}
notificationBuilder.setStyle(NotificationCompat.DecoratedCustomViewStyle())
notificationBuilder.setCustomContentView(notificationViews)
notificationBuilder.setCustomBigContentView(notificationViews)
notificationBuilder.setCustomHeadsUpContentView(notificationViews)
} else {
val headers = data.getSerializable(CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>
getPicassoInstance(context, headers).load(data.getString(EXTRA_CALLKIT_AVATAR, ""))
.into(targetLoadAvatarDefault)
val avatarUrl = data.getString(EXTRA_CALLKIT_AVATAR, "")
if (avatarUrl != null && avatarUrl.isNotEmpty()) {
val headers =
data.getSerializable(CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>
getPicassoInstance(context, headers).load(avatarUrl)
.into(targetLoadAvatarDefault)
}
notificationBuilder.setContentTitle(data.getString(EXTRA_CALLKIT_NAME_CALLER, ""))
notificationBuilder.setContentText(data.getString(EXTRA_CALLKIT_HANDLE, ""))
val declineAction: NotificationCompat.Action = NotificationCompat.Action.Builder(
Expand Down Expand Up @@ -178,18 +185,23 @@ class CallkitNotificationManager(private val context: Context) {
}
notificationBuilder = NotificationCompat.Builder(context, "callkit_missed_channel_id")
notificationBuilder.setChannelId("callkit_missed_channel_id")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
notificationBuilder.setCategory(Notification.CATEGORY_MISSED_CALL)
}
notificationBuilder.setContentTitle(data.getString(EXTRA_CALLKIT_NAME_CALLER, ""))
notificationBuilder.setContentText(data.getString(EXTRA_CALLKIT_HANDLE, ""))
notificationBuilder.setSubText(context.getString(R.string.text_missed_call))
notificationBuilder.setSmallIcon(smallIcon)
val isCustomNotification = data.getBoolean(EXTRA_CALLKIT_IS_CUSTOM_NOTIFICATION, false)
if (isCustomNotification) {
val headers = data.getSerializable(CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>
val headers =
data.getSerializable(CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>

getPicassoInstance(context, headers).load(data.getString(EXTRA_CALLKIT_AVATAR, ""))
.transform(CircleTransform()).into(targetLoadAvatarDefault)
} else {
val headers = data.getSerializable(CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>
val headers =
data.getSerializable(CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_HEADERS) as HashMap<String, Any?>

getPicassoInstance(context, headers).load(data.getString(EXTRA_CALLKIT_AVATAR, ""))
.into(targetLoadAvatarDefault)
Expand Down Expand Up @@ -241,7 +253,6 @@ class CallkitNotificationManager(private val context: Context) {
}

private fun createNotificationChanel() {
val sound: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channelCall = NotificationChannel(
"callkit_incoming_channel_id",
Expand All @@ -257,10 +268,6 @@ class CallkitNotificationManager(private val context: Context) {
}
getNotificationManager().createNotificationChannel(channelCall)

val attributes = AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
.build()
val channelMissedCall = NotificationChannel(
"callkit_missed_channel_id",
"Missed Call",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hiennv.flutter_callkit_incoming

import android.app.Service
import android.content.Context
import android.content.Intent
import android.media.AudioAttributes
import android.media.AudioManager
Expand All @@ -12,6 +13,7 @@ import android.text.TextUtils

class CallkitSoundPlayerService : Service() {

private var vibrator: Vibrator? = null
private var mediaPlayer: MediaPlayer? = null
private var data: Bundle? = null
private val handler: Handler = Handler(Looper.getMainLooper())
Expand All @@ -29,7 +31,7 @@ class CallkitSoundPlayerService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {

this.playSound(intent)

this.playVibrator()
return START_STICKY;
}

Expand All @@ -38,6 +40,21 @@ class CallkitSoundPlayerService : Service() {
handler.removeCallbacks(runnableTimeout)
mediaPlayer?.stop()
mediaPlayer?.release()
vibrator?.cancel()
}

private fun playVibrator() {
vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val vibratorManager = this.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
vibratorManager.defaultVibrator
} else {
getSystemService(VIBRATOR_SERVICE) as Vibrator
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vibrator?.vibrate(VibrationEffect.createWaveform(longArrayOf(0L, 1000L, 1000L), 0))
}else{
vibrator?.vibrate(longArrayOf(0L, 1000L, 1000L), 0)
}
}

private fun playSound(intent: Intent?) {
Expand All @@ -50,19 +67,31 @@ class CallkitSoundPlayerService : Service() {
CallkitIncomingBroadcastReceiver.EXTRA_CALLKIT_DURATION,
30000L
)
val uri = sound?.let { getRingtoneUri(it) }
mediaPlayer = MediaPlayer.create(this@CallkitSoundPlayerService, uri).apply {
isLooping = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val attribution = AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
.build()
setAudioAttributes(attribution)
} else {
setAudioStreamType(AudioManager.STREAM_NOTIFICATION)
}
start()
var uri = sound?.let { getRingtoneUri(it) }
if(uri == null){
uri = RingtoneManager.getActualDefaultRingtoneUri(
this@CallkitSoundPlayerService,
RingtoneManager.TYPE_RINGTONE
)
}
mediaPlayer = MediaPlayer()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val attribution = AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
.setLegacyStreamType(AudioManager.STREAM_RING)
.build()
mediaPlayer?.setAudioAttributes(attribution)
} else {
mediaPlayer?.setAudioStreamType(AudioManager.STREAM_RING)
}
try {
mediaPlayer?.setDataSource(applicationContext, uri!!)
mediaPlayer?.prepare()
mediaPlayer?.isLooping = true
mediaPlayer?.start()
} catch (e: Exception) {
e.printStackTrace()
}
if (duration != null) {
handler.postDelayed(runnableTimeout, duration)
Expand Down
Loading

0 comments on commit 6aa5143

Please sign in to comment.