2

I'm writing an application that receives messages in the background using a service. I would like to display a screen similar to the native incoming call screen (a screen that shows above everything else, even if the device is locked). Currently the app just controls a widget that's on both the lockscreen and home screen, but having a more native looking activity would be good.

I have already tried a dialog activity. It kind of does what I need, but it does not show in the lock screen and due to my starting it from a background service, shows the main activity behind it.

4

1 回答 1

5

I found a solution to this for anybody who may stumble across this in the future. Create an activity to show your screen, then add the following to the activity class:

public class DialogActivity extends Activity
{
    /**
     * Tag for this class to be used when logging.
     */
    public static final String TAG = "DialogActivity";

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // Set the window to always display on the forefront and to be opened when locked
        Window oWindow = this.getWindow();

        oWindow.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                         + WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                         + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        // Set our layout
        this.setContentView(R.layout.activity_dialog);

This appears to have the desired effect. Setting the activity's theme to be full screen also helps create an even more similar experience to the ringer.

于 2013-09-25T10:12:40.910 回答