I've been looking for the past 2 days on SW, google and so on. I'm looking for a way to implement an activity that comes with the native Android ICS lockscreen as the one shown in the screens below.
Those screens come from Player Pro but I noticed that also other players ( PlayerPro for instance ) have the same feature that looks exactly the same, that's why i think it's something native or at least, there is a common way to implement it.
So far I only managed to get and Activity that replace the lockscreen using these flags:
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
with a BroadCaseReciever on these events:
Intent.ACTION_SCREEN_ON
Intent.ACTION_SCREEN_OFF
Intent.ACTION_USER_PRESENT
My problem is that i want my activity to be shown with the lockscreen not replacing it. Do you guys know how to achieve this?
is there a native-hidden API to do this?
can you guys link me some sample that implement this particular feature?
thanks in advance ;)
I think you might be looking for the Audio Controls "remote view" (RemoteControlClient) API added in Android 4.0 (API level 14). I found the RemoteControlClient API in the Android developer docs that:
enables exposing information meant to be consumed
by remote controls capable of displaying metadata, artwork and media
transport control buttons.
(It was linked off of this page.)
Note: I have never used this API myself, so I apologize if this does not work for you.
You're almost doing it right. Keep doing what you do with the BroadcastReceiver. That's the way to go. For the Window, these are the flags you need to use:
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Do not use FLAG_DISMISS_KEYGAURD
What these flags do: SHOW_WHEN_LOCKED allows your activity to show up on top of the lock screen. FLAG_NOT_TOUCH_MODAL allows touch events that are not on your activity to go to the other activities, ie, allows the user to unlock the screen. FLAG_DISMISS_KEYGUARD gets rid of the lock screen, so we do not use it.
Define this style in your res/values/styles.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.FloatingTranslucent" parent="android:Theme.Translucent.NoTitleBar">
<item name="android:windowIsFloating">true</item>
</style>
</resources>
In your manifest, define your activity's style
<activity android:name=".SampleActivity" android:theme="#style/Theme.FloatingTranslucent">
...
</activity>
What this does is makes your activity completely see through and wrap content.
Now, your activity should be on top of the lock screen, allowing touch input to the lock screen and to your app, with your activity not full size.
Cheers.
Related
I've been making Android apps for a long time and can get them to open in full screen mode on every device except Chromebook. No matter what I do, they only open about half screen and a user has to click the "maximize" button to get them to open further.
Here is the code I use to try to get the apps full screen:
<item name="android:windowFullscreen">true</item>
in the relevant style in themes.xml
as well as
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
in MainActivity's onCreate() method.
I've also tried putting
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
in the application block of AndroidManifest.xml.
Is there something else I can do to get the apps to open full screen on Chromebook?
(I'm using HP Chromebook x360, if that helps)
So there is a section of the Android documentation for using Android on ChromeOS which makes reference to Window Management - Launch Size which seems appropriate.
Quoting from the documentation:
Use a launch size only in desktop environments. This helps the window manager to give you the proper bounds and orientation. To indicate a preferences when used in desktop mode, add the following meta tags inside the <activity>:
<meta-data android:name="WindowManagerPreference:FreeformWindowSize"
android:value="[phone|tablet|maximize]" />
<meta-data android:name="WindowManagerPreference:FreeformWindowOrientation"
android:value="[portrait|landscape]" />
Use static launch bounds. Use inside the manifest entry of your activity to specify a "fixed" starting size. See this example:
<layout android:defaultHeight="500dp"
android:defaultWidth="600dp"
android:gravity="top|end"
android:minHeight="450dp"
android:minWidth="300dp" />
Use dynamic launch bounds. An activity can create and use ActivityOptions.setLaunchBounds(Rect) when creating a new activity. By specifying an empty rectangle, your app can be maximized.
Note: These options work only if the activity started is a root activity. You can also do this using a springboard activity to clear the activity stack in the task with a new start.
Background
Somehow the app "Navbar Apps" allows to customize the background of the nav bar, even if it's not in the foreground, and even not just a simple color.
The problem
I thought it's only possible to change the color of it, and only when the app is in the foreground...
I've seen it on some custom roms, even having special effects when music plays, but I didn't know it's possible to customize it even without a custom rom (or root).
The questions
Is it a hack? How do they change, not just the color of the navigation bar, but even set a background image for it (including dynamic one, for battery status) ?
Is it also possible to change other system bars, like the notification bar?
How does it check which app is in the foreground (needed for deciding when to change the color, based on current app, probably)? Is it a new API ? I thought that the API for getting the foreground activity got deprecated and now doesn't help in any way...
The basic setup is quite easy. Making it into an app will take some work.
You'll need to use the Accessibility APIs, along with WindowManager#addView(...).
Is it a hack?
I can't say I like the idea, but its not exactly a hack.
How do they change, not just the color of the navigation
bar, but even set a background image for it (including dynamic one,
for battery status) ?
Since we're adding a View (or ViewGroup), we have a lot more control.
Is it also possible to change other system bars, like the notification bar?
I'll look into this.
How does it check which app is in the foreground (needed for deciding
when to change the color, based on current app, probably)?
You can use Accessibility APIs to listen for Window level changes (AccessibilityEvent) - this will give you the packageName. Use it as you like.
I'll provide you with some pointers:
Manifest:
permission: SYSTEM_ALERT_WINDOW
accessibility service declaration: <service />
Accessibilityservice
Inflate, initialize & add your layout in: onServiceConnected()
I used TYPE_SYSTEM_OVERLAY with WindowManager#addView(...)
Listen for AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
Override onAccessibilityEvent(AccessibilityEvent); packageName will be available here
Outcome
An example project is hosted here: Link.
I'm looking for the "Android way" of implementing a modal view which interrupts the current flow, and displays another set of screens (more than one). Once done, I'd like to go back to where I was.
I'm actually looking for something similar to the iOS behavior described here.
Is there a standard way of doing it in Android (ICS)?
Thanks!
Ariel
I think the functionality closest to a modal view in iOS would be an Activity with theme set to for example
<activity android:theme="#android:style/Theme.Dialog"/>
or
<activity android:theme="#android:style/Theme.Holo.Dialog"/>
I'm designing a custom Android 4.0 (ICS) device for special purpose.
One of the things I'm looking for is a way to make the Android Launcher, when other activities were previously running, show the last running activity as a transparent, dimmed background, with the launcher icons and widgets on top.
What I'm looking for, is something like this: How do I create a transparent Activity on Android?, except as a modification to Launcher2. I guess I can apply a similar style to the launcher as proposed in that SO, but what about the wallpaper?
AFAIU, the wallpaper is rendered by a separate service, and I still want it rendered if there are no other activities behind the launcher.
Any tips?
I figured this one out myself eventually. It turned out pretty simple.
Just modify the theme as suggested in the mentioned SO-article, and simply change inheritance from the Wallpaper-enabled theme.
Also, there were a small code-snippet that was reactivating the wallpaper. Switch that out, and I've now got a transparent launcher, that shows what's going on behind it.
How can I create a floating window in Android Honeycomb like the one of Calculator or notepad application?
I've tested with
android:theme="#android:style/Theme.Dialog"
and I get a centered transparent activity but the problem is that it isn't movable and hasn't close button.
That calculator you show isn't a part of Android. Also, Android windows don't have close buttons like that. I don't know what you are looking at, but it isn't standard Android in any way shape or form.
AirCalc can do it https://play.google.com/store/apps/details?id=com.myboyfriendisageek.aircalc&hl=en
--Edit
Just to add to my previous answer. It doesn't need to be Custom API provided by device manufacturer as #hackbod mentioned in the above answer.
You can actually write a Service and Add a Layout to the WindowManager and set it to be TYPE_SYSTEM_OVERLAY and there you go, your application is running on top of other applications.