简体   繁体   English

如何在Android中发出类似Facebook Messenger的通知

[英]How to make a Facebook Messenger-like notification like this in Android

I want to implement notifications like the one in the following image. 我想实现下图所示的通知。

Notification appears any time. 通知随时出现。 I think it's of course a background service waiting for new messages from the server then shows this. 我认为这当然是后台服务,等待服务器发出新消息,然后显示此消息。 What I think this is an activity implemented as dialog with this custom UI. 我认为这是使用此自定义UI实施为对话框的活动。 Am I correct? 我对么? And is it a normal startActivity method from the service? 它是服务中的普通startActivity方法吗? And how do I do the transition animation to make it appears slowly from left to right with zooming when show up? 以及如何使过渡动画在显示时通过缩放从左到右缓慢显示?

在此处输入图片说明

Check out this link http://www.piwai.info/chatheads-basics . 查看此链接http://www.piwai.info/chatheads-basics He provides information about how to add them on your screen. 他提供有关如何在屏幕上添加它们的信息。

The trick is to add a View to the WindowManager like following code 诀窍是像下面的代码一样向WindowManager添加View

private WindowManager windowManager;
private ImageView chatHead;

public void addView()
{
  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);
}

Don't forget to add the permission <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> 不要忘记添加权限<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何制作像 Facebook/Messenger 这样的“用户活跃”布局 - How to make a "user active" layout like Facebook/Messenger 如何在android中创建像facebook messenger一样的浮动按钮或窗口 - How to create floating button or window like facebook messenger in android 如何在Android代码中获取类似Facebook的通知? - How to get notification like facebook in android code? ACTION_MOVE上的重叠式布局(类似聊天工具的聊天气泡)退出布局 - Overlay layout (messenger-like chat bubbles) exit layout on ACTION_MOVE Facebook Messenger喜欢活动吗? - Facebook Messenger like Activity? android如何创建一个实时通知的服务(如facebook或whatapps) - android how to create a service that make a notification in real time (like facebook or whatapps) android如何使顶部浮动通知像微信消息通知 - android how to make top float notification like wechat message notification 如何制作自定义“按钮”,例如Android版Facebook - How to make custom “button” like Facebook for Android 以编程方式在 Android java 中显示像 facebook Messenger 这样的 UI - Display UI like facebook messenger in Android java programatically 如何实现Facebook Messenger / Google Hangouts(如布局)以预览ANDROID上搜索栏中的所选项目? - How do I achieve a Facebook Messenger/ Google Hangouts like layout to preview selected items in search bar on ANDROID?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM