List of usage examples for android.content Context sendBroadcast
public abstract void sendBroadcast(@RequiresPermission Intent intent);
From source file:github.madmarty.madsonic.util.Util.java
/** * <p>Broadcasts the given song info as the new song being played.</p> *//*w w w .j a v a2 s .com*/ public static void broadcastNewTrackInfo(Context context, MusicDirectory.Entry song) { DownloadService downloadService = (DownloadService) context; Intent intent = new Intent(EVENT_META_CHANGED); Intent avrcpIntent = new Intent(AVRCP_METADATA_CHANGED); if (song != null) { intent.putExtra("title", song.getTitle()); intent.putExtra("artist", song.getArtist()); intent.putExtra("album", song.getAlbum()); File albumArtFile = FileUtil.getAlbumArtFile(context, song); intent.putExtra("coverart", albumArtFile.getAbsolutePath()); avrcpIntent.putExtra("playing", true); } else { intent.putExtra("title", ""); intent.putExtra("artist", ""); intent.putExtra("album", ""); intent.putExtra("coverart", ""); avrcpIntent.putExtra("playing", false); } addTrackInfo(context, song, avrcpIntent); context.sendBroadcast(intent); context.sendBroadcast(avrcpIntent); }
From source file:com.mk4droid.IMC_Services.DatabaseHandler.java
/** * Download and Update locally table of votes for the current user so as not to be able to vote multiple times for an issue. * //from www . j a v a 2 s . com * @param UserNameSTR * @param PasswordSTR * @return */ public int AddUpdUserVotes(String UserNameSTR, String PasswordSTR, Context ctx) { if (UserNameSTR.length() == 0) return 0; if (!db.isOpen()) db = this.getWritableDatabase(); db.execSQL("DELETE FROM " + TABLE_Votes); String response = Download_Data.Download_UserVotes(UserNameSTR, PasswordSTR); if (response == null) return 0; try { //-------- Get Info from HTTP post -------- JSONArray jArr = new JSONArray(response); int NVotes = jArr.length(); Log.e("UPD", "Votes"); for (int i = 0; i < NVotes; i++) { float prog = 100 * ((float) (i + 1)) / ((float) NVotes); ctx.sendBroadcast( new Intent("android.intent.action.MAIN").putExtra("progressval", (int) (83 + prog * 0.17))); JSONArray jArrCurr = new JSONArray(jArr.get(i).toString()); int VoteID = jArrCurr.getInt(0); //"id"); int IssueID = jArrCurr.getInt(1); //Int("improvemycityid"); //------------ See if exists in mySQL --------- Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_Votes + " WHERE " + KEY_IssueIDVotes + "=" + Integer.toString(IssueID), null); //-------------- Prepare values for add or upd ---------- ContentValues values = new ContentValues(); values.put(KEY_VoteID, Integer.toString(VoteID)); values.put(KEY_IssueIDVotes, Integer.toString(IssueID)); //---------- Insert Vote to SQLite -------------- if (!cursor.moveToFirst()) db.insert(TABLE_Votes, null, values); cursor.close(); } } catch (JSONException e1) { e1.printStackTrace(); } return response.getBytes().length; }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
@NonNull @Override// w w w. j a v a2 s. c o m public ContentProviderResult[] applyBatch(@NonNull final ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { holdNotifyChange = true; try { return super.applyBatch(operations); } finally { holdNotifyChange = false; boolean broadcastSourceChanged = false; Context context = getContext(); if (context != null) { ContentResolver contentResolver = context.getContentResolver(); synchronized (pendingNotifyChange) { Iterator<Uri> iterator = pendingNotifyChange.iterator(); while (iterator.hasNext()) { Uri uri = iterator.next(); contentResolver.notifyChange(uri, null); if (MuzeiContract.Artwork.CONTENT_URI.equals(uri)) { context.sendBroadcast(new Intent(MuzeiContract.Artwork.ACTION_ARTWORK_CHANGED)); } else if (MuzeiProvider.uriMatcher.match(uri) == SOURCES || MuzeiProvider.uriMatcher.match(uri) == SOURCE_ID) { broadcastSourceChanged = true; } iterator.remove(); } } if (broadcastSourceChanged) { context.sendBroadcast(new Intent(MuzeiContract.Sources.ACTION_SOURCE_CHANGED)); } } } }
From source file:org.kiwix.kiwixmobile.KiwixMobileActivity.java
public static void updateWidgets(Context context) { Intent intent = new Intent(context.getApplicationContext(), KiwixSearchWidget.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); // Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID, // since it seems the onUpdate() is only fired on that: AppWidgetManager widgetManager = AppWidgetManager.getInstance(context); int[] ids = widgetManager.getAppWidgetIds(new ComponentName(context, KiwixSearchWidget.class)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { widgetManager.notifyAppWidgetViewDataChanged(ids, android.R.id.list); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); context.sendBroadcast(intent); }/*from w w w .ja va2 s . co m*/ }
From source file:github.madmarty.madsonic.util.Util.java
/** * <p>Broadcasts the given player state as the one being set.</p> */// ww w . j av a 2 s . co m public static void broadcastPlaybackStatusChange(Context context, MusicDirectory.Entry song, PlayerState state) { Intent intent = new Intent(EVENT_PLAYSTATE_CHANGED); Intent avrcpIntent = new Intent(AVRCP_PLAYSTATE_CHANGED); switch (state) { case STARTED: intent.putExtra("state", "play"); avrcpIntent.putExtra("playing", true); break; case STOPPED: intent.putExtra("state", "stop"); avrcpIntent.putExtra("playing", false); break; case PAUSED: intent.putExtra("state", "pause"); avrcpIntent.putExtra("playing", false); break; case COMPLETED: intent.putExtra("state", "complete"); avrcpIntent.putExtra("playing", false); break; default: return; // No need to broadcast. } addTrackInfo(context, song, avrcpIntent); if (state != PlayerState.PREPARED) { //context.sendBroadcast(intent); } context.sendBroadcast(avrcpIntent); }
From source file:cw.kop.autobackground.LiveWallpaperService.java
private void closeNotificationDrawer(Context context) { Intent closeDrawer = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); context.sendBroadcast(closeDrawer); }
From source file:github.daneren2005.dsub.util.Util.java
/** * <p>Broadcasts the given player state as the one being set.</p> *//*from w w w .ja va 2s . co m*/ public static void broadcastPlaybackStatusChange(Context context, MusicDirectory.Entry song, PlayerState state) { Intent intent = new Intent(EVENT_PLAYSTATE_CHANGED); Intent avrcpIntent = new Intent(AVRCP_PLAYSTATE_CHANGED); switch (state) { case STARTED: intent.putExtra("state", "play"); avrcpIntent.putExtra("playing", true); break; case STOPPED: intent.putExtra("state", "stop"); avrcpIntent.putExtra("playing", false); break; case PAUSED: intent.putExtra("state", "pause"); avrcpIntent.putExtra("playing", false); break; case PREPARED: // Only send quick pause event for samsung devices, causes issues for others if (Build.MANUFACTURER.toLowerCase().indexOf("samsung") != -1) { avrcpIntent.putExtra("playing", false); } else { return; // Don't broadcast anything } break; case COMPLETED: intent.putExtra("state", "complete"); avrcpIntent.putExtra("playing", false); break; default: return; // No need to broadcast. } addTrackInfo(context, song, avrcpIntent); if (state != PlayerState.PREPARED) { context.sendBroadcast(intent); } context.sendBroadcast(avrcpIntent); }
From source file:org.messic.android.smartphone.notifications.MessicPlayerNotification.java
private void registerBroadcastActions() { IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_BACK);//from w ww . j a v a 2 s . co m filter.addAction(ACTION_PLAY); filter.addAction(ACTION_PAUSE); filter.addAction(ACTION_NEXT); filter.addAction(ACTION_CLOSE); filter.addAction(ACTION_ALBUM); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION_BACK)) { player.prevSong(); } else if (intent.getAction().equals(ACTION_PLAY)) { player.resumeSong(); } else if (intent.getAction().equals(ACTION_PAUSE)) { player.pauseSong(); } else if (intent.getAction().equals(ACTION_NEXT)) { player.nextSong(); } else if (intent.getAction().equals(ACTION_CLOSE)) { service.stopForeground(true); service.unregisterReceiver(this); mNotificationManager.cancel(ONGOING_NOTIFICATION_ID); ump.clearAndStopAll(); Intent ssa = new Intent(MessicPlayerNotification.this.service, LoginActivity.class); ssa.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); ssa.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); MessicPlayerNotification.this.service.getApplication().startActivity(ssa); } else if (intent.getAction().equals(ACTION_ALBUM)) { Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); context.sendBroadcast(it); Observable<MDMAlbum> observable = getAlbum(player.getCurrentSong().getAlbum()); observable.subscribeOn(Schedulers.io()).onBackpressureBuffer() .observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<MDMAlbum>() { @Override public void call(MDMAlbum mdmAlbum) { Intent ssa = new Intent(MessicPlayerNotification.this.service, AlbumInfoActivity.class); ssa.putExtra(AlbumInfoActivity.EXTRA_ALBUM_SID, mdmAlbum); ssa.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ssa.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); MessicPlayerNotification.this.service.getApplication().startActivity(ssa); } }); } } }; this.service.registerReceiver(receiver, filter); }
From source file:com.mobisys.android.ibp.ObservationRequestQueue.java
protected void submitObservationRequestFinally(final boolean single, final Bundle b, final Context context, final ObservationInstance sp) { String path;// w w w . j a v a 2s . c om if (sp.getId() == -1) path = Request.PATH_SAVE_OBSERVATION; else path = Request.PATH_UPDATE_OBSERVATION; sp.setStatus(StatusType.PROCESSING); ObservationInstanceTable.updateRowFromTable(context, sp); WebService.sendRequest(context, Request.METHOD_POST, path, b, new WebService.ResponseHandler() { @Override public void onSuccess(String response) { //ObservationParamsTable.deleteRowFromTable(context, sp); try { JSONObject jObj = new JSONObject(response); boolean success = jObj.optBoolean("success"); if (success) { sp.setStatus(StatusType.SUCCESS); sp.setId(jObj.getJSONObject("observationInstance").optLong("id")); ObservationInstanceTable.updateRowFromTable(context, sp); if (Preferences.DEBUG) Log.d("ObsRequestQueue", "******Broadcast send from ObsRequestQueue...."); //send broadcast to HomeActivity and ObsStatusActivity to change status or view Intent i = new Intent("com.mobisys.android.ibp.check_incomplete_obs"); context.sendBroadcast(i); } else { sp.setStatus(StatusType.FAILURE); String fail = jObj.optString("msg"); JSONArray jarray = jObj.getJSONArray("errors"); if (jarray != null && jarray.length() > 0) { sp.setMessage(jarray.getJSONObject(0).optString("message")); } else sp.setMessage(fail); ObservationInstanceTable.updateRowFromTable(context, sp); } } catch (JSONException e) { sp.setStatus(StatusType.FAILURE); sp.setMessage("Unknown error occured.."); ObservationInstanceTable.updateRowFromTable(context, sp); e.printStackTrace(); } if (!single) { ObservationInstance cp_new = ObservationInstanceTable.getFirstRecord(context); observationMethods(single, cp_new, context); } } @Override public void onFailure(Throwable e, String content) { Log.d("NetWorkState", content); if (e instanceof UnknownHostException || e instanceof ConnectException) { mIsRunning = false; return; } sp.setStatus(StatusType.FAILURE); sp.setMessage(content); ObservationInstanceTable.updateRowFromTable(context, sp); if (!single) { ObservationInstance cp_new = ObservationInstanceTable.getFirstRecord(context); observationMethods(single, cp_new, context); } } }); }
From source file:com.drinviewer.droiddrinviewer.DrinViewerBroadcastReceiver.java
/** * Starts the alarm repeater after a disconnection from a WiFi network. * The alarm is firing request to discover server at regular time interval * /*from w w w . j a v a 2 s.c o m*/ * @param context The context to use * @return true on success */ private boolean startAlarmRepeater(Context context) { boolean returnValue = false; // Gets the Binder to the DiscoverServerService IBinder b = peekService(context, new Intent(context, DiscoverServerService.class)); DiscoverServerApi discoverServerApi = DiscoverServerApi.Stub.asInterface(b); // start the alarm repeater only if the api exists and the discover process in not running try { if (b != null && discoverServerApi != null && !discoverServerApi.isRunning()) { // Get the alarm manager if (alarmManager == null) alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Instantiate the intent and set its action Intent i = new Intent(context, this.getClass()); i.setAction(context.getResources().getString(R.string.broadcast_startdiscovery)); // send the wifiBroadcastAddress together with the intent i.putExtra("wifiBroadcastAddress", wifiBroadcastAddress); // Get the broadcast PendingIntent pending = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); if (pending != null) { Calendar cal = Calendar.getInstance(); // cancel the alarm alarmManager.cancel(pending); // Run the intent immediately and schedule repeating at fixed time intervals context.sendBroadcast(i); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() + DroidDrinViewerConstants.DISCOVER_REPEAT_TIME, DroidDrinViewerConstants.DISCOVER_REPEAT_TIME, pending); returnValue = true; } } } catch (RemoteException e) { e.printStackTrace(); returnValue = false; } return returnValue; }