I am writing an app to run under the managed profile (android for work). But it always crashed when sending a notification. Here is the sample code:
protected void onResume() { super.onResume(); final Notification.Builder builder = new Notification.Builder(this); builder.setAutoCancel(true) .setContentText("Test Notification") .setSmallIcon(android.R.drawable.ic_menu_close_clear_cancel); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(1001, builder.build()); } and the log: 01-12 15:08:23.990 12822 12822 E AndroidRuntime: Caused by: java.lang.SecurityException: Permission Denial: broadcast from android asks to run as user 0 but is calling from user 10; this requires android.permission.INTERACT_ACROSS_USERS_FULL or android.permission.INTERACT_ACROSS_USERS 01-12 15:08:23.990 12822 12822 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1599) 01-12 15:08:23.990 12822 12822 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1552) 01-12 15:08:23.990 12822 12822 E AndroidRuntime: at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:709) 01-12 15:08:23.990 12822 12822 E AndroidRuntime: at android.app.NotificationManager.notify(NotificationManager.java:230) 01-12 15:08:23.990 12822 12822 E AndroidRuntime: at android.app.NotificationManager.notify(NotificationManager.java:194) 01-12 15:08:23.990 12822 12822 E AndroidRuntime: at com.example.testproj.MainActivity.onResume(MainActivity.java:56) 01-12 15:08:23.990 12822 12822 E AndroidRuntime: at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1258) 01-12 15:08:23.990 12822 12822 E AndroidRuntime: at android.app.Activity.performResume(Activity.java:6312) 01-12 15:08:23.990 12822 12822 E AndroidRuntime: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3092) 01-12 15:08:23.990 12822 12822 E AndroidRuntime: ... 10 more and the permissions mentioned above: <!-- @SystemApi @hide Allows an application to call APIs that allow it to do interactions across the users on the device, using singleton services and user-targeted broadcasts. This permission is not available to third party applications. --> <permission android:name="android.permission.INTERACT_ACROSS_USERS" android:protectionLevel="signature|privileged|development" /> <!-- @hide Fuller form of {@link android.Manifest.permission#INTERACT_ACROSS_USERS} that removes restrictions on where broadcasts can be sent and allows other types of interactions. --> <permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" android:protectionLevel="signature|installer" /> So, the question is, as the two permissions mentioned (INTERACT_ACROSS_USERS_FULL and INTERACT_ACROSS_USERS) are hidden from third party app, how can I send out a notification under the managed profile ? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. To post to this group, send email to android-developers@googlegroups.com. Visit this group at https://groups.google.com/group/android-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/4617f786-540d-4cff-92d3-98c5ed109174%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.