如果您点击通知上的快速回复按钮,我正在尝试创建一个小窗口打开.在WhatsApp中,它打开了一个半屏幕窗口.目前我正在做以下事情:

我打开一个名为NotificationActivity的活动.在AndroidManifest.xml中,我将活动注册为

<activity
    android:name=".activity.NotificationActivity"
    android:theme="@style/Theme.AppCompat.Light.Dialog.custom"
    android:label="@string/title_activity_notification"
    android:screenorientation="portrait"
    android:windowSoftInputMode="adjustResize|stateHidden" />

这是风格:

<style name="Theme.AppCompat.Light.Dialog.custom">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

现在,当应用程序完全关闭(关闭然后滑开),它的工作完美.

但是,如果应用程序被最小化,当有人点击回复按钮时,它会打开应用程序,然后在其上粘贴NotificationActivity.如何防止应用程序在后台打开,只有半屏幕通知活动被打开.

非常感谢

编辑:我在想,也许xml文件是相关的?

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="300dp"
    android:layout_marginTop="15dp"
    android:background="@color/white"
    android:orientation="vertical"
    android:paddingTop="12dp"
    android:weightSum="20">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/lvChat"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="10"
            android:background="@android:color/transparent"
            android:cacheColorHint="@android:color/transparent"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:listSelector="@android:color/transparent"
            android:scrollbars="none"
            android:stackFromBottom="false"
            android:transcriptMode="alwaysScroll"/>

        <LinearLayout
            android:id="@+id/chatFooter"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ECEFF1"
            android:orientation="horizontal">

            <LinearLayout
                android:id="@+id/sendLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center_vertical"
                android:paddingBottom="@dimen/scale_5dp"
                android:paddingTop="@dimen/scale_5dp"
                android:weightSum="2">

                <LinearLayout
                    android:layout_width='0dp'
                    android:layout_height="wrap_content"
                    android:layout_weight="1.8">

                    <com.heyjude.heyjudeapp.customview.EditRobotoRegular
                        android:id="@+id/editchatMsg"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/linear_back"
                        android:hint="Type your message..."
                        android:imeOptions="actionSend"
                        android:inputType="textMultiLine|textCapSentences|text"
                        android:padding="@dimen/scale_5dp"
                        android:textColor="#5f6060"
                        android:textColorHint="#5f6060"
                        android:textSize="@dimen/text_14"/>
                </LinearLayout>

                <ImageButton
                    android:id="@+id/ivSend"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.3"
                    android:background="@android:color/transparent"
                    android:src="@drawable/ic_chat_icon"/>

            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@color/grey_list"
            android:gravity="center"
            android:orientation="horizontal"
            android:weightSum="2">

            <Button
                android:id="@+id/buttonView"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="View"
                android:textAllCaps="false"
                android:textSize="@dimen/text_22"/>

            <Button
                android:id="@+id/buttonCancel"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="Cancel"
                android:textAllCaps="false"
                android:textSize="@dimen/text_22"/>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

还不知道这是否相关,但这里是如何创建回复

String KEY_TEXT_REPLY = "key_text_reply";
String replyLabel = "Type here";
Intent intent = new Intent(context,NotificationActivity.class);
intent.putExtra(Constants.REQUEST_ID,messageData.taskid);
intent.putExtra(Constants.JUDE_ID,messageData.from);
intent.putExtra(Constants.FROM,Constants.NOTIFICATION);

PendingIntent pendingIntent = PendingIntent.getActivity(
                context,intent,PendingIntent.FLAG_UPDATE_CURRENT);

RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY)
        .setLabel(replyLabel)
        .build();

NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
                R.drawable.send_button,"Reply",pendingIntent)
                .addRemoteInput(remoteInput)
                .build();

builder.addAction(replyAction);

解决方法

要实现你想要的,你需要使用属性 android:launchMode的值为singleInstance:

Same as "singleTask",except that the system doesn’t launch any other
activities into the task holding the instance. The activity is always
the single and only member of its task.

您还应该添加android:excludeFromrecents =“true”,以将您的活动从最近使用的应用程序列表中排除,如documentation所述:

Whether or not the task initiated by this activity should be excluded
from the list of recently used applications,the overview screen. That
is,when this activity is the root activity of a new task,this
attribute determines whether the task should not appear in the list of
recent apps. Set “true” if the task should be excluded from the list;
set “false” if it should be included. The default value is “false”.

总而言之,您需要更改您的AndroidManifest.xml,如下所示:

<activity
    android:name=".activity.NotificationActivity"
    android:theme="@style/Theme.AppCompat.Light.Dialog.custom"
    android:label="@string/title_activity_notification"
    android:screenorientation="portrait"
    android:windowSoftInputMode="adjustResize|stateHidden"
    android:launchMode="singleInstance"
    android:excludeFromrecents="true" />

