mediaStore items can no longer be deleted after reinstall

Question relevant to Android platforms API 30 to 35, app is targeting api 33
My android application’s job is to synchronize users music library on a computer to android. That includes addition of media such as music, videos to android as well as deletion.
Addition and deletion works when app is installed, however on reinstall, app can add additional files during sync but if items need to be removed because user removed media from its library in computer it is failing. MediaItems can not be removed in android. There are several dozens of files that need adding or removing, sometimes 100s. The functions of addition and removal are below.

I understand that since api 29/30 if app is reinstalled it loses ownership of it’s files. But it makes no sense when user reinstalls the app, all the previously stored content is ignored and new directory is used to resync, How to solve this problem, what is the best solution.

   void addAudioToMediaStore(InputStream inStream) {      
    // Code to an audio media to mediastore
    Uri audioCollection = MediaStore.Audio.Media
                .getContentUri(MediaStor
    ContentValues songDetails = new ContentValues();
    songDetails.put(MediaStore.Audio.Media.DISPLAY_NAME,
            filename);

    songDetails.put(MediaStore.Audio.Media.RELATIVE_PATH,
            String.format("Music/Library/%s/%s/",artist,album));

    songDetails.put(MediaStore.Audio.Media.IS_PENDING, 1);

    Uri songContentUri = resolver
            .insert(audioCollection, songDetails);

    byte[] buffer = new byte[1024 * 250];
    long nTotalBytes = 0;

    try
    {
        OutputStream os = resolver.openOutputStream(songContentUri, "rw");

        while (nTotalBytes != size)
        {
            int nRead = inStream.read(buffer, 0, buffer.length);

            if (nRead >= 0) {
                os.write(buffer, 0, nRead);
                nTotalBytes += nRead;
            } else {
                Log.d("TEST API 30-35 MEDIASTORE", String.format("Warning() read returned -1"));
                                   break;
            }

        }

        os.flush();
        os.close();

    } catch (Exception e) {
        throw new RuntimeException(e);
    }finally {
     return false;

    }
    songDetails.clear();
    songDetails.put(MediaStore.Audio.Media.IS_PENDING, 0);
    int result  = resolver.update(songContentUri, songDetails, null, null);
    
    return true;
}

and delete works like this

 public int deleteMediaStoreRecords(String artist, String album, String filename) {

    Uri audioCollection = MediaStore.Audio.Media
                .getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
   

    String relativePath = "%Library/"+artist+"/"+album+"%";
    String selection = MediaStore.Audio.Media.DISPLAY_NAME + " LIKE ?" + " AND " + MediaStore.Audio.Media.RELATIVE_PATH + " LIKE ?" ;
    // TODO This will break if we have no matching item in the MediaStore.
    int numDeleted = context.getContentResolver().delete(audioCollection,
            selection,
            new String[]{filename,relativePath}
            );

    return numDeleted;
    }

Query mediaStore for files, find your files and request delete

createDeleteRequest

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật