android oreo上的永久服务

Android 8的电池消耗改进对用户来说很好,但是如果我的服务能按预期工作,我有点害怕。 首先:感谢您提出任何建议,但我不能只安排我的服务。 我希望一直在后台运行一个类似OK Google的关键词监听器。 它将基于开源的pocketsphinx-android库。 我知道这会消耗很多电池电量,我会告诉用户这个。 我们可以在android 8+上创建永久后台服务吗? 我需要在gradle中定位android 8,因为我期待一些旧目标的bug。 我也不想使用前台服务来惹恼用户,该服务会在状态栏中永久显示通知。 [ https://developer.android.com/about/versions/oreo/background.html] – 是否真的无法为我的用例(但最好是所有用例)提供永久性后台服务?

Java中的通用构建器

我为查找表创建了一个构建器并使用它,如下所示。 public class RaceCodeDataBuilder { private RaceCode raceCode; public RaceCodeDataBuilder() { raceCode = new RaceCode(); } public RaceCodeDataBuilder code(String code) { raceCode.setCode(code); return this; } public RaceCodeDataBuilder displayName(String displayName) { raceCode.setDisplayName(displayName); return this; } public RaceCode build() { return raceCode; } } 在测试中使用此构建器: RaceCode mockRaceCode = new RaceCodeDataBuilder() .code(“2054-5”) .displayName(“Black or African American”) .build(); 我期待更多类似的构建器用于其他查找表,例如StateCodeBuilder,GenderCodeBuilder,并且它们都只有“code”和“displayName”,类似于上面的构建器。 […]

如何清除ResourceBundle缓存

这是使用Guice在Tomcat上运行的webapp。 根据文档,我们应该能够调用ResourceBundle.clearCache(); 清除ResourceBundle缓存并可能从bundle属性文件中获取最新信息。 我们还尝试了以下方法: Class klass = ResourceBundle.getBundle(“my.bundle”).getClass().getSuperclass(); Field field = klass.getDeclaredField(“cacheList”); field.setAccessible(true); ConcurrentHashMap cache = (ConcurrentHashMap) field.get(null); cache.clear(); // If i debug here I can see the cache is now empty! 和 ResourceBundle.clearCache(this.class.getClassLoader()); 我期待的行为是: 启动tomcat并点击页面,然后显示“Hello World” 将包含“Hello World”的属性文件更改为“Goodbye Earth” 使用servlet清除缓存 点击页面,期待看到’Goodbye Earth’ 所以问题是,ResourceBundle.clearCache()实际上是如何工作的? 还有一些我们需要清除的通用文件缓存吗?

有没有办法配置Struts绑定null而不是空String?

当用户决定将表单中的字段保留为空时,Apache Struts将空String绑定为ActionForm属性的值。 有没有办法全局修改行为并选择null而不是空String ? 我知道Spring MVC完全相同,但也有StringTrimmerEditor可以注册为属性编辑器将字符串修剪为null 。

通用堆栈数组

我必须实现一个通用堆栈,但是当我尝试构建项目时,我遇到了一个我无法弄清楚的错误。 这是代码: Stack.java – >接口 package stack; public interface Stack { public boolean isEmpty(); public boolean isFull(); public void push(T x) throws StackFullException; public boolean offer(T x); public T pop() throws StackEmptyException; public T poll(); public T peek() throws StackEmptyException; public T element(); } StackArray.java – >接口的实现 package stack; public class StackArray implements Stack { […]

pdf解析为java中的文本

我有一个阿拉伯语PDF,我想用Java将其解析为文本文档。 我已经尝试了很多次,英语单词解析成功,但阿拉伯语单词没有。 任何人都可以推荐一个能够正确转换阿拉伯语单词的解决方案吗?

如何使用solrj将一个文档添加到solr索引?

我可以使用以下代码重新索引整个solr核心: public void indexSolr() throws SolrServerException, IOException { HttpSolrServer solr = new HttpSolrServer(solrIndexPath); logger.info(“Indexing fcv solr at ” + solrIndexPath); // reindex to pickup new articles ModifiableSolrParams params = new ModifiableSolrParams(); params.set(“qt”, “/” + solrDataImportPath); params.set(“command”, “full-import”); params.set(“clean”, “true”); params.set(“commit”, “true”); solr.query(params); } 如何只将一个文档插入索引而不必索引整个文档?

使用Intents将数据结果返回到父活动

我能够成功地将我的第一个Activity中的ListView中的字符串传输到第二个Activity中的EditText 。 我现在想要编辑文本并将其发回以在我的第一个Activity中更新我的ListView 。 我基本上希望将编辑作为弹出窗口发送回第一个活动,以帮助我测试哪个字符串被传回 我不确定在onActivityResult()放入什么Intent: protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) { String name = data.getExtras().getString(“name”); Toast.makeText(this, name, Toast.LENGTH_SHORT).show(); } } 这是我的第一个活动: public class ToDoActivity extends Activity { private ArrayList todoItems; private ArrayAdapter todoAdapter; // declare array adapter which will translate the piece […]

onPostExecute()中的ArrayList空指针exception

在ArrayList中获取NullPointerException 。 我正在使用下面的行来记录ArrayList的大小,但我总是得到NPE。 可能是什么原因? Log.d(“catArrayList:Size:New”, “”+categoryArrayList.size()); 这是一些更多的代码: protected void onPostExecute(Boolean result) { dialog.cancel(); Log.d(“catArrayList:Size”, “”+categoryArrayList.size()); Log.d(“typArrayList:Size”, “”+typeArrayList.size()); Log.d(“serArrayList:Size”, “”+serviceArrayList.size()); Log.d(“cArrayList:Size”, “”+cArrayList.size()); Log.d(“tArrayList:Size”, “”+tArrayList.size()); Log.d(“sArrayList:Size”, “”+sArrayList.size()); Category c = categoryArrayList.get(0); typeArrayList = c.getTypeArrayList(); Log.d(“catArrayList:Size:New”, “”+categoryArrayList.size()); for(int i=0;i<typeArrayList.size();i++) { tArrayList.add(typeArrayList.get(i).getName()); } spinner1.setAdapter(new ArrayAdapter(CategoryActivity.this, android.R.layout.simple_spinner_dropdown_item, cArrayList)); spinner2.setAdapter(new ArrayAdapter(CategoryActivity.this, android.R.layout.simple_spinner_dropdown_item, tArrayList)); spinner3.setAdapter(new ArrayAdapter(CategoryActivity.this, android.R.layout.simple_spinner_dropdown_item, sArrayList)); } 日志说: 09-12 11:05:54.585: […]

如果可能,将jFrame输出到第二个监视器

我有一个关于Java的Swing的jFrame,如果这个监视器存在,我希望它输出到第二个监视器。 我尝试了这个(通过这个页面)来获得显示的分辨率 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (int j = 0; j < gs.length; j++) { GraphicsConfiguration[] gc = gs[j].getConfigurations(); for (int i = 0; i < gc.length; i++) { Rectangle gcBounds = gc[i].getBounds(); int xoffs = gcBounds.x; int yoffs = gcBounds.y; } } 但后来我在调试器中看到xoffs和yoffs为我的第一台显示器(1360 * 768)xoffs = 1360和yoffs = 0秒显示器(1280 […]