In developing PhoneLab Conductor app, I need to provide user a way to give us feedback after applying OTA update. Although this feature was disabled in release, I thought it's worthwhile to record how to implement that functionality anyway.

The Scenario

After the phone received and OTA update and rebooted to apply it, the conductor app will pop up an notification, saying something like "You've updated your platform, if there's any question, please tap to email for help.". So when user tap the notification, a selection alert should pop up to let user select which email client to use. Then open that email client with proper recipient, subject, and email body (e.g., some extra debug information).

The Overall Flow

When we post an notification using Notification.Builder, we can optionally set an PendingIntent about what action to take when user tap that notification. This is done via the setContentIntent function.


And that PendingIntent will broadcast an custom intent so our BoradcastReceiver will be called and handle that tap event.

private String reportProblemIntentName = this.getClass().getName() + ".ReportProblem";
private IntentFilter reportProblemIntentFilter = new IntentFilter(reportProblemIntentName);
private PendingIntent reportProblemPendingIntent;
private BroadcastReceiver reportProblemReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        // to be filled

// in initilization function
reportProblemPendingIntent = PendingIntent.getBroadcast(context, 0, 
    new Intent(reportProblemIntentName), PendingIntent.FLAG_UPDATE_CURRENT);
context.registerReceiver(reportProblemReceiver, reportProblemIntentFilter);

Launch Email App

Now when user tap the notification, the onReceive handler will be called.

First, we need to cancel the notification.

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

Then we prepare the intent for launch email app.

Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
String messageBody =
    "========================\n" +
    "  Optional debug info   \n" +
    "========================\n" +
    "Please describe your problems here.\n\n";
String uriText = "mailto:" + Uri.encode(PHONELAB_HELP_EMAIL) + "?subject="
    + Uri.encode("OTA Update Problem") + "&body=" + Uri.encode(messageBody);

Note that in order to actually launch the email chooser, we need another intent.

Intent actualIntent = Intent.createChooser(emailIntent, "Send email to PhoneLab");