Ada*_*atz 10 notifications android
如果您点击通知上的快速回复按钮,我正在尝试创建一个小窗口.在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" />
Run Code Online (Sandbox Code Playgroud)
这是风格:
<style name="Theme.AppCompat.Light.Dialog.custom">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)
现在,当应用程序完全关闭(关闭然后刷掉)时,它可以完美地运行.
但是,如果应用程序只是最小化,当有人点击回复按钮时,它会打开应用程序,然后将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>
Run Code Online (Sandbox Code Playgroud)
也不确定这是否相关,但这是我如何创建回复
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,
0,
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);
Run Code Online (Sandbox Code Playgroud)
要实现您想要的效果,您需要使用android:launchMode具有值的属性singleInstance:
与 相同
"singleTask",只是系统不会在持有实例的任务中启动任何其他活动。该活动始终是其任务的唯一成员。
您还应该添加android:excludeFromRecents="true"将您的活动从最近使用的应用程序列表中排除,如文档所述:
是否应从最近使用的应用程序列表(概览屏幕)中排除由此活动启动的任务。也就是说,当此活动是新任务的根活动时,此属性确定该任务是否不应出现在最近的应用程序列表中。如果任务应从列表中排除,则设置为“true”;如果应该包含它,则设置“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" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
948 次 |
| 最近记录: |