提交 5e4633f3 编写于 作者: 董重

新建FloatingImageDisplayService

上级 b05018e1
......@@ -18,7 +18,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".FloatingWindowService"></service>
<service android:name=".FloatingButtonService"></service>
<service android:name=".FloatingImageDisplayService"></service>
</application>
</manifest>
\ No newline at end of file
......@@ -19,7 +19,7 @@ import android.widget.Button;
* Created by dongzhong on 2018/5/30.
*/
public class FloatingWindowService extends Service {
public class FloatingButtonService extends Service {
private WindowManager windowManager;
private WindowManager.LayoutParams layoutParams;
......
package dongzhong.testforfloatingwindow;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.view.WindowManager;
/**
* Created by dongzhong on 2018/5/30.
*/
public class FloatingImageDisplayService extends Service {
private WindowManager windowManager;
private WindowManager.LayoutParams layoutParams;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
......@@ -23,17 +23,26 @@ public class MainActivity extends AppCompatActivity {
Toast.makeText(this, "授权失败", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "授权成功", Toast.LENGTH_SHORT).show();
startService(new Intent(MainActivity.this, FloatingWindowService.class));
startService(new Intent(MainActivity.this, FloatingButtonService.class));
}
}
}
public void startFloatingService(View view) {
public void startFloatingButtonService(View view) {
if (!Settings.canDrawOverlays(this)) {
Toast.makeText(this, "当前无权限,请授权", Toast.LENGTH_SHORT);
startActivityForResult(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())), 1111);
} else {
startService(new Intent(MainActivity.this, FloatingWindowService.class));
startService(new Intent(MainActivity.this, FloatingButtonService.class));
}
}
public void startFloatingLayoutService(View view) {
if (!Settings.canDrawOverlays(this)) {
Toast.makeText(this, "当前无权限,请授权", Toast.LENGTH_SHORT);
startActivityForResult(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())), 1111);
} else {
startService(new Intent(MainActivity.this, FloatingButtonService.class));
}
}
}
......@@ -8,7 +8,13 @@
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start floating service"
android:onClick="startFloatingService" />
android:text="start floating button"
android:onClick="startFloatingButtonService" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start floating layout"
android:onClick="startFloatingLayoutService"/>
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册