Flash Plus Tripped Up By Android Pie

Ever since I upgraded to the Pixel 3 XL, my app Flash Plus crashed whenever I would receive phone calls. I figured out that it was a permissions issue, using the Android Studio debugger. However, there was no indication as to which permission was missing. My app already requests permission for 10 items. It seems with each Android release, Google adds more and more granular permissions in the name of security. However, the app runs just fine on my Pixel 2 XL unmodified. It is also on Android Pie. So, I have no idea why it works on one device but not the other.

In Android Pie, they added a new one related to accessing phone call details. It is:

<uses-permission android:name="android.permission.READ_CALL_LOG" />

I added that to AndroidManifest.xml. I also had to have my app request that permission from the user, as follows:

ActivityCompat.requestPermissions(FlashPlusActivity.this,
        new String[]{..., Manifest.permission.READ_CALL_LOG},
        REQUEST_PERMISSIONS);

Without the READ_CALL_LOG permission, the Pixel 3 XL will return an empty string from the onCallStateChanged() PhoneStateListener method. The empty string was causing the app to crash on the Pixel 3 XL.

Another thing I noticed was after fixing that bug and pushing the updated app back to the device, the notifications stopped working. Why it suddenly stopped working is a mystery. Of course, Google changed how notifications worked between Android Oreo and Android Pie. So, here’s how I got the notifications working again. In Android Pie, Google added notification channels. In order to display a notification, you must first create a notification channel, as shown below:

private void createNotificationChannel() {
     // Create the NotificationChannel, but only on API 26+ because
     // the NotificationChannel class is new and not in the support library
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
         CharSequence name = "Flash Plus";
         String description = "Flash Plus notification channel";
         int importance = NotificationManager.IMPORTANCE_DEFAULT;
         NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
         channel.setDescription(description);
         // Register the channel with the system; you can't change the importance
         // or other notification behaviors after this
         NotificationManager notificationManager = getSystemService(NotificationManager.class);
         notificationManager.createNotificationChannel(channel);
     }
 }

Then, I used the NotificationCompat.Builder to build a notification using the notification channel:

createNotificationChannel();
 NotificationCompat.Builder nBuilder =
         new NotificationCompat.Builder(this, CHANNEL_ID)
                 .setSmallIcon(android.R.drawable.presence_online)
                 .setContentTitle(getText(R.string.app_name))
                 .setContentText(getText(R.string.flash))
                 .setPriority(NotificationCompat.PRIORITY_DEFAULT);
 Intent notificationIntent = new Intent(this, FlashPlusActivity.class);
 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
 nBuilder.setContentIntent(pendingIntent);

Now, my app works as expected. I hope this information was useful.

About the Author

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You may also like these

No Related Post