I Want To Show Gif Image Show On Screen Even When App Is Closed
With a mouse click, you implement two things: Sound is playing The GIF image is showing I'm trying to show the GIF on the screen even when I close the app I'm using the service
Solution 1:
According to your requirement you need to implement system window alert in service class to show image in background when the app is closed
This is the solution for your requirement.
In manifest
add this
<uses-permissionandroid:name="android.permission.SYSTEM_ALERT_WINDOW" />
Then in your launcher activity
or any base activity add these permissions
privatestaticfinalint CODE_DRAW_OVER_OTHER_APP_PERMISSION = 2084;
In onCreate()
add this
if (SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
Intentintent=newIntent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, CODE_DRAW_OVER_OTHER_APP_PERMISSION);
//finish();
}
Handle the request permission
@OverridepublicvoidonActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CODE_DRAW_OVER_OTHER_APP_PERMISSION) {
if (SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
Intentintent=newIntent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, CODE_DRAW_OVER_OTHER_APP_PERMISSION);
} else {
// do stuff here
}
}
}
and do this in service
class check the link below and do your stuff respectively
https://medium.com/@kevalpatel2106/create-chat-heads-like-facebook-messenger-32f7f1a62064
where image_layout
. xml is
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><pl.droidsonroids.gif.GifImageViewandroid:id="@+id/catgif"android:layout_width="match_parent"android:layout_height="match_parent"android:src="@drawable/ic_launcher_background"android:background="@android:color/holo_blue_dark"
/></android.support.constraint.ConstraintLayout>
Update:- You can make changed in image_layout file to show your GIF any size and gravity in the screen You can make changes with
android:layout_width="any_size"
android:layout_height="any_size"
Post a Comment for "I Want To Show Gif Image Show On Screen Even When App Is Closed"