android 4.2的多屏支持 presentation

android presentation实现双屏异显 https://blog.csdn.net/a_lucky_girl/article/details/53885520
Android4.2以后,多屏幕的支持 学习 http://blog.sina.com.cn/s/blog_a6559d920101hoar.html
基于Android 4.4 开发的多窗口系统 开放源码 Android 多窗口 开源
https://blog.csdn.net/ritterliu/article/details/32699125
Android多窗口分屏(原生方法)
https://blog.csdn.net/tangnengwu/article/details/49305599
am stack boxes

am stack create 2 1 4 0.5
Syntax:
am stack create <int1> <int2> <int3> <float1>
<int1>: TASK_ID – the id for the existing task that you want a separate stack for.
<int2>: RELATIVE_STACK_BOX_ID – an existing stack id. The postion of the new stack will be relative to this one.
<int3>: POSITION – the relative position of the stack. Could be any one of these values:
0: before relative stack (depends on RTL/LTR configuration)
1: after relative stack (depends on RTL/LTR configuration)
2: to left of relative stack
3: to right of relative stack
4: above relative stack
5: below relative stack
6: displayed on a higher layer than the relative stack (unused)
7: displayed on a lower layer than the relative stack (unused)
<float1>: WEIGHT – a number between 0.2 – 0.8 inclusive

https://blog.csdn.net/t12x3456/article/details/12527995 4.2特性

权限

<!-- 显示系统窗口权限 -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<!-- 在 屏幕最顶部显示addview-->
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />

2.自定义类 继承Presentation

(Presentation作为Dialog类的扩展,Presentation类提供了一个区域,在其中,您的应用可以在辅助显示屏上显示不同的UI)

public class DifferentDislay extends Presentation{
    public DifferentDislay(Context outerContext, Display display) {
        super(outerContext,display);
        
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
    }
}

3.这段代码就可实现

DisplayManager mDisplayManager;// 屏幕管理类
mDisplayManager = (DisplayManager) this.getSystemService(Context.DISPLAY_SERVICE);
Display[] displays = mDisplayManager.getDisplays();

if (mPresentation == null) {
   mPresentation = new DifferentDislay(this, displays[displays.length - 1]);// displays[1]是副屏

   mPresentation.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
   mPresentation.show();
}

4.如果点击home键,辅屏依然显示内容 可以不写服务就能实现

second = new SecondScreen(getApplicationContext(),
displays[1]);// displays[1]是副屏
second.getWindow().setType(
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
second.show();

说明:getApplicationContext()返回应用的上下文,生命周期是整个应用,应用摧毁它才摧毁

4.如果点击home键,辅屏依然显示内容 就把3中的代码写在服务中(服务在清单中注册哦)然后在调用的地方开启服务

intentService = new Intent(MainActivity.this,FirstService.class);
startService(intentService);

5.服务代码

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.hardware.display.DisplayManager;
import android.os.IBinder;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;


public class HomeService extends Service {
 
// 获取设备上的屏幕
DisplayManager mDisplayManager;// 屏幕管理器
Display[] displays;// 屏幕数组
        DifferentDislay2 mPresentation2;   (继承Presentation)
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@SuppressLint("NewApi")
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
//registerHomeandMenuActionReceiver();// 注册监听home键和菜单键的监听广播
// 双屏异显
mDisplayManager = (DisplayManager) this
.getSystemService(Context.DISPLAY_SERVICE);
displays = mDisplayManager.getDisplays();
showView();
}

@SuppressLint("NewApi")
private void showView(){

if (null == mPresentation2) {

mPresentation2 = new DifferentDislay2(getApplicationContext(),displays[1]);// displays[1]是副屏
mPresentation2.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
mPresentation2.show();
   
Toast.makeText(getApplicationContext(), "哈哈哈哈哈", 1000).show();
}

}  
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值