Example usage for android.app Activity sendBroadcast

List of usage examples for android.app Activity sendBroadcast

Introduction

In this page you can find the example usage for android.app Activity sendBroadcast.

Prototype

@Override
    public void sendBroadcast(Intent intent) 

Source Link

Usage

From source file:Main.java

public static void saveImageSendBroadcast(Activity activity, String filePath) {
    activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + filePath)));
    //  com.hss01248.lib.activity. sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory()+ filePath)));
}

From source file:Main.java

/**
 * copy current image to Gallery/*from  ww  w .j av  a2 s  .c o  m*/
 */
public static void galleryAddPic(Uri currentImageUri, Activity activity) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(currentImageUri);
    activity.sendBroadcast(mediaScanIntent);
}

From source file:Main.java

public static void disImage(Activity act, File file) {
    Intent itt = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    itt.setData(Uri.fromFile(file));//from  www  .  ja  v a 2  s .co m
    act.sendBroadcast(itt);

    Intent it = new Intent(Intent.ACTION_VIEW);
    it.setDataAndType(Uri.parse(file.getPath()), "image/*");
    act.startActivity(it);
}

From source file:org.openmidaas.app.common.Utils.java

private static void setValueAndPersist(Activity activity, GenericAttribute attribute, String value) {
    try {//from  ww w  .j a  va 2 s .c  o  m
        attribute.setValue(value.toString());
        attribute.save();
        activity.sendBroadcast(new Intent().setAction(Intents.ATTRIBUTE_LIST_CHANGE_EVENT));
    } catch (InvalidAttributeValueException e) {
        DialogUtils.showNeutralButtonDialog(activity, activity.getString(R.string.defaultErrorDialogTitle),
                "Invalid value ");
    } catch (MIDaaSException e) {
        DialogUtils.showNeutralButtonDialog(activity, activity.getString(R.string.defaultErrorDialogTitle),
                e.getError().getErrorMessage());
    }
}

From source file:com.samknows.measurement.util.LoginHelper.java

public static void logout(Activity parent) {
    parent.startActivity(new Intent(parent, SamKnowsLogin.class));

    AppSettings.getInstance().clearAll();
    AppSettings.getInstance().setServiceActivated(false);
    CachingStorage.getInstance().dropExecutionQueue();
    CachingStorage.getInstance().dropParamsManager();

    Intent broadcastIntent = new Intent();
    broadcastIntent.setAction(Constants.INTENT_ACTION_LOGOUT);
    parent.sendBroadcast(broadcastIntent);
}

From source file:org.onebusaway.android.directions.realtime.RealtimeService.java

/**
 * Start realtime updates.//from  www.j a  v  a2  s.c  o  m
 *
 * @param source Activity from which updates are started
 * @param bundle Bundle with selected itinerary/parameters
 */
public static void start(Activity source, Bundle bundle) {

    SharedPreferences prefs = Application.getPrefs();
    if (!prefs.getBoolean(OTPConstants.PREFERENCE_KEY_LIVE_UPDATES, true)) {
        return;
    }

    bundle.putSerializable(OTPConstants.NOTIFICATION_TARGET, source.getClass());
    Intent intent = new Intent(OTPConstants.INTENT_START_CHECKS);
    intent.putExtras(bundle);
    source.sendBroadcast(intent);
}

From source file:com.todoroo.astrid.activity.FilterListFragment.java

/**
 * Creates a shortcut on the user's home screen
 *
 * @param shortcutIntent/*from   w ww .j  a  v a 2s.co m*/
 * @param label
 */
private static void createShortcut(Activity activity, Filter filter, Intent shortcutIntent, String label) {
    if (label.length() == 0)
        return;

    Bitmap bitmap = superImposeListIcon(activity, filter.listingIcon, filter.listingTitle);

    Intent createShortcutIntent = new Intent();
    createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
    createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
    createShortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); //$NON-NLS-1$

    activity.sendBroadcast(createShortcutIntent);
    Toast.makeText(activity, activity.getString(R.string.FLA_toast_onCreateShortcut, label), Toast.LENGTH_LONG)
            .show();
}

From source file:com.ubuntuone.android.files.fragment.AutoUploadCustomizeFragment.java

@SuppressWarnings("unused")
private void rescanWithMediaScanner() {
    final String primaryStorage = Environment.getExternalStorageDirectory().getAbsolutePath();
    final String secondaryStorage = Preferences.getSecondaryStorageDirectory().getAbsolutePath();

    Intent primaryStorageIntent = new Intent(Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" + primaryStorage));
    Intent secondaryStorageIntent = new Intent(Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" + secondaryStorage));

    Activity activity = getActivity();
    activity.sendBroadcast(primaryStorageIntent);
    activity.sendBroadcast(secondaryStorageIntent);
}

From source file:com.dnielfe.manager.utils.SimpleUtils.java

public static void createShortcut(Activity main, String path) {
    File file = new File(path);

    try {/* w w w.j av a  2  s  .co m*/
        // Create the intent that will handle the shortcut
        Intent shortcutIntent = new Intent(main, Browser.class);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        shortcutIntent.putExtra(Browser.EXTRA_SHORTCUT, path);

        // The intent to send to broadcast for register the shortcut intent
        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, file.getName());
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(main, R.drawable.ic_launcher));
        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        main.sendBroadcast(intent);

        Toast.makeText(main, main.getString(R.string.shortcutcreated), Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Toast.makeText(main, main.getString(R.string.error), Toast.LENGTH_SHORT).show();
    }
}

From source file:Main.java

public static Bitmap saveBitmapToFile(Activity activity, Bitmap bitmap) {
    String mPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
    File imageFile = new File(mPath);
    boolean create = imageFile.mkdirs();
    boolean canWrite = imageFile.canWrite();
    Calendar cal = Calendar.getInstance();
    String date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);

    String filename = null;//from w  w  w .j  a  va 2s.  c om
    int i = 0;
    while (imageFile.exists()) {
        i++;
        filename = date + "_mandelbrot" + i + ".png";
        imageFile = new File(mPath, filename);
        boolean canWrite2 = imageFile.canWrite();

    }

    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        /*resultB*/bitmap.compress(CompressFormat.PNG, 90, bos);
        byte[] bitmapdata = bos.toByteArray();

        //write the bytes in file
        FileOutputStream fos = new FileOutputStream(imageFile);
        fos.write(bitmapdata);
        fos.flush();
        fos.close();

        Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        intent.setData(Uri.fromFile(imageFile));
        activity.sendBroadcast(intent);

        displaySuccesToast(activity);
    } catch (FileNotFoundException e) {
        displayFileError(activity);
        e.printStackTrace();
    } catch (IOException e) {
        displayFileError(activity);
        e.printStackTrace();
    }
    return bitmap;
}