Skip to content

trindadedev13/c_android_assets_manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Native Android Assets Manager

  • A bridge between Java and C for android assets manager.

Public API

android_assets_manager_new(void)

Creates and returns a new android_assets_manager instance.

  • Parameters: None
  • Returns: struct android_assets_manager* or NULL on failure

Example:

struct android_assets_manager* manager = android_assets_manager_new();

void android_assets_manager_close(struct android_assets_manager* manager)

Closes and frees the manager instance.

  • Parameters:
    • manager: pointer to the manager instance

Example:

android_assets_manager_close(manager);

char* read_text_file(const char* filename)

Reads a UTF-8 text file from the assets/ directory.

  • Parameters:
    • filename: relative path to the asset file
  • Returns: char* containing null-terminated string, or NULL on failure
  • Note: You must free the returned pointer using free().

Example:

char* content = manager->read_text_file("data/config.json");
if (content) {
  puts(content);
  free(content);
}

struct int8_array_t* read_bin_file(const char* filename)

Reads a binary file from the assets/ directory.

  • Parameters:
    • filename: relative path to the asset file
  • Returns: struct int8_array_t* or NULL on failure
    (with data and len fields)

Example:

struct int8_array_t* bin = manager->read_bin_file("game.bin");  
if (bin) {  
  // Use bin->data and bin->len  
  free(bin->data);  
  free(bin);  
}

bool file_exists(const char* filename)

Checks whether the given file exists in the assets/ directory.

  • Parameters:
    • filename: relative path to the file
  • Returns: true if the file exists, false otherwise

Example:

if (manager->file_exists("readme.txt")) {  
  // File exists  
}

char** list_files(const char* directory, size_t* out_count)

Lists the files in a given directory inside assets/.

  • Parameters:
    • directory: path to the directory inside assets (with trailing slash)
    • out_count: pointer to receive the number of entries
  • Returns: char** array of filenames, or NULL on failure

Example:

size_t count;  
char** files = manager->list_files("textures/", &count);  
if (files) {  
  for (size_t i = 0; i < count; ++i) {  
    printf("File: %s\\n", files[i]);  
  }  
  manager->free_file_list(files, count);  
}

void free_file_list(char** list, size_t count)

Frees the memory allocated by list_files().

  • Parameters:
    • list: the list returned by list_files()
    • count: the number of elements

Example:

manager->free_file_list(files, count);

About

A bridge between Java and C for android assets manager.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors