0

Current :

Toast toast = Toast.makeText(context, "test", Toast.LENGTH_SHORT).show();

The Toast was showed on Idle Screen. But it does not appear on Lock Screen.

I want to show Toast on Lock Screen. How..?

Rithesh M
  • 1,287
  • 1
  • 12
  • 23
JuL
  • 113
  • 1
  • 7
  • 1
    I don't think you can, at least not with the stock one. That's the whole point of a lock screen. – Mgamerz Feb 04 '13 at 05:13
  • You can try this, but I don't know if it will work: toast.getView().getWindow().addFlags( WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); That's how you do it for a view, it *may* work for a toast if you do it to its view. – Gabe Sechan Feb 04 '13 at 05:20
  • have you tried `PowerManager.ACQUIRE_CAUSES_WAKEUP` option before showing Toast ? – ρяσѕρєя K Feb 04 '13 at 05:20
  • @Gabe: who do you do a ` toast.getView().getWindow()`? there is no such method. – roetzi Feb 23 '13 at 13:05

1 Answers1

1

I meet the same problem. I added TextView to my Activity's View, replacing Android Framework's Toast. That is to say: I implemented Toast by myself.

TextView mCustomToast = (TextView)findViewById(R.id.tv_custom_toast);
/**
 * show custom toast:
 * fix the problem that {@link android.widget.Toast} can't show when screen be 
   locked
 */
private void showCustomToast() {
    if (mCustomToast != null) {
        if (mCustomToast.getVisibility() == View.VISIBLE) {
            return;
        }
        mCustomToast.setVisibility(View.VISIBLE);
        mCustomToast.postDelayed(new Runnable() {
            @Override
            public void run() {
                mCustomToast.setVisibility(View.GONE);
            }
        }, 1000);
    }
}
jerry
  • 11
  • 2