3

注意:在问这个之前我已经浏览了stackoverflow的答案,所以不要让它重复

我正在尝试创建在后台模式下运行的应用程序,我的应用程序中没有任何活动,我的应用程序应该像 10 分钟后一样工作,它将检查通话记录,如果它从上次更改,那么它应该将通话记录发送到服务器. 我已经尝试过 boot_completed 意图

 public class BootUpReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("schedulereceiver", "starting schedule");
    }
}

我已经宣布接收者喜欢

 <receiver
            android:name="com.ixo.BootUpReceiver"
            android:enabled="true" android:exported="false"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
  </receiver>

我已添加权限

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

我想澄清一下,我正在测试 4.2 版本,以及它的 nexus 平板电脑,希望它不会造成问题

如果我正在检查日志

> 02-26 12:31:10.809: W/ActivityManager(478): No content provider found
> for permission revoke: file:///data/local/tmp/Tracker.apk 

02-26 12:31:10.809: I/PackageManager(478): Copying native libraries to
> /data/app-lib/vmdl1018712645 

02-26 12:31:10.889: D/dalvikvm(478): GC_CONCURRENT freed 1347K, 13% free 13294K/15184K, paused 3ms+7ms, total 62ms 02-26 12:31:10.889: I/PackageManager(478): Removing non-system package:com.ixo.tracker 

02-26 12:31:10.899: I/ActivityManager(478): Force stopping package com.ixo.tracker appid=10100 user=-1 

02-26 12:31:10.989: I/PackageManager(478): Running dexopt on: com.ixo.tracker 

02-26 12:31:10.989: I/PackageManager(478): Package com.ixo.tracker codePath changed from
/data/app/com.ixo.tracker-2.apk to /data/app/com.ixo.tracker-1.apk; Retaining data and using new 

02-26 12:31:11.049: D/dalvikvm(2434): DexOpt: 'Landroid/annotation/SuppressLint;' has an earlier definition; blocking out

更新

有时我会收到类似的日志

02-26 13:42:22.139: E/InstalledAppDetails(6171): Exception when retrieving package:com.ixo.tracker
02-26 13:42:22.139: E/InstalledAppDetails(6171): android.content.pm.PackageManager$NameNotFoundException: com.ixo.tracker
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:80)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at com.android.settings.applications.InstalledAppDetails.retrieveAppEntry(InstalledAppDetails.java:621)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at com.android.settings.applications.InstalledAppDetails.refreshUi(InstalledAppDetails.java:640)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at com.android.settings.applications.InstalledAppDetails.onActivityResult(InstalledAppDetails.java:534)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at android.app.Activity.dispatchActivityResult(Activity.java:5297)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3315)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3362)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at android.app.ActivityThread.access$1100(ActivityThread.java:141)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at android.os.Looper.loop(Looper.java:137)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at android.app.ActivityThread.main(ActivityThread.java:5041)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at java.lang.reflect.Method.invokeNative(Native Method)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at java.lang.reflect.Method.invoke(Method.java:511)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-26 13:42:22.139: E/InstalledAppDetails(6171):    at dalvik.system.NativeStart.main(Native Method)
02-26 13:42:22.169: W/AppSecurityPermissions(6171): Couldn't retrieve permissions for package:com.ixo.tracker

更新

如果它在 3.1 及更高版本中不起作用,是否有任何替代方法可以在上面开发。

4

1 回答 1

2

作为安全修复,新版本的 Android 将不允许 BroadcastReceiver 在用户启动之前接收 BOOT_COMPLETE - 这需要他们启动的活动。这很烦人,但您必须添加某种活动。

于 2013-02-26T07:10:32.780 回答