简体   繁体   English

使用cca Google Chrome应用时,从后台服务中触发Chrome警报

[英]Fire Chrome Alarms from background service when using cca Google Chrome apps

Experimenting with Mobile Chrome apps API: ( https://github.com/MobileChromeApps/mobile-chrome-apps ) 尝试使用移动Chrome应用API:( https://github.com/MobileChromeApps/mobile-chrome-apps

What I'm trying to achieve is the registering of my chrome alarms without having to crudely start the apps' main activity as this causes a bad user experience. 我想要实现的是注册我的chrome警报而不必粗暴地启动应用程序的主要活动,因为这会导致糟糕的用户体验。

The challenge: I have specified a chome.alarm which gets successfully registered when I open the app ('cca run android ' for example). 挑战:我已经指定了一个chome.alarm,它在我打开应用程序时成功注册(例如'cca run android')。 These alarms are specified in a background.js file, which is declared as a background script in the manifest.json file. 这些警报在background.js文件中指定,该文件在manifest.json文件中声明为后台脚本。

I wanted these to be registered automatically on boot, therefore I implemented a background service and thought I could simply call the app to register the alarms specified in the background.js file. 我希望这些在引导时自动注册,因此我实现了后台服务,并认为我可以简单地调用应用程序来注册background.js文件中指定的警报。 However, the only way I can find thus far to achieve this, is via a call to launch the apps main activity via an Intent from within the background service as explained in more detail below. 然而,到目前为止我能找到的唯一方法是通过调用从后台服务中通过Intent启动应用程序主要活动,如下面更详细的解释。

On boot , my background service simply invokes: 在启动时 ,我的后台服务只是调用:

//Launch main activity..
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.company.appname");
startActivity(LaunchIntent);

The above launches the app into its main activity and the aforementioned chrome.alarms are registered as desired. 以上内容将应用程序启动到其主要活动中,并根据需要注册上述chrome.alarms。 Happy days! 快乐的时光! A massive downside to this, of course, is that no user wants the full blown main activity window to open on boot. 当然,一个巨大的缺点是没有用户希望在启动时打开完整的主活动窗口。

Please advise if there is a less clunky way to have the chrome.alarm specified in background.js registered at boot by a background thread. 请告知是否有一个不太笨重的方法来在后台线程启动时在后台注册的background.js中指定chrome.alarm。 I do not wish to open the mainActivity of the app, yet this is currently the only way thus far I can see to get them to be registered. 我不想打开应用程序的mainActivity,但这是迄今为止我能看到的唯一方式来让它们注册。 It is preferable not to register these alarms from within the Android SDK as I intend to stay as close to using web APIs and want to use background.js as the hook to do this keeping things in-line with chrome web apps as-well-as the android platform. 最好不要在Android SDK中注册这些警报,因为我打算保持尽可能接近使用Web API,并且希望使用background.js作为钩子来实现这一点,以保证与Chrome网络应用程序保持一致。作为Android平台。

What I have done: 我做了什么:

A cca (chrome mobile web app) app which registers a background service natively (I extend BackgroundService) as a plugin and register this to run at boot time. 一个cca(chrome移动网络应用程序)应用程序,它本地注册后台服务(我扩展BackgroundService)作为插件并注册它以在启动时运行。 This is the only 'native android code' in order to load the app at boot-time. 这是唯一的“本机安卓代码”,以便在启动时加载应用程序。

Upon booting android, this background service then simply issues a startActivity(LaunchIntent) in order to open the app. 在启动android时,这个后台服务然后只是发出一个startActivity(LaunchIntent)来打开应用程序。 In doing so, my chrome.alarm specified in my background.js file get registered successfully. 这样做,我的background.js文件中指定的chrome.alarm成功注册。 If I don't do this, my chrome alarm specified in background.js do not get registered until I manually open the apps main activity. 如果我不这样做,在我手动打开应用程序主要活动之前,我在background.js中指定的chrome警报不会被注册。 Therefore I use the backgroundService to open the apps main activity. 因此,我使用backgroundService打开应用程序主要活动。 This is not at all ideal, I would simply like to somehow have my chrome.alarms registered without crudely having to launch the apps main activity window. 这根本不是理想的,我只是想以某种方式注册我的chrome.alarms而不必粗暴地启动应用程序主活动窗口。

Is there a call which I can place in my BackgroundService to have only the chrome.alarms contained in my background.js file read and registered to fire? 是否有一个调用我可以放在我的BackgroundService中,只有我的background.js文件中包含的chrome.alarms读取和注册才能触发? Thank you for your time. 感谢您的时间。

First, thanks for using Chrome Apps for Mobile! 首先,感谢您使用Chrome Apps for Mobile! (Note: I work on the project) (注意:我在项目上工作)

Sorry that our current bootstrap is "crude" and "clunky", and we agree that it is. 对不起,我们目前的引导程序是“粗糙”和“笨重”,我们同意它是。 You can track this issue for progress on our effort to replace our current Background-scripts-embedded-in-main-Activity-webview strategy with a real background service and multiple window support. 您可以跟踪此问题 ,以便我们使用真实的后台服务和多窗口支持替换当前的Background-scripts-embedded-in-main-Activity-webview策略。 Basically you've summarized exactly our plan and existing limitations. 基本上,您已经完全概括了我们的计划和现有限制。

This work is actually scheduled for the near term, and will certainly be done before the end of the year. 这项工作实际上是在近期安排的,并且肯定会在今年年底之前完成。

As well as chrome.alarms , this feature is quite important for chrome.gcm and chrome.tcpServer (among other reasons). chrome.alarms ,此功能对chrome.gcmchrome.tcpServer非常重要(除其他原因外)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Chrome Apps Developer Tool cca说背景,不支持全屏权限 - Chrome Apps Developer Tool cca says background, fullscreen permissions not supported 从后台页面获取正在运行的Chrome应用 - get the running chrome apps from background page 从命令行启动谷歌应用程序时,不要打开谷歌浏览器浏览器 - When launching google apps from command line , don't want to open google chrome browser Google Chrome应用程式:chrome.storage.local - Google Chrome Apps: chrome.storage.local Google Sheets API和Chrome应用 - Google Sheets API and Chrome Apps 是否可以使用免费的Google Apps订阅来限制对Chrome扩展程序的访问? - Is it possible to restrict access to Chrome extension using free Google Apps subscription? 如何使用以下方式允许弹出窗口和重定向 <webview> 在Google Chrome应用中? - How to allow popup windows and redirects using <webview> in Google Chrome Apps? 减少Cordova Chrome应用(cca)APK大小 - Reduce Cordova Chrome App (cca) APK Size Chrome应用程序:当我运行cca create时,我得到:找不到模块&#39;delayed-stream&#39; - Chrome App: When I run cca create I get: Cannot find module 'delayed-stream' Google Chrome套餐应用:如何制作透明的圆形背景,例如google hangout app? - Google Chrome Package Apps : How to make transparent rounded background like google hangout app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM