How can I retrieve Notifications list of status bar programmatically? - android

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.

Related

How to detect user interaction with graphstream?

I am investigating the use of GraphStream on Android using
api 'com.github.graphstream:gs-ui-android:2.0-alpha'
api 'com.github.graphstream:gs-core:2.0-alpha'
I have managed to construct and display my Graph fine,
However I cannot see how to listen for user interactions on the nodes within my graph.
I need to display a Dialog when any node is clicked on by the user and display the specific nodes information.
I've tried setting a Listener on the org.graphstream.ui.android_viewer.AndroidViewer, however I never received any callbacks
I can drag the displayed nodes around the screen so I know there are default listeners, how to I add my own listeners though?
You can implement ViewerListener with the ViewerPipe like this :
ViewerPipe pipe = fragment.getViewer().newViewerPipe();
pipe.addAttributeSink( graph );
pipe.addViewerListener( this ); // this or any class which implements ViewerListener
pipe.pump();
You can get an exemple here : https://github.com/graphstream/gs-ui-android-test/blob/master/app/src/main/java/ui/graphstream/org/gs_ui_androidtestFull/Activity_TestArrows.java
And here to understand how ViewerPipe works : http://graphstream-project.org/doc/Tutorials/Graph-Visualisation/

Mandatory Settings Update

I am making one android app where one setting is must every user need to update that which is pincode.
So after successful login, if the user has not updated pincode yet, it needs to be updated mandatory before navigating to any other screen.
What is the best way to implement this? Any Ideas?
Update:
After answer, I meant to say that setting I will be fetching from firebase database as boolean flag. So my actual query is how to show that as a mandatory to get the user update? (i.e) either navigating to different activity or showing popup and getting the setting etc. I need UI design ideas.
What is the best practice?
It is not clear what is the point of this, and if you have a server side that controls that stuff, but I'll try to give a help.
If you have a Server controlling authentication:
On login, call the API of your service to check if has happened or not. You could save the answer in a "shared preference" (Android Documentation), so you don't call your API every time.
If you only want to have the application on a client side:
Use 1 to store values that indicate if the desired action was performed or not, which is verified right after the login.
EDIT:
If the action is mandatory, you could send the user to an activity to update the pin, this will happen until the action is performed.
Client side approach:
You can use SharedPreferences to persist a value, like a simple boolean, that will inform you if that the user already updated the pincode or not.
I would recommend you to perform the check in the onResume() of your Launcher Activity.
Putting it simple and explicit:
public static final String PREF_FILE_NAME = "PrefFileName";
public static final String PREF_IS_PIN_CODE_UPDATED = "PREF_IS_PIN_CODE_UPDATED";
#Override
protected void onResume() {
super.onResume();
SharedPreferences prefs = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE);
Boolean isPinCodeUpdated = prefs.getBoolean(PREF_IS_PIN_CODE_UPDATED, false);
if (isPinCodeUpdated) {
// You can proceed
} else {
// Force the user to update the pin code, by prompting for instance a dialog where he can change the pin with setCancelable(false)
}
}
After you know that your user already updated the pin code you just need to set the preference to true.
SharedPreferences.Editor editor = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE).edit();
editor.putBoolean(PREF_IS_PIN_CODE_UPDATED, true);
editor.apply();
After this every time the user opens the app it will pass in the onResume() method and your isPinCodeUpdated var will be true and the app should proceed as usual.
From you question I am assuming that you didn't want a response in terms of UI but how could you have the information persisted.
Note: This implementation fails for multiple users in the same device. With few tweaks you can make it work for multiple users in the same device but in my opinion this verification should be done server side.

Adding a Two Way Friend Relation on Parse for Android

I am currently working on an app with a friendship feature similar to Facebook(a request is sent and if accepted they both become friends). The sending user can select multiple users from a list and send them all invites at once. When this happens, the receiving users are added to a relation called "pendingRelation" for the sending user. However, I would also like the sending user to be added as a "pendingRelation" for all the receiving users as soon as the request is sent. I have messed around and haven't been able to find a good solution for this. The code to add the selected users as "pendingRelation" is simple.
private boolean sendFriendRequest() {
//Cycles through list of selected friends and adds as "Pending"
for (int i = 0; i < mPendingFriends.size(); i++) { //Cycles through list
mPendingRelation.add(mPendingFriends.get(i));
}
mCurrentUser.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e != null) {
Log.e(TAG, e.getMessage());
}
}
});
If anyone can help me add the sender as a "pendingRelation" to the reciever as well to create this two-way relationship that would be great. Thanks!
I've actually thought about making a follow system with Parse which is quite similiar to your problem. Have you thought about making a new ParseObject instead of relation? Then you could add something like ParseUser pendingUser, ParseUser requestUser, boolean isAccepted.
Anywho if you can't find help from here you can try post it to parse.com questions.
I am trying to figure out the same thing for my app (although I am using javascript so I can't give you working code.. sorry.).
To expand on Torsten's answer. One solution would be to create a table(class) in Parse with the fields "pendingFriendRequest" "associatedUserID_requestingUser" "associatedUserID_receivingUser" and "accepted (boolean)".
SIDE NOTE: You could also add a matching function this way by querying
this table(class) and determining whether there are two
"pendingFriendRequests" from each individual user for the other user.
Then, you can present the user the results of querying this table and an option to "accept" (you can also present an option to ignore/delete and just drop the row).
Once the user clicks "accept" link that to a function which then creates the user relation.
In javascript it looks something like this:
likeAUser: function (userId) {
var currentUser = $rootScope.loggedInUser;
var User = Parse.Object.extend("User");
var user = new User();
user.id = userId;
var likes = currentUser.relation("Likes");
//console.log(likes);
likes.add(user);
return currentUser.save();
},
and within the function you are creating the new relation you would then drop(delete) the row from the "pendingRequests" table.
I hope this helps,
I have been racking my brain on how to do this and this is the best way I can figure out pending Parse making it easier to interact with relations elements inside their user class. Sorry I don't know the android version to help more.

Notifications in Android: change specific properties/fields?

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.

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