Example usage for android.content ContentValues put

List of usage examples for android.content ContentValues put

Introduction

In this page you can find the example usage for android.content ContentValues put.

Prototype

public void put(String key, byte[] value) 

Source Link

Document

Adds a value to the set.

Usage

From source file:Main.java

public static boolean installRingtone(final Context context, int resid, final String toneName) {

    String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
    String filename = toneName + ".mp3";
    File fileAlarms = new File(exStoragePath, "/Notifications");
    final File fileTone = new File(fileAlarms, filename);

    if (fileTone.exists())
        return false;

    boolean exists = fileAlarms.exists();
    if (!exists) {
        fileAlarms.mkdirs();//from w w w . j av  a 2  s .c o  m
    }

    if (fileTone.exists())
        return false;

    byte[] buffer = null;
    InputStream fIn = context.getResources().openRawResource(resid);
    int size = 0;

    try {
        size = fIn.available();
        buffer = new byte[size];
        fIn.read(buffer);
        fIn.close();
    } catch (IOException e) {
        return false;
    }

    FileOutputStream save;
    try {
        save = new FileOutputStream(fileTone);
        save.write(buffer);
        save.flush();
        save.close();
    } catch (FileNotFoundException e) {
        return false;
    } catch (IOException e) {
        return false;
    }

    MediaScannerConnection.scanFile(context, new String[] { fileTone.getAbsolutePath() }, null,
            new MediaScannerConnection.OnScanCompletedListener() {

                @Override
                public void onScanCompleted(String path, Uri uriTone) {

                    ContentValues values = new ContentValues();
                    values.put(MediaStore.MediaColumns.DATA, fileTone.getAbsolutePath());
                    values.put(MediaStore.MediaColumns.TITLE, toneName);
                    values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/mp3");
                    values.put(MediaStore.Audio.Media.ARTIST, "zom");

                    //new
                    values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
                    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
                    values.put(MediaStore.Audio.Media.IS_ALARM, true);
                    values.put(MediaStore.Audio.Media.IS_MUSIC, false);

                    // Insert it into the database
                    Uri newUri = context.getContentResolver().insert(uriTone, values);

                    //                RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri);

                    //   Settings.System.putString(context.getContentResolver(),
                    //         Settings.System.RINGTONE, uri.toString());

                }
            });

    return true;
}

From source file:mx.com.adolfogarcia.popularmovies.data.TestUtilities.java

/**
 * Returns the values of a row that may be inserted into the movie database.
 *
 * @return the values of a row that may be inserted into the movie database.
 *///from w  w w  . jav a  2s .co m
static ContentValues createMadMaxMovieReviewValues() {
    ContentValues testValues = new ContentValues();
    testValues.put(CachedMovieReviewEntry.COLUMN_MOVIE_API_ID, 76341);
    testValues.put(CachedMovieReviewEntry.COLUMN_API_ID, "55edd26792514106d600e380");
    testValues.put(CachedMovieReviewEntry.COLUMN_AUTHOR, "extoix");
    testValues.put(CachedMovieReviewEntry.COLUMN_CONTENT, "Awesome movie!");
    testValues.put(CachedMovieReviewEntry.COLUMN_URL, "http://j.mp/1hQIOdj");
    return testValues;
}

From source file:mx.com.adolfogarcia.popularmovies.data.TestUtilities.java

/**
 * Returns the values of a row that may be inserted into the movie database.
 *
 * @return the values of a row that may be inserted into the movie database.
 *//*from  w  w w.j ava  2  s .c  o  m*/
static ContentValues createMadMaxMovieVideoValues() {
    ContentValues testValues = new ContentValues();
    testValues.put(CachedMovieVideoEntry.COLUMN_MOVIE_API_ID, 76341);
    testValues.put(CachedMovieVideoEntry.COLUMN_API_ID, "551afc679251417fd70002b1");
    testValues.put(CachedMovieVideoEntry.COLUMN_LANGUAGE, "en");
    testValues.put(CachedMovieVideoEntry.COLUMN_KEY, "jnsgdqppAYA");
    testValues.put(CachedMovieVideoEntry.COLUMN_NAME, "Trailer 2");
    testValues.put(CachedMovieVideoEntry.COLUMN_NAME, "Trailer 2");
    testValues.put(CachedMovieVideoEntry.COLUMN_SITE, "YouTube");
    testValues.put(CachedMovieVideoEntry.COLUMN_SIZE, 720);
    testValues.put(CachedMovieVideoEntry.COLUMN_TYPE, "Trailer");
    return testValues;
}

