我正在尝试使用BroadcastReceiver
和将位置数据更新到 Web 数据库Service
。
但是,我很难在 Galaxy Tab 7.0 Plus 上使用 Android 3.2。
相同的应用程序在 Android 2.3.6 Galaxy Note 上运行良好,但不能在平板电脑上运行。事实上,我将RECEIVE_BOOT
意图操作添加到我的接收器,但它永远不会被实例化,也就是说,nReceive()
在启动完成后永远不会调用 o。我想知道系统是否有任何更新导致此操作。
这是我的 xml 和接收器类:
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tests.bootreceiver"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver
android:name=".BootUpReceiver"
android:enabled="true"
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>
<service android:name=".MyService" >
</service>
</application>
BootUpReceiver.java
public class BootUpReceiver extends BroadcastReceiver {
private static int INTERVAL = 1000*15;
@Override
public void onReceive(Context context, Intent intent) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pi = PendingIntent.getService(context, 0, new Intent(context, MyService.class), PendingIntent.FLAG_UPDATE_CURRENT);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), INTERVAL, pi);
}
}
有没有理由让同一段代码在一个系统中工作而在另一个系统上不起作用?
谢谢!