I have an app with media buttons and text in the notification that I want to update programatically. So I did this:
public void updateNotificatonIcons() {
ArrayList<NotificationCompat.Action> acts = NotificationBuilder.mActions;
acts.set(1, new NotificationCompat.Action((isPlaying) ? R.drawable.my_media_stop : R.drawable.my_media_play, "Stop", stopintent));
NotificationBuilder.mActions = acts;
NotificationManagerCompat.from(context).notify(1, NotificationBuilder.build());
}
The problem is that AndroidStudio complains about NotificationBuilder.mActions:
Builder.mActions can only be accessed from within the same library group prefix (referenced groupId=androidx.core with prefix androidx from groupId=Android)
I googled and added a #SuppressLint("RestrictedApi") before the method, and it works.
Is this the "correct" way of updating the notification? Is there a better way without the need of a #SupressLint?
Related
I'm using PlayerNotificationManager for displaying playback notifications in my application. Everything is working fine but I want to add my application's logo in the notification with custom fonts.
I changed the play & pause buttons on the notification by adding drawables.xml. But can't find a way to change the font.
So, how can I change the default notification layout and characteristics that Exoplayer provides?
Edit:
I have seen this issue on Github which says that we need to extend PlayerNotificationManager in order to use custom layout. But I can't seem to get it working.
Here is my code:
private void setPlayerNotificationManager(Player player) {
playerNotificationManager = new PlayerNotificationManager(context, "123", 1234, mediaDescriptionAdapter);
playerNotificationManager.setUseNavigationActions(false);
playerNotificationManager.setUsePlayPauseActions(true);
playerNotificationManager.setRewindIncrementMs(0);
playerNotificationManager.setFastForwardIncrementMs(0);
//playerNotificationManager.setColor(Color.GREEN);
playerNotificationManager.setColorized(true);
playerNotificationManager.setUseChronometer(false);
playerNotificationManager.setSmallIcon(R.drawable.logo);
playerNotificationManager.setPlayer(player);
}
As said on the repo you need to extends the PlayerNotificationManager to do that you need to create this class and copy everything inside your project, and then add the layout you want to use as described in this link
You need to add your layout in the builder here
I would like to set the italic "Contents hidden" message for a public notification manually.
Android seem to set "Contents hidden" automatically if only a VISIBILITY_PRIVATE notification without a public counterpart is presented.
Here, the setContent-parts are automatically replaced.
For an example from K9mail see screenshot 1.
However, I would like to use a custom layout for the public notification while letting the notification look similar (i.e., "Contents hidden").
It is a notification for a music player, which should provide buttons for pause and play next songs.
So, how can I either
access the (localized) value for "Contents hidden" that Android is actually using (not implementing it manually) or
tell Android to replace all "setContent"-parts automatically as if I would not provide a public notification.
Any suggestions?
For the sake of completeness - the issue is related with this pull request: https://github.com/gateship-one/odyssey/pull/120
Pretty simple just use:
String foo = mContext.getString(android.content.res.Resources.getSystem().getIdentifier("notification_hidden_text", "string", "android"));
So building a new app specifically for the Android TV interface (lollipop leanback) and I'm using the PlaybackOverlayFragment that is provided by the framework which has a PlaybackControlsRow with all the usual controls on it.
The problem is, the default behavior is for the user to have to click the "Play" button to start the video and I want it to start automatically. That part is easy and I have it working but then the Play/Pause icons on the provided control are out of sync (showing play when should be pause) because the item was started outside of the events of clicking on that control.
Documentation is sparse on these framework elements and examining the class I can't find any public method that would allow me to put this control in the proper "mode" or tell it to display the play or pause icon myself.
Anyone with experience with these yet that would know how to do this?
In order to change the state of the button, even after adding your Actions to the Adapter, you'll need to notify the changes to the adapter that has your Action.
mPlayPauseAction.nextIndex(); // next index, if it was pause, it'll be play
notifyChanged(mPlayPauseAction);
// where notifyChanged(Action action) is:
private void notifyChanged(Action action) {
ArrayObjectAdapter adapter = mPrimaryActionsAdapter; // reference to your adapter
if (adapter.indexOf(action) >= 0) {
adapter.notifyArrayItemRangeChanged(adapter.indexOf(action), 1);
return;
}
}
Well, I partially answered my own question.
If I know before the PlaybackControlsRow is created that I want to set it to the pause state (actually, playing state but showing pause button) then if I call setIndex(PlaypauseAction.PAUSE) on the PlayPauseAction before adding it to the controlsrow then it works.
It doesn't appear that I can modify it myself after adding it but that may be something else I'm doing wrong.
Im suffering from a problem in notification. Im doing my project in PHONEGAP.
I want to show multiple lines in push notification in android. Now i am only getting single line notification. i cannot expand or do anything with that notification. im using a phonegap plugin.
com.phonegap.plugins.PushPlugin
Please help me to overcome this problem.
Screen shot is given below.
Current Notification
Expected Notification
This involves a custom layout in the native notification (remoteviews) , so it is needed to modify you favorite plugin
Android custom notification layout with RemoteViews
In case of this plugin: https://github.com/phonegap-build/PushPlugin
Modify GCMIntentService.java, particulary NotificationCompat.Builder setContent with a the custom View. This custom view can be loaded from xml or instatiated by code: How to create a RelativeLayout programmatically with two buttons one on top of the other?
Example of a custom builder: Create custom notification, android
Change the params for the plugin or parse payload message to separate lines
Path: \platforms\android\src\com\plugin\gcm
Filename: GCMIntentService.java
String message = extras.getString("message");
if (message != null) {
mBuilder.setContentText(message);
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));//add this line
I'm currently working on an app to display the battery status and I'd like to use Android-drawables instead of own images to reduce the app size.
I've found this page which lists available images and the availability for each SDK-version:http://www.fixedd.com/projects/android_drawables_display
My question: How can I access the "system"-drawables? If you click on the link and choose the tab "Status", there are some battery-drawables like "stat_sys_battery_0", but I can't access it, Eclipse doesn't offer intellisense for it and won't compile the app if I use one of those drawables.
As those drawables are part of all SDK-versions, I'd think I should be able to use them, or are those "special" drawables protected in a way so they can only be used by system-functions (and not apps)?
Any idea is appreciated.
Select0r
Hope this is what you were looking for:
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
#Override
public void onReceive(Context arg0, Intent intent) {
int level = intent.getIntExtra("level", 0);
int batteryIconId = intent.getIntExtra("icon-small", 0);
Button toolBarBattery = (Button) findViewById(R.id.toolBarButton);
LevelListDrawable batteryLevel = (LevelListDrawable) getResources().getDrawable(batteryIconId);
batteryLevel.setLevel(level);
toolBarBattery.setBackgroundDrawable(batteryLevel);
}
};
I've found another link with information that not all drawables are public. It doesn't say why some drawables would be private, but I guess I'll have to live with the fact and copy the needed images to my app.http://androiddrawableexplorer.appspot.com/
NOTE: Some of the images in the Android jar are not public and therefore cannot be directly used (you can copy them to you own application, but can't reference them via the "android" package namespace).
There actually seems to be a way to access the system icons, but it's not really working as stated in the documentation, but I'll add it in case somebody is interested:
intent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL, -1)
Will get you the resource-ID of the icon that matches the current battery-status:http://developer.android.com/reference/android/os/BatteryManager.html#EXTRA_ICON_SMALL
Extra for ACTION_BATTERY_CHANGED:
integer containing the resource ID of
a small status bar icon indicating the
current battery state.
However, it always returns the same icon, no matter what the actual battery level is. Finding the icon by just trying random numbers may work, but I don't know if the IDs are consistent throughout the SKD-levels as well as different machines, so I'd rather not rely in that.