I'm doing a call recorder program.But, ACTION_NEW_OUTGOING_CALL permission removed from api 29, it gives such an error. My aim, delete codes used by this permission,How can i do?.i dont want incoming our outcoming information. Please help!
My codes:
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (!action.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED) &&
!action.equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
return;
}
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
String extraState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
Log.d(Constants.TAG, "PhoneReceiver phone number: " + phoneNumber);
if (!FileHelper.isStorageWritable(context))
return;
if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction())) {
App.isOutComming = true;
}
if (extraState != null) {
dispatchExtra(context, intent, phoneNumber, extraState);
} else if (phoneNumber != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, RecordService.class)
.putExtra("commandType", Constants.STATE_INCOMING_NUMBER)
.putExtra("phoneNumber", phoneNumber));
} else {
context.startService(new Intent(context, RecordService.class)
.putExtra("commandType", Constants.STATE_INCOMING_NUMBER)
.putExtra("phoneNumber", phoneNumber));
}
} else {
Log.d(Constants.TAG, "phone number x:x " + null);
}
}
But When I lounch this application,i see this error :
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 number=0 vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0)
You should create Notiication channel for android.O
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val importance = android.app.NotificationManager.IMPORTANCE_LOW
val mChannel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME, importance)
mChannel.description = CHANNEL_DESCRIPTION
mChannel.enableLights(true)
mChannel.lightColor = Color.RED
mChannel.enableVibration(true)
val mNotificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as android.app.NotificationManager
mNotificationManager.createNotificationChannel(mChannel)
}
and when creating notificiation you should give it the channel id
NotificationCompat.Builder(context, CHANNEL_ID)
User contributions licensed under CC BY-SA 3.0