如果您单击通知上的快速回复按钮,我会尝试创建一个小窗口来打开它。在 WhatsApp 中,它会打开一个半屏窗口。目前我正在做以下事情:
我打开了一个名为 NotificationActivity 的 Activity 。在 AndroidManifest.xml 中,我将 Activity 注册为
<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 粘贴到上面。如何防止应用程序在后台打开并且只打开半屏通知 Activity 。
非常感谢
编辑:我在想也许 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,
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);
最佳答案
要实现您想要的效果,您需要使用属性 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" 以将您的 Activity 从最近使用的应用程序列表中排除,如 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 - 尝试为前置和手机创建 Whatsapp 快速回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39344133/
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
如何使用RSpec::Core::RakeTask初始化RSpecRake任务?require'rspec/core/rake_task'RSpec::Core::RakeTask.newdo|t|#whatdoIputinhere?endInitialize函数记录在http://rubydoc.info/github/rspec/rspec-core/RSpec/Core/RakeTask#initialize-instance_method没有很好的记录;它只是说:-(RakeTask)initialize(*args,&task_block)AnewinstanceofRake
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion为什么SecureRandom.uuid创建一个唯一的字符串?SecureRandom.uuid#=>"35cb4e30-54e1-49f9-b5ce-4134799eb2c0"SecureRandom.uuid方法创建的字符串从不重复?
我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie
我正在阅读SandiMetz的POODR,并且遇到了一个我不太了解的编码原则。这是代码:classBicycleattr_reader:size,:chain,:tire_sizedefinitialize(args={})@size=args[:size]||1@chain=args[:chain]||2@tire_size=args[:tire_size]||3post_initialize(args)endendclassMountainBike此代码将为其各自的属性输出1,2,3,4,5。我不明白的是查找方法。当一辆山地自行车被实例化时,因为它没有自己的initialize方法
我正在尝试按0-9和a-z的顺序创建数字和字母列表。我有一组值value_array=['0','1','2','3','4','5','6','7','8','9','a','b','光盘','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','','u','v','w','x','y','z']和一个组合列表的数组,按顺序,这些数字可以产生x个字符,比方说三个list_array=[]和一个当前字母和数字组合的数组(在将它插入列表数组之前我会把它变成一个字符串,]current_combo['0','0','0']