android – 尝试创建Whatsapps快速回复前N个手机的更多相关文章

  1. HTML5自定义视频播放器源码

    这篇文章主要介绍了HTML5自定义视频播放器源码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  2. HTML5自定义mp3播放器源码

    这篇文章主要介绍了HTML5自定义mp3播放器源码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  3. html5自定义video标签的海报与播放按钮功能

    这篇文章主要介绍了html5自定义video标签的海报与播放按钮功能,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  4. CSS中实现动画效果-附案例

    这篇文章主要介绍了 CSS中实现动画效果并附上案例代码及实现效果,就是CSS动画样式处理,动画声明需要使用@keyframes name,后面的name是人为定义的动画名称,下面我们来看看文章的具体实现内容吧,需要的小伙伴可以参考一下

  5. h5页面背景图很长要有滚动条滑动效果的实现

    这篇文章主要介绍了h5页面背景图很长要有滚动条滑动效果的实现,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  6. html5 canvas合成海报所遇问题及解决方案总结

    这篇文章主要介绍了html5 canvas合成海报所遇问题及解决方案总结,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  7. html5借用repeating-linear-gradient实现一把刻度尺(ruler)

    这篇文章主要介绍了html5借用repeating-linear-gradient实现一把刻度尺,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  8. 如何在Canvas中添加事件的方法示例

    这篇文章主要介绍了如何在Canvas中添加事件的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  9. HTML5自定义元素播放焦点图动画的实现

    这篇文章主要介绍了HTML5自定义元素播放焦点图动画的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  10. 有关HTML5页面在iPhoneX适配问题

    这篇文章主要介绍了有关HTML5页面在iPhoneX适配问题,需要的朋友可以参考下

随机推荐

  1. bluetooth-lowenergy – Altbeacon库无法在Android 5.0上运行

    昨天我在Nexus4上获得了Android5.0的更新,并且altbeacon库停止了检测信标.似乎在监视和测距时,didEnterRegion和didRangeBeaconsInRegion都没有被调用.即使RadiusNetworks的Locate应用程序现在表现不同,一旦检测到信标的值,它们就不再得到更新,并且通常看起来好像信标超出了范围.我注意到的一点是,现在在logcat中出现以下行“B

  2. android – react-native动态更改响应者

    我正在使用react-native进行Android开发.我有一个视图,如果用户长按,我想显示一个可以拖动的动画视图.我可以使用PanResponder实现这一点,它工作正常.但我想要做的是当用户长按时,用户应该能够继续相同的触摸/按下并拖动新显示的Animated.View.如果您熟悉Google云端硬盘应用,则它具有类似的功能.当用户长按列表中的任何项目时,它会显示可拖动的项目.用户可以直接拖

  3. android – 是否有可能通过使用与最初使用的证书不同的证书对其进行签名来发布更新的应用程序

    是否可以通过使用与最初使用的证书不同的证书进行签名来发布Android应用程序的更新?我知道当我们尝试将这样的构建上传到市场时,它通常会给出错误消息.但有没有任何出路,比如将其标记为主要版本,指定市场中的某个地方?解决方法不,你不能这样做.证书是一种工具,可确保您是首次上传应用程序的人.所以总是备份密钥库!

  4. 如何检测Android中是否存在麦克风?

    ..所以我想在让用户访问语音输入功能之前检测麦克风是否存在.如何检测设备上是否有麦克风.谢谢.解决方法AndroidAPI参考:hasSystemFeature

  5. Android – 调用GONE然后VISIBLE使视图显示在错误的位置

    我有两个视图,A和B,视图A在视图B上方.当我以编程方式将视图A设置为GONE时,它将消失,并且它正下方的视图将转到视图A的位置.但是,当我再次将相同的视图设置为VISIBLE时,它会在视图B上显示.我不希望这样.我希望视图B回到原来的位置,这是我认为会发生的事情.我怎样才能做到这一点?编辑–代码}这里是XML:解决方法您可以尝试将两个视图放在RelativeLayout中并相对于彼此设置它们的位置.

  6. android – 获得一首歌的流派

    我如何阅读与歌曲相关的流派?我可以读这首歌,但是如何抓住这首歌的流派,它存放在哪里?解决方法检查此代码:

  7. android – 使用textShadow折叠工具栏

    我有一个折叠工具栏的问题,在展开状态我想在文本下面有一个模糊的阴影,我使用这段代码:用:我可以更改textColor,它可以工作,但阴影不起作用.我为阴影尝试了很多不同的值.是否可以为折叠文本投射阴影?

  8. android – 重用arm共享库

    我已经建立了armarm共享库.我有兴趣重用一个函数.我想调用该函数并获得返回值.有可能做这样的事吗?我没有任何头文件.我试过这个Android.mk,我把libtest.so放在/jni和/libs/armeabi,/lib/armeabi中.此时我的cpp文件编译,但现在是什么?我从objdump知道它的名字编辑:我试图用这个android.mk从hello-jni示例中添加prebuild库:它工作,但libtest.so相同的代码显示以下错误(启动时)libtest.so存在于libhello-j

  9. android – 为NumberPicker捕获键盘’Done’

    我有一个AlertDialog只有一些文本,一个NumberPicker,一个OK和一个取消.(我知道,这个对话框还没有做它应该保留暂停和恢复状态的事情.)我想在软键盘或其他IME上执行“完成”操作来关闭对话框,就像按下了“OK”一样,因为只有一个小部件可以编辑.看起来处理IME“Done”的最佳方法通常是在TextView上使用setonEditorActionListener.但我没有任何Te

  10. android – 想要在调用WebChromeClient#onCreateWindow时知道目标URL

    当我点击一个带有target=“_blank”属性的超链接时,会调用WebChromeClient#onCreateWindow,但我找不到新的窗口将打开的新方法?主页url是我唯一能知道的东西?我想根据目标网址更改应用行为.任何帮助表示赞赏,谢谢!

返回
顶部