android – 尝试创建Whatsapps快速回复前N个手机

前端之家收集整理的这篇文章主要介绍了android – 尝试创建Whatsapps快速回复前N个手机前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果您点击通知上的快速回复按钮,我正在尝试创建一个小窗口打开.在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" />
原文链接:https://www.f2er.com/android/312526.html

猜你在找的Android相关文章