Android - How to display a dialog over a native screen?
For my application I used an activity with the Dialog
theme.
You can declare the theme in the manifest file :
<activity android:name="PopupActivity"
android:launchMode="singleInstance" android:excludeFromRecents="true"
android:taskAffinity="" android:theme="@android:style/Theme.Dialog" />
- use
launcheMode="singleInstance"
andtaskAffinity=""
if your popup is detached from your main application. Otherwise user may click the back button and return to the previous activity of your application. excludeFromRecents="true"
to avoid your popup to appear in recent tasks (long press home)theme="@android:style/Theme.Dialog"
to set the Dialog theme.
How to display dialog on any screen (fragment or activity) in android
Create a transparent activity and in its onCreate method show your dialog.
Set an OnDismissListener for the dialog and in this callback finish the activity.
Every where you need showing your dialog you can start this transparent activity
Show dialog with touch events over lockscreen in Android 2.3
I do not think you can launch an activity each time when device is locked without binding your application as admin privilaged app programatically.
Once your app is admin privilaged app, you can programatically set password & lock the screen & then programatically unlock it using Device Policy Manager.
On top of that lock screen you can programatically launch your own activity & you can create your own unlocker & unlock device through that activity as you can get call backs via DeviceAdminReceiver.
Here is a good example for that & all you need is to create your own activity after you called DevicePolicyManager.lockNow(). Then it will appear on top of lock screen as normal activity plus extra control over native lockscreen.
Showing a screen like the native incoming call screen in Android
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.
Displaying an android dialog out of application
The answer is in this thread:
Android - How to display a dialog over a native screen?
Related Topics
Http Post Method Passing Null Values to the Server
How to Implement a Gcm Hello World for Android Using Android Studio
Android: How to Get Current Opened Application Name on Screen
Gradle 0.9.+/0.9.2 Error: Unable to Load Class 'Com.Android.Builder.Testing.Api.Deviceprovider'
Broadcast Receiver Not Working in Ics If the App Is Not Started Atleast Once
How to Change Images on Imageview After Some Interval
Why Is My Field 'Null' After Injection? How to Inject My Object
Android SQLite Selection Args[] with Int Values
How to Create Custom Shape Button with Selector in Android
Out of Memory Exception Due to Large Bitmap Size
Embed Activity Feed of a Public Facebook Page Without Forcing User to Login/Allow
Getactionview() of My Menuitem Return Null
Android Google Maps V2: How to Add Marker with Multiline Snippet
How to Cast Action Provider to Share Action Provider
Change Navigationview Items When User Is Logged