注意:在询问之前我有冲浪stackoverflow的答案,所以不要重复
我正在尝试创建以后台模式运行的应用,我的应用中没有任何活动, 我的应用程序应该像 10分钟后,它将检查通话记录,如果从上次更改,则应将呼叫记录发送到服务器。 我尝试过boot_completed intent
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及以上版本中不起作用,是否有任何替代方案可以在上面进行开发。
答案 0 :(得分:2)
作为安全修复程序,Android的新版本将不允许BroadcastReceiver在用户启动之前接收BOOT_COMPLETE,这需要他们启动的活动。这很烦人,但你必须添加某种活动。