PhoneGap的 - 从后台到前台带 [英] Phonegap - Bring from background to foreground

查看:547
本文介绍了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 -background-模式

可能有人给我一个忙吗?非常感谢这个了。

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和软件包名我搜索:平台/安卓/ src目录/ COM /我/的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天全站免登陆