Android BOOT_COMPLETE接收器在CN1上不起作用

问题描述 投票:1回答:1

我想知道这是否是CN1特定的东西,或者它是否与Galaxy A6有关。我的直觉告诉我,此接收方中的上下文与com.codename1.impl.android.AndroidNativeUtil.getActivity().getApplicationContext()中的上下文不相同

我添加以下内容

android.permission.RECEIVE_BOOT_COMPLETED构建提示中:true

android.xapplication构建提示中:

<receiver android:name="com.groups.AutoStartReceiver">
<intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

然后,对于放置在native / android中的接收器(我在其中将一些内容写入测试文件以验证其已被调用):

package com.groups;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class AutoStartReceiver extends BroadcastReceiver 
{
@Override
public void onReceive(Context context, Intent arg1) 
{
    DataOutputStream os = null;
  try {
      os = new DataOutputStream(context.openFileOutput("testLogger", 0));
      os.writeUTF("onReceive called");
  } catch (Exception ex) {
  } finally {
      try {
          os.close();
      } catch (IOException ex) {
      }
  }
}
}

但是,当我在启动和启动应用程序后读取文本文件的内容时,找不到该文件(FileNotFoundException)

我已经检查了单独写入文件的代码(在应用运行时),并且可以正常工作。我知道我可以使用“首选项”,但是我尝试将其保留为尽可能本机,以防操作系统在启动时不喜欢“首选项”等。

如果需要,我可以共享我的整个清单文件

我想知道这是否是CN1特定的东西,或者它是否与Galaxy A6有关。我的直觉告诉我,此接收器中的上下文以及com.codename1.impl.android.AndroidNativeUtil ....

codenameone
1个回答
0
投票

似乎BOOT_COMPLETED已被弃用,不再起作用。我已经在一些地方阅读过,但没有官方]

© www.soinside.com 2019 - 2024. All rights reserved.