{"id":21884661,"url":"https://github.com/onehilltech/android-metadata","last_synced_at":"2025-04-15T07:19:28.949Z","repository":{"id":14086053,"uuid":"16789868","full_name":"onehilltech/android-metadata","owner":"onehilltech","description":"A library for reading meta-data from AndroidManifest.xml","archived":false,"fork":false,"pushed_at":"2018-11-13T05:00:26.000Z","size":151,"stargazers_count":43,"open_issues_count":2,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-15T07:19:21.981Z","etag":null,"topics":["android","android-metadata","androidmanifest","annotations","java","metadata"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onehilltech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-13T02:53:19.000Z","updated_at":"2024-11-02T04:49:22.000Z","dependencies_parsed_at":"2022-09-25T13:44:32.354Z","dependency_job_id":null,"html_url":"https://github.com/onehilltech/android-metadata","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onehilltech%2Fandroid-metadata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onehilltech%2Fandroid-metadata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onehilltech%2Fandroid-metadata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onehilltech%2Fandroid-metadata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onehilltech","download_url":"https://codeload.github.com/onehilltech/android-metadata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249023745,"owners_count":21199961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-metadata","androidmanifest","annotations","java","metadata"],"created_at":"2024-11-28T10:15:14.405Z","updated_at":"2025-04-15T07:19:28.930Z","avatar_url":"https://github.com/onehilltech.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"android-metadata\n==================\n\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-android--metadata-green.svg?style=true)](https://android-arsenal.com/details/1/4045)\n[![Download](https://jitpack.io/v/onehilltech/android-metadata.svg)](https://jitpack.io/#onehilltech/android-metadata)\n[![Build Status](https://travis-ci.org/onehilltech/android-metadata.svg)](https://travis-ci.org/onehilltech/android-metadata)\n[![codecov.io](http://codecov.io/github/onehilltech/android-metadata/coverage.svg?branch=master)](http://codecov.io/github/onehilltech/android-metadata?branch=master)\n\nA utility library for Android designed to simplify reading meta-data\nvalues from AndroidManifest.xml.\n\n* **Quickly** access a meta-data values from anywhere with few lines of code.\n* Read individual meta-data values into **type-specific** variables.\n* **Instantiate** objects from meta-data values.\n* Read one or more meta-data values into **annotated** Java classes.\n* Use meta-data values to pass configuration parameters to **third-party libraries**.\n\n## Installation\n\n#### Gradle\n\n```\nbuildscript {\n  repositories {\n    maven { url \"https://jitpack.io\" }\n  }\n}\n\ndependencies {\n  compile com.github.onehilltech:android-metadata:x.y.z\n}\n```\n\n## Getting Started\n\nHere is the quickest and easiest way to load the metadata from AndroidManifest.xml\nand get a value. The value, by default, is a String value type.\n\n```java\nManifestMetadata metadata = ManifestMetadata.get (context);\n\n// \u003cmeta-data android:name=\"appid\" android:value=\"32ba65ae723940\" /\u003e\nString value = metadata.getValue (\"appid\");\n```\n\nIf the value is not a String type, then you can provide a hint:\n\n```java\nManifestMetadata metadata = ManifestMetadata.get (context);\n\n// \u003cmeta-data android:name=\"conn.timeout\" android:value=\"60\" /\u003e\nInteger connTimeout = metadata.getValue (\"conn.timeout\", Integer.class);\n```\n\nYou can even directly load a resource from the metadata:\n\n```java\nManifestMetadata metadata = ManifestMetadata.get (context);\n\n// \u003cmeta-data android:name=\"appname\" android:resource=\"@string/app_name\" /\u003e\nString appName = metadata.getValue (\"appname\", true, String.class);\n```\n\nIn some cases, you may need to provide additional information about\nthe resource type since different resources types can have the same \nJava type:\n\n```java\nManifestMetadata metadata = ManifestMetadata.get (context);\n\n// \u003cmeta-data android:name=\"bgcolor\" android:resource=\"@color/background\" /\u003e\nInteger bgColor = metadata.getValue (\"bgcolor\", true, Integer.class, ResourceType.Color);\n```\n\n## Using Annotations to Load Metadata\n\nHere is the simplest example of using an annotation to define what \nmeta-data value in AndroidManifest.xml it should be initialized with:\n\n```java\npublic class MyData {\n  private String appid_;\n  \n  @MetadataProperty (name=\"my.message\")\n  public String message;\n  \n  @MetadataMethod (name=\"appid\")\n  public void setAppId (String appid) {\n    this.appid_ = appid;\n  }\n}\n```\n\nIn the example above, the field **message** will be initialized with \nthe value of meta-data tag named **my.message**. You initialize all \nvalues with the **@Metadata** annotation using a single line of code:\n\n```java\nMyData myData = new MyData ();\nManifestMetadata.get (context).initFromMetadata (myData);\n```\n\nThis method will auto-detect the target type, and then assign the value. \nIf the field is not assignable using the meta-data's value, then an \nexception will be thrown.\n\n### Reading from a Resource\n\nIn some cases, you will want to read the value from a resource (i.e., \nyou use android:resource in the meta-data tag). You can use the **@Metadata** \nannotation to read resource values as well:\n\n```java\npublic class MyData {\n  private String appid_;\n  \n  @MetadataProperty (name=\"my.message\", fromResource=true)\n  public String message;\n\n  @MetadataMethod (name=\"appid\", fromResource=true)\n  public void setAppId (String appid) {\n    this.appid_ = appid;\n  }\n}\n```\n\n### Giving Resource Type Hints\n\nThere are some resources that have the same field type, such as integer \nand color. This makes it hard to auto-detect the resources type. We can\ntherefore provide a hint as follows:\n\n```java\npublic class MyData {\n  @MetadataProperty (name=\"my.message\", fromResource=true, resourceType=ResourceType.Color)\n  public int backgroundColor;\n}\n```\n\nIn the example above, the value for **backgroundColor** will be loaded \nfrom resources and interpreted as a color.\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonehilltech%2Fandroid-metadata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonehilltech%2Fandroid-metadata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonehilltech%2Fandroid-metadata/lists"}