BroadcastReceiver issues in Android 3.1+

I am trying to update location data in a web database using BroadcastReceiver and Service .

However, I am having difficulty making it work with Android 3.2 on the Galaxy Tab 7.0 Plus.

The same application works fine on Android 2.3.6 Galaxy Note, but it does not work on the tablet. In fact, I am adding the RECEIVE_BOOT intent RECEIVE_BOOT to my recipient, but it is never created, i.e. O nReceive() never called after the download completes. I wonder if there are any updates to the system that trigger this action.

Here are my xml and receiver classes:

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); } 

}

Is there a reason why the same piece of code works on one system and doesn't work on another?

Thanks!

+2
source share
2 answers

since for Android 3 all components of the application are prohibited from starting (receiving broadcast messages) until the application is opened by the user.

to check if this is your problem, add dummy activity to the application and run it. Now your application will be able to receive intentions from now on (even after a reboot).

here is the AOSP problem describing the problem,

http://code.google.com/p/android/issues/detail?id=18225

note that it is closed as "works as intended." this is technically a security fix. applications can use some well-known broadcasts, such as TIMER_TICK , to get started without the user ever running the application, or knowing that the application is running.

+4
source

Check it out: Download full issues

+2
source

Source: https://habr.com/ru/post/1487540/


All Articles