List of usage examples for android.content Context sendBroadcast
public abstract void sendBroadcast(@RequiresPermission Intent intent);
From source file:org.mariotaku.twidere.util.Utils.java
public static void notifyForUpdatedUri(final Context context, final Uri uri) { if (context == null) return;/* w ww . j a v a 2 s .com*/ switch (getTableId(uri)) { case TABLE_ID_STATUSES: { context.sendBroadcast(new Intent(BROADCAST_HOME_TIMELINE_DATABASE_UPDATED)); break; } case TABLE_ID_MENTIONS: { context.sendBroadcast(new Intent(BROADCAST_MENTIONS_DATABASE_UPDATED)); break; } case TABLE_ID_DIRECT_MESSAGES_INBOX: { context.sendBroadcast(new Intent(BROADCAST_RECEIVED_DIRECT_MESSAGES_DATABASE_UPDATED)); break; } case TABLE_ID_DIRECT_MESSAGES_OUTBOX: { context.sendBroadcast(new Intent(BROADCAST_SENT_DIRECT_MESSAGES_DATABASE_UPDATED)); break; } default: { return; } } context.sendBroadcast(new Intent(BROADCAST_DATABASE_UPDATED)); }
From source file:piuk.blockchain.android.WalletApplication.java
public void notifyWidgets() { final Context context = getApplicationContext(); // notify widgets final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); for (final AppWidgetProviderInfo providerInfo : appWidgetManager.getInstalledProviders()) { // limit to own widgets if (providerInfo.provider.getPackageName().equals(context.getPackageName())) { final Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetManager.getAppWidgetIds(providerInfo.provider)); context.sendBroadcast(intent); }// www . ja va 2 s . c o m } }
From source file:com.dwdesign.tweetings.util.Utils.java
public static void notifyForUpdatedUri(final Context context, final Uri uri) { if (context == null) return;// w w w. ja v a 2s.c o m switch (getTableId(uri)) { case URI_STATUSES: { context.sendBroadcast( new Intent(BROADCAST_HOME_TIMELINE_DATABASE_UPDATED).putExtra(INTENT_KEY_SUCCEED, true)); break; } case URI_MENTIONS: { context.sendBroadcast( new Intent(BROADCAST_MENTIONS_DATABASE_UPDATED).putExtra(INTENT_KEY_SUCCEED, true)); break; } case URI_DIRECT_MESSAGES_INBOX: { context.sendBroadcast(new Intent(BROADCAST_RECEIVED_DIRECT_MESSAGES_DATABASE_UPDATED) .putExtra(INTENT_KEY_SUCCEED, true)); break; } case URI_DIRECT_MESSAGES_OUTBOX: { context.sendBroadcast( new Intent(BROADCAST_SENT_DIRECT_MESSAGES_DATABASE_UPDATED).putExtra(INTENT_KEY_SUCCEED, true)); break; } default: { return; } } context.sendBroadcast(new Intent(BROADCAST_DATABASE_UPDATED)); }
From source file:com.aware.Aware.java
public static void reset(Context c) { if (!c.getPackageName().equals("com.aware")) return;//from w w w . j ava2 s . com String device_id = Aware.getSetting(c, Aware_Preferences.DEVICE_ID); //Remove all settings c.getContentResolver().delete(Aware_Settings.CONTENT_URI, null, null); //Read default client settings SharedPreferences prefs = c.getSharedPreferences(c.getPackageName(), Context.MODE_PRIVATE); PreferenceManager.setDefaultValues(c, c.getPackageName(), Context.MODE_PRIVATE, R.xml.aware_preferences, true); prefs.edit().commit(); Map<String, ?> defaults = prefs.getAll(); for (Map.Entry<String, ?> entry : defaults.entrySet()) { Aware.setSetting(c, entry.getKey(), entry.getValue()); } //Restore old Device ID Aware.setSetting(c, Aware_Preferences.DEVICE_ID, device_id); //Turn off all active plugins Cursor active_plugins = c.getContentResolver().query(Aware_Plugins.CONTENT_URI, null, Aware_Plugins.PLUGIN_STATUS + "=" + Plugins_Manager.PLUGIN_ACTIVE, null, null); if (active_plugins != null && active_plugins.moveToFirst()) { do { Aware.stopPlugin(c, active_plugins.getString(active_plugins.getColumnIndex(Aware_Plugins.PLUGIN_PACKAGE_NAME))); } while (active_plugins.moveToNext()); active_plugins.close(); } //Apply fresh state Intent aware_apply = new Intent(Aware.ACTION_AWARE_REFRESH); c.sendBroadcast(aware_apply); Intent preferences = new Intent(c, Aware_Preferences.class); preferences.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); c.startActivity(preferences); }
From source file:com.vonglasow.michael.satstat.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { Context c = getApplicationContext(); File dumpDir = c.getExternalFilesDir(null); DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.ROOT); fmt.setTimeZone(TimeZone.getTimeZone("UTC")); String fileName = String.format("satstat-%s.log", fmt.format(new Date(System.currentTimeMillis()))); File dumpFile = new File(dumpDir, fileName); PrintStream s;/* w ww . ja v a2s .c o m*/ try { InputStream buildInStream = getResources().openRawResource(R.raw.build); s = new PrintStream(dumpFile); s.append("SatStat build: "); int i; try { i = buildInStream.read(); while (i != -1) { s.write(i); i = buildInStream.read(); } buildInStream.close(); } catch (IOException e1) { e1.printStackTrace(); } s.append("\n\n"); e.printStackTrace(s); s.flush(); s.close(); Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri contentUri = Uri.fromFile(dumpFile); mediaScanIntent.setData(contentUri); c.sendBroadcast(mediaScanIntent); } catch (FileNotFoundException e2) { e2.printStackTrace(); } defaultUEH.uncaughtException(t, e); } }); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mSharedPreferences.registerOnSharedPreferenceChangeListener(this); prefUnitType = mSharedPreferences.getBoolean(Const.KEY_PREF_UNIT_TYPE, prefUnitType); prefKnots = mSharedPreferences.getBoolean(Const.KEY_PREF_KNOTS, prefKnots); prefCoord = Integer .valueOf(mSharedPreferences.getString(Const.KEY_PREF_COORD, Integer.toString(prefCoord))); prefUtc = mSharedPreferences.getBoolean(Const.KEY_PREF_UTC, prefUtc); prefCid = mSharedPreferences.getBoolean(Const.KEY_PREF_CID, prefCid); prefCid2 = mSharedPreferences.getBoolean(Const.KEY_PREF_CID2, prefCid2); prefWifiSort = Integer .valueOf(mSharedPreferences.getString(Const.KEY_PREF_WIFI_SORT, Integer.toString(prefWifiSort))); prefMapOffline = mSharedPreferences.getBoolean(Const.KEY_PREF_MAP_OFFLINE, prefMapOffline); prefMapPath = mSharedPreferences.getString(Const.KEY_PREF_MAP_PATH, prefMapPath); ActionBar actionBar = getSupportActionBar(); setContentView(R.layout.activity_main); // Find out default screen orientation Configuration config = getResources().getConfiguration(); WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); int rot = wm.getDefaultDisplay().getRotation(); isWideScreen = (config.orientation == Configuration.ORIENTATION_LANDSCAPE && (rot == Surface.ROTATION_0 || rot == Surface.ROTATION_180) || config.orientation == Configuration.ORIENTATION_PORTRAIT && (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270)); Log.d(TAG, "isWideScreen=" + Boolean.toString(isWideScreen)); // Create the adapter that will return a fragment for each of the // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); Context ctx = new ContextThemeWrapper(getApplication(), R.style.AppTheme); mTabLayout = new TabLayout(ctx); LinearLayout.LayoutParams mTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); mTabLayout.setLayoutParams(mTabLayoutParams); for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { TabLayout.Tab newTab = mTabLayout.newTab(); newTab.setIcon(mSectionsPagerAdapter.getPageIcon(i)); mTabLayout.addTab(newTab); } actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(mTabLayout); mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager)); mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout)); // This is needed by the mapsforge library. AndroidGraphicFactory.createInstance(this.getApplication()); // Get system services for event delivery locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mOrSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); mAccSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mGyroSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mMagSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mLightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); mProximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mPressureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); mHumiditySensor = sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); mTempSensor = sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); }
From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java
public static void broadcastA2dpPlayStatusChange(Context context, PlayerState state, DownloadService downloadService) { if (downloadService.getCurrentPlaying() != null) { Intent avrcpIntent = new Intent(CM_AVRCP_PLAYSTATE_CHANGED); Entry song = downloadService.getCurrentPlaying().getSong(); if (song == null) { return; }// w w w.ja v a2s . com if (song != currentSong) { currentSong = song; } String title = song.getTitle(); String artist = song.getArtist(); String album = song.getAlbum(); Integer duration = song.getDuration(); Integer listSize = downloadService.getDownloads().size(); Integer id = downloadService.getCurrentPlayingIndex() + 1; Integer playerPosition = downloadService.getPlayerPosition(); avrcpIntent.putExtra("track", title); avrcpIntent.putExtra("track_name", title); avrcpIntent.putExtra("artist", artist); avrcpIntent.putExtra("artist_name", artist); avrcpIntent.putExtra("album", album); avrcpIntent.putExtra("album_name", album); if (playerPosition != null) { avrcpIntent.putExtra("position", (long) playerPosition); } if (id != null) { avrcpIntent.putExtra("id", (long) id); } if (listSize != null) { avrcpIntent.putExtra("ListSize", (long) listSize); } if (duration != null) { avrcpIntent.putExtra("duration", (long) duration); } switch (state) { case STARTED: avrcpIntent.putExtra("playing", true); break; case STOPPED: avrcpIntent.putExtra("playing", false); break; case PAUSED: avrcpIntent.putExtra("playing", false); break; case COMPLETED: avrcpIntent.putExtra("playing", false); break; default: return; // No need to broadcast. } context.sendBroadcast(avrcpIntent); } }
From source file:org.hermes.android.NotificationsController.java
private void setBadge(final Context context, final int count) { notificationsQueue.postRunnable(new Runnable() { @Override/*from w w w. j a va 2s .com*/ public void run() { try { ContentValues cv = new ContentValues(); cv.put("tag", "org.hermes.messenger/org.hermes.ui.LaunchActivity"); cv.put("count", count); context.getContentResolver() .insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv); } catch (Throwable e) { //ignore } try { String launcherClassName = getLauncherClassName(context); if (launcherClassName == null) { return; } Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE"); intent.putExtra("badge_count", count); intent.putExtra("badge_count_package_name", context.getPackageName()); intent.putExtra("badge_count_class_name", launcherClassName); context.sendBroadcast(intent); } catch (Throwable e) { FileLog.e("tmessages", e); } } }); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Deletes a application desktop shortcut icon. * * This method need two additional permissions in the application: * * <code>//from ww w.j a v a2s. com * <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /> * </code> * * @param context The application context. * @param appClass Shortcut's activity class. * @param appName The shortcut's name */ public static void application_shortcutRemove_method1(Context context, Class appClass, String appName) { Intent shortcutIntent = new Intent(context, appClass); shortcutIntent.setAction(Intent.ACTION_MAIN); Intent delIntent = new Intent(); delIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); delIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName); // Inform launcher to remove shortcut delIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT"); context.sendBroadcast(delIntent); }
From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java
public static void broadcastA2dpMetaDataChange(Context context, DownloadService downloadService) { Entry song = null;/* ww w. j a va 2 s . c o m*/ Intent avrcpIntent = new Intent(CM_AVRCP_METADATA_CHANGED); if (downloadService != null) { DownloadFile entry = downloadService.getCurrentPlaying(); if (entry != null) { song = entry.getSong(); } } if (downloadService == null || song == null) { avrcpIntent.putExtra("track", ""); avrcpIntent.putExtra("track_name", ""); avrcpIntent.putExtra("artist", ""); avrcpIntent.putExtra("artist_name", ""); avrcpIntent.putExtra("album", ""); avrcpIntent.putExtra("album_name", ""); avrcpIntent.putExtra("ListSize", (long) 0); avrcpIntent.putExtra("id", (long) 0); avrcpIntent.putExtra("duration", (long) 0); avrcpIntent.putExtra("position", (long) 0); } else { if (song != currentSong) { currentSong = song; } String title = song.getTitle(); String artist = song.getArtist(); String album = song.getAlbum(); Integer duration = song.getDuration(); Integer listSize = downloadService.getDownloads().size(); Integer id = downloadService.getCurrentPlayingIndex() + 1; Integer playerPosition = downloadService.getPlayerPosition(); avrcpIntent.putExtra("track", title); avrcpIntent.putExtra("track_name", title); avrcpIntent.putExtra("artist", artist); avrcpIntent.putExtra("artist_name", artist); avrcpIntent.putExtra("album", album); avrcpIntent.putExtra("album_name", album); if (playerPosition != null) { avrcpIntent.putExtra("position", (long) playerPosition); } if (id != null) { avrcpIntent.putExtra("id", (long) id); } if (listSize != null) { avrcpIntent.putExtra("ListSize", (long) listSize); } if (duration != null) { avrcpIntent.putExtra("duration", (long) duration); } } context.sendBroadcast(avrcpIntent); }
From source file:com.androzic.plugin.tracker.SMSReceiver.java
@Override public void onReceive(Context context, Intent intent) { String Sender = ""; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Log.e(TAG, "SMS received"); Bundle extras = intent.getExtras();//w w w .jav a2s .co m if (extras == null) return; StringBuilder messageBuilder = new StringBuilder(); Object[] pdus = (Object[]) extras.get("pdus"); for (int i = 0; i < pdus.length; i++) { SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]); String text = msg.getMessageBody(); Sender = msg.getDisplayOriginatingAddress(); Log.w(TAG, "Sender: " + Sender); if (text == null) continue; messageBuilder.append(text); } String text = messageBuilder.toString(); boolean flexMode = prefs.getBoolean(context.getString(R.string.pref_tracker_use_flex_mode), context.getResources().getBoolean(R.bool.def_flex_mode)); Log.i(TAG, "SMS: " + text); Tracker tracker = new Tracker(); if (!parseXexunTK102(text, tracker) && !parseJointechJT600(text, tracker) && !parseTK102Clone1(text, tracker) && !(parseFlexMode(text, tracker) && flexMode)) return; if (tracker.message != null) { tracker.message = tracker.message.trim(); if ("".equals(tracker.message)) tracker.message = null; } tracker.sender = Sender; if (!"".equals(tracker.sender)) { // Save tracker data TrackerDataAccess dataAccess = new TrackerDataAccess(context); dataAccess.updateTracker(tracker); try { Application application = Application.getApplication(); tracker = dataAccess.getTracker(tracker.sender);//get latest positon of tracker application.sendTrackerOnMap(dataAccess, tracker); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } dataAccess.close(); context.sendBroadcast(new Intent(Application.TRACKER_DATE_RECEIVED_BROADCAST)); // Show notification boolean notifications = prefs.getBoolean(context.getString(R.string.pref_tracker_notifications), context.getResources().getBoolean(R.bool.def_notifications)); if (notifications) { Intent i = new Intent("com.androzic.COORDINATES_RECEIVED"); i.putExtra("title", tracker.message != null ? tracker.message : tracker.name); i.putExtra("sender", tracker.name); i.putExtra("origin", context.getApplicationContext().getPackageName()); i.putExtra("lat", tracker.latitude); i.putExtra("lon", tracker.longitude); String msg = context.getString(R.string.notif_text, tracker.name); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle(context.getString(R.string.app_name)); if (tracker.message != null) builder.setContentText(tracker.name + ": " + tracker.message); else builder.setContentText(msg); PendingIntent contentIntent = PendingIntent.getBroadcast(context, (int) tracker._id, i, PendingIntent.FLAG_ONE_SHOT); builder.setContentIntent(contentIntent); builder.setSmallIcon(R.drawable.ic_stat_tracker); builder.setTicker(msg); builder.setWhen(tracker.time); int defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND; boolean vibrate = prefs.getBoolean(context.getString(R.string.pref_tracker_vibrate), context.getResources().getBoolean(R.bool.def_vibrate)); if (vibrate) defaults |= Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); builder.setAutoCancel(true); Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify((int) tracker._id, notification); } // Conceal SMS boolean concealsms = prefs.getBoolean(context.getString(R.string.pref_tracker_concealsms), context.getResources().getBoolean(R.bool.def_concealsms)); if (concealsms) abortBroadcast(); } }