How to create notification icon badge on Android apps (like iPhone) - java

I am very new to programming and would like to know what is the best way to go about creating a notification icon badge similar to the ones on the iPhone apps. This would be basically for creating a badge for the notifications that end up in the notification bar.

This is actually an answer from Mark Murphy:
For most phones, you use the number field of the Notification object.
See here:
http://github.com/commonsguy/cw-android/tree/master/Notifications/Notify1/
Now, there are a few phones by one major device manufacturer that have
a bug, whereby the number field is ignored. I am working on getting
them to fix it. So you can't absolutely rely on that red bubble being
there, though it will be on most phones.

Are you talking about a graphical icon? I created a transparent PNG using the gimp and pass that drawable id as the 1st argument to the Notification constructor.
Notification notification = new Notification(R.drawable.someicon,title,System.currentTimeMillis())

I know this is very old question. May be this link is helpful is you are still looking for answer. https://github.com/leolin310148/ShortcutBadger

Related

How can I add custom view in android status bar?

I am creating a chat app, and I want to add a view like textview or a progressbar in android system's status bar for the app like this
I don't know what to do for this. I also searched in google for a solution, but they giving result for Notification.
Here I mention that, I'm not asking for any notification or floating view! I just want to add a view in that status bar.
Can anyone help me to do this?
Thanks in advance!!
As an app developer, you have no permission to set a view inside the status bar. Only the Android OS itself can manage and change views in the status bar according to the current state of the device (what notifications it has, battery status etc.)
As a developer, you can only:
Hide it
Change its color
What are you trying to achieve? Surely Android has a better solution to your problem.

Set different constraints for each orientation in Android Studio

The question sounds way harder than it is. Simply all I want to do is to be able to set a different layout for, I already added a landscape orientation, and recreated the whole design the way I desire in landscape. However, the app restarts each time I rotate the phone, if I add android:configChanges="orientation" in manifest, it does save the state but not the way I set in landscape. The app is 4 layouts in each orientation. So if I could just make different constraints for landscape the doesn't interrupt the original portrait it could solve my problem.
sorry for the poor explanation. It's my first week with Android.
You are correct in designing different layouts for different orientations.
For the state, you should override the onSaveInstanceState() method in Java.
Using that, you can save the state of the application and then inflate the layout the way you like in Java.

Place notification beneath the divider android java

I am busy with notifications, and I was wondering how I could archieve such thing as in the image below. I tried setting it as ongoing, but it didn't quite archieve the functionality I would like it to be.
How can I place my notification beneath that divider? (So above or under USB for charging)
Set your notification to PRIORITY_MIN:
builder.setPriority(NotificationCompat.PRIORITY_MIN);

Android - Honeycomb or ICS Go Completely Full Screen

Is there a way in ICS or Honeycomb to go completely full screen? I want the system UI completely gone! Currently what I do is:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
But this results in the Status Bar being replaced by really dim dots! I want it completely gone! Lets say for example I want to play a video or show a picture that takes up the whole screen. I'm okay with the status bar coming back on user interaction but I need it completely gone when there is no user interaction.
With the code above. I get the following look:
I want the dim dots gone as well and my video / image to be completely full screen.
This is not possible in Honeycomb, but has been added in API v14. Use:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
See the more detailed answers over here (though I would use a Build.Version.SDK_INT check instead of the suggested reflection-based check for support):
Hide ICS back home task switcher buttons
As the previous poster Suggested, that is completely impossible without rooting your device and performing some somewhat dirty process kill operations. The reason for is that new Hardware (like a tablet, for instance) may not have hardware buttons for navigation - and so by hiding those buttons the User would have no means of doing things that they are supposed to be guaranteed to be able to do, like going to the home screen, or accessing device info. Whether or not you might agree with that reasoning, such is the API.
The last information I have is that you can use the black tape to cover it. That's the suggestion given by Chet Haase. Watch this google IO 2011 session Q&A starting at 53minutes
You want SYSTEM_UI_FLAG_HIDE_NAVIGATION . Keep in mind that since the soft navigation buttons are key to device experience this only hides the buttons until there is some user interaction. If you want to permanently hide them then rooting the device (as others have suggested) is the only way to go.
The flag was added as of Ice Cream Sandwich, API 14. Previous to 14 a flag STATUS_BAR_HIDDEN was added in Honeycomb, API 11 that had a similar function. Previous to that the soft navigation buttons didn't exist, so fullscreen modes were handled entirely by Themes (specifically Theme.NoTitleBar.Fullscreen).
Use:
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH )
mBaseLayout.setSystemUiVisibility( View.SYSTEM_UI_FLAG_HIDE_NAVIGATION );
else if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB )
mBaseLayout.setSystemUiVisibility( View.STATUS_BAR_HIDDEN );

Android recognize cell phone with keyboard or not?

In my android app, I want to detect the user's device if the device has keyboard(like motorola milestone) and then show corresponding user interface. How do I do that?
http://developer.android.com/reference/android/content/res/Configuration.html
public int keyboard
The kind of keyboard attached to the device. One of: KEYBOARD_NOKEYS, KEYBOARD_QWERTY, KEYBOARD_12KEY.
If you're asking if there is a mechanism to allow detection of physical keyboard?
yes, Android does have the capability to notify applications of a keyboard open/close event.
You'll have to add detection of configuration changes to your activities. I believe there is a notification that is posted to the activity currently displayed that will indicate the keyboard state (or device configuration change).
http://developer.android.com/guide/topics/manifest/activity-element.html might give more insight in to what you're looking for.

Categories

Resources