我似乎無法找出這一個。我有一個在清單中註冊的broadcastReceiver。我每分鐘ping一次gps,broadcastReceiver的onReceive會觸發並啓動服務。這項服務抓住了一個wakelock以防萬一,使用ASyncTask將GPS Coords發送到我們的服務器並釋放喚醒鎖,並調用stopSelf()。這會在我的Nexus 6p和HTC上持續發生火災。Android三星手機停止broadcastceceiver隨機更新
但是在三星GS5上,這隻能工作很長時間。它停止的時間似乎是隨機的,但通常在30分鐘內,有時短至5分鐘。 broadcastReceiver再也不會被調用,這意味着onReceive只是停止發射。
關於三星的所有省電設置已關閉,我可以注意到。除非有一個超級棘手的隱藏的,否則我無法弄清楚三星手機如何阻止這個廣播接收器,或停止GPS,無論發生什麼事情。
即使未關閉應用程序,也會發生這種情況。手機閒置,屏幕關閉,大約5-30分鐘後,手機停止獲取座標。
無論我使用GPS_PROVIDER還是NETWORK_PROVIDER,都會發生這種情況,儘管網絡提供者似乎發生的速度更快。
這裏是我開始GPS的地方。
public void startBackgroundGPS() {
Activity activity = this.cordova.getActivity();
Context context = activity.getApplicationContext();
ComponentName component = new ComponentName(context, LocationReceiver.class);
int status = context.getPackageManager().getComponentEnabledSetting(component);
Log.d(TAG, Integer.toString(status));
if(status == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || status == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
Log.d(TAG, "receiver is enabled");
//getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED , PackageManager.DONT_KILL_APP);
} else if(status == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
Log.d(TAG, "receiver is disabled");
context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED , PackageManager.DONT_KILL_APP);
}
Intent intent = new Intent(context, LocationReceiver.class);
intent.setAction("myBroadcast");
intent.putExtra("session_id", session_id);
intent.putExtra("device_id", device_id);
//intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
PendingIntent pendingIntent = PendingIntent.getBroadcast(activity.getApplicationContext(), 58534, intent, PendingIntent.FLAG_UPDATE_CURRENT);
//Register for broadcast intents
locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, pendingIntent);
}
這裏是我的廣播接收器
public class LocationReceiver extends BroadcastReceiver {
//private static boolean semaphore = true;
@Override
public void onReceive(Context context, Intent intent) {
Log.d("DistanceFilterLocationService", intent.getAction());
Location location = (Location) intent.getExtras().get(android.location.LocationManager.KEY_LOCATION_CHANGED);
Intent locationServiceIntent = new Intent(context, DistanceFilterLocationService.class);
locationServiceIntent.putExtra("device_id", intent.getStringExtra("device_id"));
locationServiceIntent.putExtra("session_id", intent.getStringExtra("session_id"));
Double longi = location.getLongitude();
Double lati = location.getLatitude();
locationServiceIntent.putExtra("longitude", longi);
locationServiceIntent.putExtra("latitude", lati);
locationServiceIntent.putExtra("accuracy", location.getAccuracy());
locationServiceIntent.putExtra("time", location.getTime());
context.startService(locationServiceIntent);
}
}
這是我在清單廣播接收器。
<receiver android:name="com.mypackage.LocationReceiver">
<intent-filter>
<action android:name="myBroadcast" />
</intent-filter>
</receiver>
任何人遇到這樣的事情?發現了幾個類似的問題,但沒有給出答案。這個殺了我,因爲它完全破壞了三星手機上應用程序的用途。
感謝您的任何幫助。