现在的位置: 首页 > 综合 > 正文

Android Music中的一个URI:”content://media/external/fs_id”

2017年09月20日 ⁄ 综合 ⁄ 共 742字 ⁄ 字号 评论关闭
  • MediaPlaybackService中调用MusicUtils的Getcardid()获取了一个id,如下:static
    int getCardId(Context context) {
            ContentResolver res = context.getContentResolver();
            Cursor c = res.query(Uri.parse("content://media/external/fs_id"), null, null, null, null);
            int id = -1;
            if (c != null) {
                c.moveToFirst();
                id = c.getInt(0);
                c.close();
            }
            return id;
    }
     content://media/external/fs_id fs_id:唯一文件系统标识号,也就是定死的 个人理解是:此URL返回Sdcard上和fs_id对应的存储路径下所有媒体文件 content://media/external/fs_id此URL决定了ContentResolver 应该与哪一个ContentProvider对话即和此\packages\providers\MediaProvider\src\com\android\providers\media\MediaProvider.java对话。刚才又看了下代码,有这么一句话"//
    Only restore the saved playlist if the card is still the same one as when the playlist was saved",看来通过这个URI获取到的是标示外部存储设备的ID,当我们更换SD卡时,通过这个获取到的ID会改变。

抱歉!评论已关闭.