From source file:mx.com.adolfogarcia.popularmovies.data.TestUtilities.java

/**
 * Returns the values of a row that may be inserted into the movie database.
 *
 * @return the values of a row that may be inserted into the movie database.
 *///from  w w w.ja  va 2s.  c o  m
static ContentValues createMadMaxMovieValues() {
    ContentValues testValues = new ContentValues();
    testValues.put(CachedMovieEntry.COLUMN_API_ID, 76341);
    testValues.put(CachedMovieEntry.COLUMN_BACKDROP_PATH, "/tbhdm8UJAb4ViCTsulYFL3lxMCd.jpg");
    testValues.put(CachedMovieEntry.COLUMN_RELEASE_DATE, 1431648000000L);
    testValues.put(CachedMovieEntry.COLUMN_ORIGINAL_TITLE, "Mad Max: Fury Road");
    testValues.put(CachedMovieEntry.COLUMN_OVERVIEW, "An apocalyptic story...");
    testValues.put(CachedMovieEntry.COLUMN_POPULARITY, 55.32);
    testValues.put(CachedMovieEntry.COLUMN_POSTER_PATH, "/kqjL17yufvn9OVLyXYpvtyrFfak.jpg");
    testValues.put(CachedMovieEntry.COLUMN_VOTE_AVERAGE, 7.7);
    testValues.put(CachedMovieEntry.COLUMN_MOST_POPULAR, BooleanUtils.toInteger(true));
    testValues.put(CachedMovieEntry.COLUMN_HIGHEST_RATED, BooleanUtils.toInteger(false));
    testValues.put(CachedMovieEntry.COLUMN_USER_FAVORITE, BooleanUtils.toInteger(false));
    return testValues;
}

From source file:edu.mit.mobile.android.locast.data.Locatable.java

/**
 * Adds the appropriate {@link Columns#_LATITUDE}, {@link Columns#_LONGITUDE} columns to the given {@link ContentValues} for the given location.
 * @param cv//from w w w  . j a  v  a  2 s . com
 * @param location
 * @return the same {@link ContentValues} that was passed in.
 */
public static ContentValues toContentValues(ContentValues cv, GeoPoint location) {
    cv.put(Columns._LATITUDE, location.getLatitudeE6() / 1E6d);
    cv.put(Columns._LONGITUDE, location.getLongitudeE6() / 1E6d);

    return cv;
}

From source file:Main.java

/**
 * Put an arbitrary object into a {@link ContentValues}
 *
 * @param target the ContentValues store
 * @param key the key to use/*from  www . j  av a2 s . c  o  m*/
 * @param value the value to store
 */
public static void putInto(ContentValues target, String key, Object value, boolean errorOnFail) {
    if (value == null) {
        target.putNull(key);
    } else if (value instanceof Boolean) {
        target.put(key, (Boolean) value);
    } else if (value instanceof Byte) {
        target.put(key, (Byte) value);
    } else if (value instanceof Double) {
        target.put(key, (Double) value);
    } else if (value instanceof Float) {
        target.put(key, (Float) value);
    } else if (value instanceof Integer) {
        target.put(key, (Integer) value);
    } else if (value instanceof Long) {
        target.put(key, (Long) value);
    } else if (value instanceof Short) {
        target.put(key, (Short) value);
    } else if (value instanceof String) {
        target.put(key, (String) value);
    } else if (value instanceof byte[]) {
        target.put(key, (byte[]) value);
    } else if (errorOnFail) {
        throw new UnsupportedOperationException("Could not handle type " + value.getClass());
    }
}

From source file:cn.sharesdk.analysis.db.MessageUtils.java

