Notifications in Android: change specific properties/fields? - android

On an Android 2.3.3 I want to update my Notification.
Today, I create a new Notification object, and fill it with stuff. That makes the ticker text show again, which I don't want. I just want to update the number in the Notification (and sometimes the contentText) without making a new Notification, and without replacing the current "contentText".
So:
How do I just update the number, without replacing any text (whatever text is in the notification now should be left untouched)
How do I get info on what text/data is in the current Notification?

Use custom notification and then update like this:
progressNotification.contentView.setProgressBar(R.id.PGB_UPLOAD, 100, percentage, false);
progressNotification.contentView.setTextViewText(R.id.TXV_UPLOAD_PROGRESS, String.valueOf(percentage)+"%");
objNotificationManager.notify(1, progressNotification);

You need to post the notification again, just as you said. To suppress the ticker, set the tickerText field to null.

Related

How can I retrieve Notifications list of status bar programmatically?

How can I retrieve Notification list of status bar programmatically on android?
I found some ways like NotificationListenerService, but I would be happy to know any methods or apis that I can retrieve every StatusBarNotification s in one method call.
public List<StatusBarNotification> getNotifications()
{
//...
}
EDIT
Thanks to comment I found some way. I'll post it later when I am finished, for further users.

How to change text when data is not available on MPAndroidChart library?

I am using MPAndroidChart to draw some charts on my Android application and I would like to change the default message that appears when the data is not available.
I am using a CombinedChart and a BarChart and in none of them I am able to change the text when data is not available.
I know that there are few questions on Stackoverflow related with this theme. For example:
MPAndroidChart - Change message "No chart data available"
MPAndroidChart -Use multiple text instead of "No Chart Data available" depends on the data
but all of them make reference to one or more of these methods:
.setDescription("");
.setNoDataTextDescription("Custom message.");
.setNoDataTextDescription("Custom message");
.setNoDataText("Custom message");
Any of them worked for me.
My snippet of code in which I try to change the text is the following:
combinedChart.setDescription(null);
combinedChart.setNoDataText("No data");
combinedChart.setData(data);
combinedChart.animateXY(2500,2500);
How can I provide a different text message to the user when data is not available?
EDIT: I have added .invalidate method as #SudhakarRaju suggested but it also does not work. My actual code is:
combinedChart.setDescription(null);
combinedChart.setNoDataText("No data");
combinedChart.setNoDataTextDescription("No data");
combinedChart.setNoDataTextDescription("No data");
combinedChart.invalidate();
combinedChart.setData(data);
combinedChart.animateXY(2500,2500);
//I also tried to put combinedChart.invalidate(); here but it also does not work.
Thanks in advance!
The same way above you mentioned but you have to add one extra line. combinedChart.invalidate(); This will work.
This code allows you to style the chart if no data:
mChart.setNoDataText(getResources().getString(R.string.no_data_available));
mChart.setNoDataTextColor(BaseActivity.getAppColor(R.color.black));
// from: https://github.com/PhilJay/MPAndroidChart/issues/89
Paint p = mChart.getPaint(Chart.PAINT_INFO);
if (p != null) {
p.setTextSize(getResources().getInteger(R.integer.no_data_text_size));
}
Remove the combinedChart.setData(data) call.
For some reason, if you send an empty Data object that contains an empty data set, the "no data" text will not be displayed.
I had the same problem and I resolved it by simply not setting the data if it's empty, or using combinedChart.clear() for that matter.

How to get the ui elements in a notification [Android]

I am trying to access the text on each button on a notification - and do further processing on the same.
I have the RemoteView object :
RemoteView rView = mStatusBarNotification.getNotification().contentView;
is it possible to get the text on each button using this RemoteView Object? If yes, how?
For example, in the following notification i need the text "Speaker" "End"
See Create custom notification, android or http://developer.android.com/guide/topics/ui/notifiers/notifications.html

Android Pass data from EditText to notification to dialog

I have an activity that has an EditText. After a user enters their text, the app may use that text later to make a notification. I can set the notification text just fine, but when the user clicks on the notification, it launches a dialog box that should have the same text. I have tried putExtra with the PendingIntent but that only displays the latest text in the dialog no matter which notification was selected. Is there a way to assign each string from the EditText a number and have the dialog load the text from what number it is?
try following logic,
make one static string variable,
private static strEditText = null;
at the time of EditText input, just store its value ion to strEditText variable like below,
strEditText = EditText.getText().toString().trim();
Now make one public static method, like below,
public static String EditTextValue()
{
return strEditText;
}
Now you can have this variable's value throughout whole project.
You can also try another method in android,
pass your arguments in Bundle
The PendingIntents are pooled/cached and the extra's don't make them different entries, so if you have a bunch of notifications with pendingIntents and the only difference between the intents are extras, then you'll end up with the notifications all using the one of the pendingIntents. [This sounds like what you're seeing, I remember this driving me nuts for a while]. You need to make your pending intents differ in something that the pool/cache cares about, like the data URI or action.

don't display the notification after seeing that once

Hi I don't want to display the any notification service in status bar if i saw one notification service once .For example i am displaying persons who are exceeding the 20 km distance from my location .some persons are displayed.when i saw it once then automatically the icon in the status bar is don't displayed.For this one give me some suggestions .Thanks in advance.
If your question is about preventing the display of notifications once the user clears one of your previous notifications, you'll probably need to maintain your own data structure to monitor this.
The idea is:
Store a hashtable/hashset/other data structure indicating which notifications the user has already seen.
Before showing a notification, check the hashtable – if the notification is in there, don't show it. Otherwise, show it.
When showing a notification, add it to the hashtable.
Flush the hashtable every so often.
You might also want to look into Notification.deleteIntent.
Caution: Before doing this, consider if this is really necessary. It might be sufficient to simply collapse visible notifications by reusing notification IDs.
I do this:
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
boolean used = sp.getBoolean("notif_used", false);
if ( used )
return;
else {
/* show the notification */
Editor editor = getSharedPreferences().edit();
editor.putBoolean("notif_used", true);
editor.commit();
}

Categories

Resources