zoukankan      html  css  js  c++  java
  • Android ContentProvider

    1:应用驱动学习

    letvRecorder 录制的音频不希望在Music app中显示,Music app 通过查询mediaData 来查找设备中的音频。

    通过判断字段 is_music = 0, 而通过

         ContentValues cv = new ContentValues();
            long current = System.currentTimeMillis();
            long modDate = file.lastModified();
            cv.put(MediaStore.Audio.Media.IS_MUSIC, "0");
            cv.put(MediaStore.Audio.Media.TITLE, entry.getRecordName());
            cv.put(MediaStore.Audio.Media.DATA, file.getAbsolutePath());
            cv.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
            cv.put(MediaStore.Audio.Media.DATE_MODIFIED, (int) (modDate / 1000));
            cv.put(MediaStore.Audio.Media.DURATION, entry.getRecordDuring());
            cv.put(MediaStore.Audio.Media.ARTIST,res.getString(R.string.audio_db_artist_name));
            cv.put(MediaStore.Audio.Media.ALBUM,res.getString(R.string.audio_db_album_name));
    //        Log.d(TAG, "Inserting audio record: " + cv.toString());
            ContentResolver resolver = getContentResolver();
            Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    //        Log.d(TAG, "ContentURI: " + base);
            Uri result = resolver.insert(base, cv);
    //只能添加指定的字段信息
            sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE));
    //系统获取媒体文件信息,然后保存到mediaData中
        
    好的处理方法是:
    1:系统扫描,添加信息到mediaData
    2: 回调方法作后续的处理
    //
    -->>>method 2 MediaScannerConnection.scanFile(context,new String[]{newFile.getAbsolutePath()},null,new MediaScannerConnection.OnScanCompletedListener(){ @Override public void onScanCompleted(String path, Uri uri) { if (uri!=null){ ContentValues cv = new ContentValues(); cv.put(MediaStore.Audio.Media.IS_MUSIC, "0"); context.getContentResolver().update(uri, cv, "is_music = ?", new String[]{"1"}); } } }); //<<<--method 2

     

  • 相关阅读:
    ssi服务器端指令
    json格式的转换为json字符串函数
    接口测试基础和jmeter
    【JZOJ6274】梦境
    【JZOJ6275】小L的数列
    【luoguP4721】分治 FFT
    【luoguP3868】猜数字
    中国剩余定理与扩展中国剩余定理
    【JZOJ6277】矩阵游戏
    【JZOJ6271】锻造 (forging)
  • 原文地址:https://www.cnblogs.com/conncui/p/ContentProvider-Android.html
Copyright © 2011-2022 走看看