List of usage examples for android.content Context sendBroadcast
public abstract void sendBroadcast(@RequiresPermission Intent intent);
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.CommandService.java
private static HttpResp<Void> sendCommandWithMedia(final Context ctx, CommandObject cmd) throws KurentoCommandException, TransportException, InvalidDataException, NotFoundException { String contentPath = cmd.getMedia(); File content = new File(contentPath); String mimeType;//from w w w . j a v a 2 s. c o m if (content.exists() && content.isFile()) { if (contentPath.contains(ConstantKeys.EXTENSION_JPG)) { mimeType = ConstantKeys.TYPE_IMAGE; } else { mimeType = ConstantKeys.TYPE_VIDEO; } } else { String error = contentPath + " does not exists or is not a file"; log.error(error); throw new KurentoCommandException(error); } CustomMultiPartEntity mpEntity; final String json = cmd.getJson(); String charset = HTTP.UTF_8; long contentSize = 0; try { contentSize = content.length(); /* Aprox. total size */ final long totalSize = content.length() + json.getBytes("UTF-16BE").length; mpEntity = new CustomMultiPartEntity(new CustomMultiPartEntity.ProgressListener() { private int i; @Override public void transferred(long num) { int totalpercent = Math.min(100, (int) ((num * 100) / totalSize)); if (totalpercent > (1 + PERCENT_INC * i) || totalpercent >= 100) { Intent intent = new Intent(); intent.setAction(ConstantKeys.BROADCAST_PROGRESSBAR); intent.putExtra(ConstantKeys.JSON, json); intent.putExtra(ConstantKeys.TOTAL, totalpercent); ctx.sendBroadcast(intent); i++; } } }); mpEntity.addPart(COMMAND_PART_NAME, new StringBody(json, HttpManager.CONTENT_TYPE_APPLICATION_JSON, Charset.forName(charset))); FormBodyPart fbp = new FormBodyPart(CONTENT_PART_NAME, new FileBody(content, mimeType)); fbp.addField(HTTP.CONTENT_LEN, String.valueOf(contentSize)); mpEntity.addPart(fbp); } catch (UnsupportedEncodingException e) { String msg = "Cannot use " + charset + "as entity"; log.error(msg, e); throw new TransportException(msg); } return HttpManager.sendPostVoid(ctx, ctx.getString(R.string.url_command), mpEntity); }
From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java
/** * <p>Broadcasts the given song info as the new song being played.</p> *//*from w ww .ja v a2s .c om*/ public static void broadcastNewTrackInfo(Context context, MusicDirectory.Entry song) { Intent intent = new Intent(EVENT_META_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()); } else { intent.putExtra("title", ""); intent.putExtra("artist", ""); intent.putExtra("album", ""); intent.putExtra("coverart", ""); } context.sendBroadcast(intent); }
From source file:org.mariotaku.twidere.provider.TwidereDataProvider.java
private void onDatabaseUpdated(final Uri uri) { if (uri == null) return;/*from w ww . j ava 2s . com*/ if ("false".equals(uri.getQueryParameter(QUERY_PARAM_NOTIFY))) return; final Context context = getContext(); switch (getTableId(uri)) { case TABLE_ID_ACCOUNTS: { clearAccountColor(); clearAccountName(); context.sendBroadcast(new Intent(BROADCAST_ACCOUNT_LIST_DATABASE_UPDATED)); break; } case TABLE_ID_DRAFTS: { context.sendBroadcast(new Intent(BROADCAST_DRAFTS_DATABASE_UPDATED)); break; } case TABLE_ID_STATUSES: case TABLE_ID_MENTIONS: case TABLE_ID_DIRECT_MESSAGES_INBOX: case TABLE_ID_DIRECT_MESSAGES_OUTBOX: { notifyForUpdatedUri(context, uri); break; } case TABLE_ID_TRENDS_LOCAL: { context.sendBroadcast(new Intent(BROADCAST_TRENDS_UPDATED)); break; } case TABLE_ID_TABS: { context.sendBroadcast(new Intent(BROADCAST_TABS_UPDATED)); break; } case TABLE_ID_FILTERED_LINKS: case TABLE_ID_FILTERED_USERS: case TABLE_ID_FILTERED_KEYWORDS: case TABLE_ID_FILTERED_SOURCES: { context.sendBroadcast(new Intent(BROADCAST_FILTERS_UPDATED)); break; } default: return; } context.sendBroadcast(new Intent(BROADCAST_DATABASE_UPDATED)); }
From source file:github.daneren2005.dsub.util.Util.java
/** * <p>Broadcasts the given player state as the one being set.</p> *///w w w . j a v a 2 s . c om public static void broadcastPlaybackStatusChange(Context context, 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. } context.sendBroadcast(intent); context.sendBroadcast(avrcpIntent); }
From source file:com.dattasmoon.pebble.plugin.FireReceiver.java
public void sendAlertToPebble(final Context context, int bundleVersionCode, String title, String body) { // Create json object to be sent to Pebble final Map<String, Object> data = new HashMap<String, Object>(); data.put("title", title); data.put("body", body); final JSONObject jsonData = new JSONObject(data); final String notificationData = new JSONArray().put(jsonData).toString(); // Create the intent to house the Pebble notification final Intent i = new Intent(Constants.INTENT_SEND_PEBBLE_NOTIFICATION); i.putExtra("messageType", Constants.PEBBLE_MESSAGE_TYPE_ALERT); i.putExtra("sender", context.getString(R.string.app_name)); i.putExtra("notificationData", notificationData); // Send the alert to Pebble if (Constants.IS_LOGGABLE) { Log.d(Constants.LOG_TAG, "About to send a modal alert to Pebble: " + notificationData); }/*from ww w . jav a 2 s . c o m*/ context.sendBroadcast(i); }
From source file:org.zywx.wbpalmstar.engine.EUtil.java
public final void createSystemSwitcherShortCut(Context context, String shortCutName) { Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); Parcelable icon = Intent.ShortcutIconResource.fromContext(context, EResources.icon); addIntent.putExtra("duplicate", false); Intent targetIntent = new Intent(context, EBrowserActivity.class); targetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent); context.sendBroadcast(addIntent); }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void sendAlertToPebble(Context context, String title, String body) { final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION"); final Map data = new HashMap(); data.put("title", TweetLinkUtils.removeColorHtml(title.replaceAll("<b>", "").replaceAll("</b>", ""), AppSettings.getInstance(context))); data.put("body", TweetLinkUtils.removeColorHtml(body.replaceAll("<b>", "").replaceAll("</b>", ""), AppSettings.getInstance(context))); final JSONObject jsonData = new JSONObject(data); final String notificationData = new JSONArray().put(jsonData).toString(); i.putExtra("messageType", "PEBBLE_ALERT"); i.putExtra("sender", "Test_for_twitter"); i.putExtra("notificationData", notificationData); Log.v("Test_pebble", "About to send a modal alert to Pebble: " + notificationData); context.sendBroadcast(i); }
From source file:cs460.grouple.grouple.GcmIntentService.java
private void updateMyActivity(Context context) { Intent intent = null;//from ww w. ja v a2s.c om // change intent based on type if (TYPE.equals(CONTENT_TYPE.GROUP_MESSAGE.toString()) || TYPE.equals(CONTENT_TYPE.EVENT_MESSAGE.toString())) { intent = new Intent("ENTITY_MESSAGE"); intent.putExtra("ID", RECEIVER); intent.putExtra("TYPE", TYPE); intent.putExtra("SENDER", SENDER); intent.putExtra("name", SENDER_FIRST + " " + SENDER_LAST); } else if (TYPE.equals(CONTENT_TYPE.USER_MESSAGE.toString())) { intent = new Intent("USER_MESSAGE"); intent.putExtra("sender", SENDER); intent.putExtra("name", SENDER_FIRST + " " + SENDER_LAST); intent.putExtra("receiver", RECEIVER); } else if (TYPE.equals(CONTENT_TYPE.FRIEND_REQUEST.toString())) { // intent = new I } // send broadcast if (intent != null) context.sendBroadcast(intent); }
From source file:com.example.camera2apidemo.Camera2BasicFragment.java
public static void saveImageToGallery(Context context, Bitmap bmp) { // ?/*from w ww. ja va 2 s. c o m*/ File appDir = new File(Environment.getExternalStorageDirectory(), "Camera2API"); if (!appDir.exists()) { appDir.mkdir(); } String fileName = System.currentTimeMillis() + ".jpg"; File file = new File(appDir, fileName); try { FileOutputStream fos = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // ? try { MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), fileName, null); } catch (FileNotFoundException e) { e.printStackTrace(); } // ? context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + path))); }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void sendAlertToPebble(Context context, String title, String body) { final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION"); final Map data = new HashMap(); data.put("title", TweetLinkUtils.removeColorHtml(title.replaceAll("<b>", "").replaceAll("</b>", ""), AppSettings.getInstance(context))); data.put("body", TweetLinkUtils.removeColorHtml(body.replaceAll("<b>", "").replaceAll("</b>", ""), AppSettings.getInstance(context))); final JSONObject jsonData = new JSONObject(data); final String notificationData = new JSONArray().put(jsonData).toString(); i.putExtra("messageType", "PEBBLE_ALERT"); i.putExtra("sender", "talon_for_twitter"); i.putExtra("notificationData", notificationData); Log.v("talon_pebble", "About to send a modal alert to Pebble: " + notificationData); context.sendBroadcast(i); }