List of usage examples for android.content BroadcastReceiver onReceive
public abstract void onReceive(Context context, Intent intent);
From source file:com.liferay.mobile.push.ReceivePushNotificationTest.java
@Test public void isIntentRegistered() { ShadowApplication app = Robolectric.getShadowApplication(); Intent intent = new Intent("com.google.android.c2dm.intent.RECEIVE"); List<BroadcastReceiver> receivers = app.getReceiversForIntent(intent); Assert.assertEquals(1, receivers.size()); BroadcastReceiver receiver = receivers.get(0); receiver.onReceive(app.getApplicationContext(), intent); Intent startedIntent = app.peekNextStartedService(); String componentClassName = startedIntent.getComponent().getClassName(); Assert.assertEquals(PushNotificationsService.class.getCanonicalName(), componentClassName); }
From source file:com.nadmm.airports.library.LibraryActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setActionBarTitle("Library", null); mReceivers = new HashMap<>(); mReceiver = new BroadcastReceiver() { @Override// w w w . j a va 2 s .c om public void onReceive(Context context, Intent intent) { String category = intent.getStringExtra(LibraryService.CATEGORY); BroadcastReceiver receiver = mReceivers.get(category); if (receiver != null) { receiver.onReceive(context, intent); } // Show the PDF here as the Fragment requesting it may be paused String action = intent.getAction(); if (action.equals(LibraryService.ACTION_GET_BOOK)) { String path = intent.getStringExtra(LibraryService.PDF_PATH); mPending = false; if (path != null) { SystemUtils.startPDFViewer(LibraryActivity.this, path); } } } }; mFilter = new IntentFilter(); mFilter.setPriority(10); mFilter.addAction(LibraryService.ACTION_CHECK_BOOKS); mFilter.addAction(LibraryService.ACTION_GET_BOOK); mFilter.addAction(LibraryService.ACTION_DOWNLOAD_PROGRESS); SQLiteDatabase db = getDatabase(DatabaseManager.DB_LIBRARY); SQLiteQueryBuilder builder = new SQLiteQueryBuilder(); builder.setTables(DatabaseManager.BookCategories.TABLE_NAME); Cursor c = builder.query(db, new String[] { "*" }, null, null, null, null, DatabaseManager.BookCategories._ID); populateTabs(c); //setBackgroundTask( new LibraryCategoryTask() ).execute( "" ); }