【问题标题】:'Plugin unable to bind to background service' - Red-folder phonegap plugin'插件无法绑定到后台服务' - 红色文件夹 phonegap 插件
【发布时间】:2016-05-13 07:50:32
【问题描述】:

我一直在尝试使用this 教程为我的科尔多瓦应用程序创建后台服务。我收到一个错误,上面写着:Plugin unable to bind to background service. 我一直在研究这个错误,并且在 github here 上提供了多个修复程序。但是,这些修复并不能解决我的问题。我已经在上面的链接中发表了评论,解释了这个问题,但还没有修复。不过也有更多的 cmets 说他们遇到了同样的问题。

here 提供的解决方案与我的问题无关,也没有解决它。

我已按照教程的确切说明进行操作,并使用了与教程中提到的名称相同的名称。我的包名是:com.red_folder.phonegap.plugin.backgroundservice.sample 并像这样在AndroidManifest.xml 中声明服务:

<service android:name="com.red_folder.phonegap.plugin.backgroundservice.sample.MyService">
   <intent-filter>
      <action android:name="com.red_folder.phonegap.plugin.backgroundservice.sample.MyService" />
   </intent-filter>
</service>

这里有人有解决这个问题的方法吗?

非常感谢!

【问题讨论】:

    标签: java android cordova phonegap-plugins cordova-plugins


    【解决方案1】:

    找到了!!!!:)

    首先检查你有没有

    包 com.red_folder.phonegap.plugin.backgroundservice.BackgroundService;

    在顶部的 MyService.java 中。

    我没有注意到它丢失了。

    完成后转到文件 com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.BackgroundServicePluginLogic.java

    第 163 行并更改

    String serviceName = data.getString(0);

    String serviceName = "com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.MyService";

    否则我遵循以下步骤(我先做了这个并且正在工作,但我认为上述方法也可以是一个解决方案,以免更改文件、位置等)。

    1. 将 MyService.java 从 com.red_folder.phonegap.plugin.backgroundservice.BackgroundService 移动到 com.my.app

    2.MyService.java如下

    package com.my.app;
    
    import android.util.Log;
    
    import com.red_folder.phonegap.plugin.backgroundservice.BackgroundService;
    
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class MyService extends BackgroundService {
        @Override
        protected JSONObject doWork() {
            JSONObject result = new JSONObject();
    
            try {
                // Following three lines simply produce a text string with Hello World and the date & time (UK format)
                SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
                String now = df.format(new Date(System.currentTimeMillis()));
                String msg = "Hello World - its currently " + now;
    
                // We output the message to the logcat
                Log.d("MyService", msg);
    
                // We also provide the same message in our JSON Result
                result.put("Message", msg);
            } catch (JSONException e) {
                // In production code, you would have some exception handling here
            }
    
            return result;
        }
    
        @Override
        protected JSONObject getConfig() {
            return null;
        }
    
        @Override
        protected void setConfig(JSONObject config) {
    
        }
    
        @Override
        protected JSONObject initialiseLatestResult() {
            return null;
        }
    
    }
    
    1. 在 AndroidManifest.xml 中也进行更改

      <service android:name="com.my.app.MyService">
          <intent-filter>
              <action android:name="com.my.app.MyService" />
          </intent-filter>
      </service>
      
    2. 转到文件 com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.BackgroundServicePluginLogic.java

    第 163 行并更改

    String serviceName = data.getString(0);

    String serviceName = "com.my.app.MyService";

    希望能帮到你!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多