I’m trying to run a simple on boot receiver. I just need to get one record from my database (which does exist – tested), I’m testing it with Toast message (is that possible?). Nothing happens when phone boots :
Receiver :
public class OnBootReceiver extends BroadcastReceiver {
int milibaza;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Cursor cursor = DatabaseManager.getAllData();
if(cursor !=null)
{
cursor.moveToFirst();
milibaza = cursor.getInt(2);
Toast.makeText(context, ((new StringBuilder("Vrijeme u bazi").append(milibaza).toString())), Toast.LENGTH_LONG).show();
cursor.close();
}
}
}
Get all data method :
public static Cursor getAllData()
{
Cursor cursor=null;
if(db!=null)
{
cursor=db.query(TABLE_NAME, new String[] { TABLE_COLUMN_ID, TABLE_COLUMN_ONE, TABLE_COLUMN_TWO }, null, null, null, null, null);
}
return cursor;
}
Values in manifest connected to receiver I’m trying to run :
<receiver android:name=".OnBootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
I don’t think you can launch the Toast using the context from the BroadcastReceiver onReceive() function. Try using an Intent to launch an Application Activity instead.