/**
 * ??//  w ww  .ja  v a  2  s .c o m
 * @param c
 * @param msg
 */
public static synchronized long insertMsg(Context c, String type, String data) {
    if (TextUtils.isEmpty(data)) {
        return -1;
    }
    DBProvider provider = DBProvider.getDBProvider(c);
    ContentValues value = new ContentValues();
    value.put(DBHelp.COLUMN_EVENT_TYPE, type);
    value.put(DBHelp.COLUMN_EVENT_DATA, data);

    long id = provider.insert(DBHelp.TABLE_STATISTICS, value);
    //Ln.e("threadID == %s, insert ID == %s ", time , id);
    return id;

}

From source file:com.dahl.brendan.wordsearch.view.IOService.java

private static void readFile(Context context, File file, boolean overwrite) {
    if (file.canRead()) {
        if (overwrite) {
            context.getContentResolver().delete(Word.CONTENT_URI, "1", null);
        }//from  ww  w. j a v  a2  s.com
        try {
            byte[] buffer = new byte[(int) file.length()];
            BufferedInputStream f = new BufferedInputStream(new FileInputStream(file));
            f.read(buffer);
            JSONArray array = new JSONArray(new String(buffer));
            List<ContentValues> values = new LinkedList<ContentValues>();
            for (int i = 0; i < array.length(); i++) {
                Log.v(LOGTAG, array.getString(i));
                ContentValues value = new ContentValues();
                value.put(Word.WORD, array.getString(i));
                values.add(value);
            }
            context.getContentResolver().bulkInsert(Word.CONTENT_URI, values.toArray(new ContentValues[0]));
        } catch (IOException e) {
            Log.e(LOGTAG, "IO error", e);
        } catch (JSONException e) {
            Log.e(LOGTAG, "bad input", e);
        }
    }
}

From source file:com.onesignal.NotificationBundleProcessor.java

private static void saveNotification(Context context, Bundle bundle, boolean opened, int notificationId) {
    try {//from   w w  w.  j  a  va  2  s  .co  m
        JSONObject customJSON = new JSONObject(bundle.getString("custom"));

        OneSignalDbHelper dbHelper = new OneSignalDbHelper(context);
        SQLiteDatabase writableDb = dbHelper.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(NotificationTable.COLUMN_NAME_NOTIFICATION_ID, customJSON.getString("i"));
        if (bundle.containsKey("grp"))
            values.put(NotificationTable.COLUMN_NAME_GROUP_ID, bundle.getString("grp"));

        values.put(NotificationTable.COLUMN_NAME_OPENED, opened ? 1 : 0);
        if (!opened)
            values.put(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, notificationId);

        if (bundle.containsKey("title"))
            values.put(NotificationTable.COLUMN_NAME_TITLE, bundle.getString("title"));
        values.put(NotificationTable.COLUMN_NAME_MESSAGE, bundle.getString("alert"));

        values.put(NotificationTable.COLUMN_NAME_FULL_DATA, bundleAsJSONObject(bundle).toString());

        writableDb.insert(NotificationTable.TABLE_NAME, null, values);

        // Clean up old records that have been dismissed or opened already after 1 week.
        writableDb.delete(NotificationTable.TABLE_NAME,
                NotificationTable.COLUMN_NAME_CREATED_TIME + " < "
                        + ((System.currentTimeMillis() / 1000) - 604800) + " AND " + "("
                        + NotificationTable.COLUMN_NAME_DISMISSED + " = 1 OR "
                        + NotificationTable.COLUMN_NAME_OPENED + " = 1" + ")",
                null);

        writableDb.close();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:fr.mixit.android.utils.SyncUtils.java

public static void updateLocalMd5(ContentResolver resolver, String url, String md5) {
    final String syncId = MixItContract.Sync.generateSyncId(url);
    final ContentValues contentValues = new ContentValues();
    contentValues.put(MixItContract.Sync.URI_ID, syncId);
    contentValues.put(MixItContract.Sync.URI, url);
    contentValues.put(MixItContract.Sync.MD5, md5);
    resolver.insert(MixItContract.Sync.CONTENT_URI, contentValues);
}