Android BroadcastReceiver not triggered -
there lot of questions related topic. cannot run on device 4.2.1 on emulator 5.0 working fine.:
here manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.bootservice" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="10" android:targetsdkversion="21" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.receive_boot_completed" /> <uses-permission android:name="android.permission.write_external_storage" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <receiver android:name=".mybroadcastreceiver" android:enabled="true" android:label="mybroadcastreceiver" > <intent-filter android:priority="1001" > <action android:name="android.intent.action.boot_completed" /> </intent-filter> </receiver> <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <service android:name=".pingservice" > </service> <service android:name=".updateservice" > </service> <receiver android:name=".onbootreceiver" > <intent-filter android:priority="1001" > <action android:name="android.intent.action.boot_completed" /> </intent-filter> </receiver> </application> </manifest>
i tried 2 receivers: none of them working. here 1 of receivers should write logfile sd, working fine launcher activity:
public class mybroadcastreceiver extends broadcastreceiver { // restart service every 30 seconds private static final long repeat_time = 1000 * 10; @override public void onreceive(context context, intent intent) { log.e("mybroadcastreceiver", "broadcastreceiver"); appendlog("mybroadcastreceiver broadcastreceiver \n"); alarmmanager service = (alarmmanager) context .getsystemservice(context.alarm_service); intent = new intent(context, updateservice.class); pendingintent pending = pendingintent.getbroadcast(context, 0, i, pendingintent.flag_cancel_current); calendar cal = calendar.getinstance(); cal.add(calendar.second, 30); service.setinexactrepeating(alarmmanager.rtc_wakeup, cal.gettimeinmillis(), repeat_time, pending); log.wtf("mybroadcastreceiver", "alarm went off"); } public static void appendlog(string text) { file logfile = new file("sdcard/logfile.txt"); if (!logfile.exists()) { try { logfile.createnewfile(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } try { // bufferedwriter performance, true set append file flag bufferedwriter buf = new bufferedwriter(new filewriter(logfile, true)); buf.append(text); buf.newline(); buf.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
i cannot see error. does? ps app started once, this: http://commonsware.com/blog/2011/07/05/boot-completed-regression.html covered.
thanks,
it took me long key problem in manifest.xml
here changes got run (only receiver block):
<receiver android:name="com.example.bootservice.mybroadcastreceiver" android:exported="true" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.package_replaced" /> <data android:path="com.example.bootservice" android:scheme="package" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.boot_completed" /> <category android:name="android.intent.category.default" /> </intent-filter> </receiver>
important
<category android:name="android.intent.category.default" />
tag
Comments
Post a Comment