哪些API用于覆盖其他应用程序(如Facebook的Chat Heads)? [英] What APIs are used to draw over other apps (like Facebook's Chat Heads)?

查看:71
本文介绍了哪些API用于覆盖其他应用程序(如Facebook的Chat Heads)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Facebook如何在Android上创建聊天头?在所有其他视图之上创建浮动视图的API是什么?

How does Facebook create the Chat Heads on Android? What is the API to create the floating views on top of all other views?

推荐答案

这个一个:

允许应用程序使用类型打开窗口 TYPE_SYSTEM_ALERT,显示在所有其他应用程序的顶部. 很少有应用程序应使用此许可权.这些窗户是专为 与用户进行系统级交互.

Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications. Very few applications should use this permission; these windows are intended for system-level interaction with the user.

恒定值:"android.permission.SYSTEM_ALERT_WINDOW"

Constant Value: "android.permission.SYSTEM_ALERT_WINDOW"

// 完整代码此处:

public class ChatHeadService extends Service {

  private WindowManager windowManager;
  private ImageView chatHead;

  @Override public IBinder onBind(Intent intent) {
    // Not used
    return null;
  }

  @Override public void onCreate() {
    super.onCreate();

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    chatHead = new ImageView(this);
    chatHead.setImageResource(R.drawable.android_head);

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT);

    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.x = 0;
    params.y = 100;

    windowManager.addView(chatHead, params);
  }

  @Override
  public void onDestroy() {
    super.onDestroy();
    if (chatHead != null) windowManager.removeView(chatHead);
  }
}

别忘了以某种方式启动该服务:

Don't forget to start the service somehow:

startService(new Intent(context, ChatHeadService.class));

..并将此服务添加到清单中.

.. And add this service to your Manifest.

这篇关于哪些API用于覆盖其他应用程序(如Facebook的Chat Heads)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