Phonegap - 从背景到前景 [英] Phonegap - Bring from background to foreground

查看:27
本文介绍了Phonegap - 从背景到前景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发我的团队以及一个必须在后台运行的应用程序,当套接字调用的事件应将应用程序置于前台时.

I'm developing my team along with an application that must run in the background when an event called by sockets should put the application in the foreground .

应用程序必须像 viber 或 whatsapp 调用一样进入前台.我停在了这一点上.我的应用程序现在可以调用音频和振动,但我必须将屏幕绘制到前景.

The application must come to foreground similar to viber or whatsapp call. I stopped at this point. My application can now call an audio and vibrate, but I have to draw the screen to the foreground.

我使用的是 5.1.1 版 phonegap.

I'm using version 5.1.1 phonegap.

我是这个插件:https://github.com/katzer/cordova-plugin-背景模式

有人可以帮我吗?已经非常感谢了.

Could someone give me a hand? Very grateful this already.

推荐答案

我找到了方法!使用toForeground"插件.https://github.com/caioladislau/cordova-toforeground

I found a way! Using the "toForeground" plugin. https://github.com/caioladislau/cordova-toforeground

      cordova.plugins.backgroundMode.enable();

      cordova.plugins.backgroundMode.onactivate = function() {
        setTimeout(function(){ 
          toForeground("MainActivity", "com.me.myapp", function() {
            navigator.notification.vibrate(1000);
          }, function(){
            navigator.notification.vibrate(5000);
          }); 
        }, 4000);
      };

注意它的调用位置:

toForeground(mainClassName, packageName, successFunction, errorFunction);

为了找到mainClassName"和packageName",我搜索了:platforms/android/src/com/me/myapp/MainActivity.java,我找到了:

To find the "mainClassName" and "packageName" I searched: platforms/android/src/com/me/myapp/MainActivity.java, and I found:

package com.me.myapp;

import android.os.Bundle;
import org.apache.cordova.*;

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        loadUrl(launchUrl);
    }
}

这篇关于Phonegap - 从背景到前景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