Skip to content

Commit

Permalink
feat: update readme with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
xXDeonoXx committed May 2, 2022
1 parent 93fed4c commit 4e0a6e6
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,52 @@ this package allows you to access wallpaper tools from native apis
## Installation

```sh
npm install rn-manage-wallpaper
yarn add rn-manage-wallpaper
```

## After install run this to link the packages.
```sh
yarn android
```

## permissions

this package needs the following permissions:

```xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
```

## Usage

WallpaperManager has one function called setWallpaper that receives 2 arguments, file uri and a flag that indicates whenever it will be set as lock screen or system screen, [FLAG_LOCK](https://developer.android.com/reference/android/app/WallpaperManager#FLAG_LOCK) and [FLAG_SYSTEM](https://developer.android.com/reference/android/app/WallpaperManager#FLAG_SYSTEM) for reference, you can get their values using the getConstants function.

## Example

in this example i use RNFetchBlob to donwload a web image and use the cache file path to define the wallpaper

```js
import WallpaperManager from 'rn-manage-wallpaper';

// ...

const result = await WallpaperManager.multiply(3, 7);
```
const FLAG_CONSTANTS = WallpaperManager.getConstants();
RNFetchBlob.config({
// add this option that makes response data to be stored as a file,
fileCache: true,
})
.fetch('GET', image.url, {
//some headers ..
})
.then(res => {
try {
WallpaperManager.setWallpaper(`${res.path()}`, FLAG_CONSTANTS.FLAG_SYSTEM);
} catch (error) {
console.log(error);
}
});
```

## Contributing

Expand Down

0 comments on commit 4e0a6e6

Please sign in to comment.