To implement a pop-up notification similar to WhatsApp, you can use a combination of a transparent Activity and a WindowManager to create a floating view. Here's a simplified example:
1. **Create a transparent Activity:**
Set your activity theme to a transparent one in the AndroidManifest.xml file:
```xml
<activity android:name=".YourPopupActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<!-- other activity configurations -->
</activity>
```
2. **Layout for YourPopupActivity:**
Create a layout for your popup. This could be a simple layout containing the views you want in the popup.
3. **Code for YourPopupActivity:**
In your activity, set the layout, and adjust window parameters:
```java
public class YourPopupActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_popup_layout);
// Adjust window parameters
WindowManager.LayoutParams params = getWindow().getAttributes();
params.gravity = Gravity.TOP | Gravity.START;
params.x = 0;
params.y = 0;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
getWindow().setAttributes(params);
}
}
```
4. **Show the Popup:**
Wherever you want to show the popup (e.g., on a button click), start your transparent activity:
```java
Intent intent = new Intent(context, YourPopupActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
```
Remember to handle permissions (e.g., SYSTEM_ALERT_WINDOW) and be cautious with floating views for a good user experience. FM WhatsApp APK
Regarding showing the popup even when the device is locked, you might need to use a combination of flags, permissions, and possibly Device Administration APIs, depending on the Android version and security settings. Keep in mind that accessing the screen while the device is locked may have security implications and may not be allowed in certain scenarios. Always consider user privacy and security when implementing such features.