Coder Social home page Coder Social logo

capacitor-community / app-icon Goto Github PK

View Code? Open in Web Editor NEW
72.0 5.0 18.0 13.33 MB

Capacitor plugin to programmatically change the app icon.

License: MIT License

Ruby 6.71% Objective-C 3.18% Swift 27.06% JavaScript 1.60% TypeScript 19.51% CSS 4.11% HTML 10.03% Java 27.81%
capacitor capacitor-plugin

app-icon's Introduction


App Icon

@capacitor-community/app-icon

Capacitor community plugin for managing an app's icon. The main feature being that you can programmatically change the app icon.


Maintainers

Maintainer GitHub Social
John Borges johnborges @johnborges

Before Starting

This plugin only changes the main app icon on the device homescreen. The icon in springboard and in other areas will not change and continue to show the original. (iOS)

Changing the app icon is only allowed when the app is in the foreground (iOS).

Android support is currently in beta. See the android-support branch for more info.

Installation

npm install @capacitor-community/app-icon
npx cap sync

Configuration

The alternate icons need to be included within the app bundle and referenced in the project prior to using this plugin. It is not possible to switch to any icon on the fly without adding it to the project first. Below are the configurations steps for each platform.

Android Configuration

Add Alternate Icons

Add the alternate icons directly to your android project in app/src/main/res.

Setup ApplicationManifest.xml

Each alternate icon is represented by an <activity-alias>. Add all the alternative icons to the ApplicationManifest.xml as child elements under <application>. The name attribute on <activity-alias> must be prefixed with dot . See ApplicationManifest.xml for full example.

<application>
    <!-- ... -->
    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:launchMode="singleTask"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
        android:label="@string/title_activity_main"
        android:theme="@style/AppTheme.NoActionBarLaunch">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <!-- <category android:name="android.intent.category.LAUNCHER" /> -->
        </intent-filter>

    </activity>
    <activity-alias
        android:label="Stencil"
        android:icon="@drawable/stencil"
        android:roundIcon="@drawable/stencil"
        android:name=".stencil"
        android:enabled="true"
        android:exported="true"
        android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity-alias>
  
  <!-- additional <activity-alias> -->

<application>

iOS Configuration

Taken from https://www.youtube.com/watch?v=AT89ofYpWTU

Create the alternate icons in assets catalog

In XCode go to Assets and create the App Icons.
Then fill with images 1024x1024px

XCode Assets Alternate Icons

The name of the asset should correspond to the name used in the code

Change build settings

  1. Visit Build Settings
  2. Search For App icon,
  3. Select "yes" for Include All App Icon Assets
  4. Include a list (in Alternate App Icon Sets) with precise names of the app icons in the Assets Catalogue.

Build Settings XCode

Usage

import { AppIcon } from '@capacitor-community/app-icon';

const changeIcon = async (iconName) => {
  await AppIcon.change({name: iconName, suppressNotification: true});
}

const getName = async () => {
  const { value } = await AppIcon.getName();
  console.log(value);
}

const resetIcon = async () => {
  const disable: string[] = ['stencil']; // all added aliaces names 
  await AppIcon.reset({ suppressNotification: true, disable });
}

API

isSupported()

isSupported() => Promise<{ value: boolean; }>

Checks if changing the app icon is supported. (iOS only)

Returns: Promise<{ value: boolean; }>

Since: 1.0.0


getName()

getName() => Promise<{ value: string | null; }>

Gets the name of currently set alternate icon. If original icon is set, returns null.

Returns: Promise<{ value: string | null; }>

Since: 1.0.0


change(...)

change(options: IconOptions) => Promise<void>

Changes app icon to specified alternate.

Param Type
options IconOptions

Since: 1.0.0


reset(...)

reset(options: ResetOptions) => Promise<void>

Reverts app icon to original.

Param Type
options ResetOptions

Since: 1.0.0


Interfaces

IconOptions

Prop Type Description Since
name string Name of alternate icon to set
disable string[] Name of icons to disable. This is not used for iOS, but required for Android. 3.1.0
suppressNotification boolean Flag controlling the in app notification which shows after icon is changed. (iOS)

ResetOptions

Prop Type Description Since
suppressNotification boolean Flag controlling the in app notification which shows after icon is changed (iOS).
disable string[] Name of icons to disable. This is not used for iOS, but required for Android. 3.1.1

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

John Borges
John Borges

๐Ÿ’ป
Simon Grimm
Simon Grimm

๐Ÿ’ป
Christian von Rohr
Christian von Rohr

๐Ÿ’ป
QliQ.dev
QliQ.dev

๐Ÿ’ป
Hadouin
Hadouin

๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

app-icon's People

Contributors

aeharding avatar allcontributors[bot] avatar dependabot[bot] avatar johnborges avatar qliqdev avatar saimon24 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

app-icon's Issues

getName() returns undefined on Android

Describe the bug

Calling getName() on Android returns undefined.

This can be tested by adding a call to getName() in the example app and observing it does not work.

To Reproduce
Steps to reproduce the behavior:

  1. Add a call to getName() after example app startup with alert(name).
  2. Restart app (optionally setting a custom icon first)
  3. Observe alert with undefined

Expected behavior

getName() should work like iOS

Smartphone (please complete the following information):

  • Device: Pixel 7a
  • OS: Android 13

On Android, adding activity-alias causes multiple icons on my homescreen

Bug Report

Plugin Version

Latest

Capacitor Version

Latest Dependencies:

@capacitor/cli: 5.6.0
@capacitor/core: 5.6.0
@capacitor/android: 5.6.0
@capacitor/ios: 5.6.0

Installed Dependencies:

@capacitor/cli: 5.1.1
@capacitor/core: 5.1.1
@capacitor/android: 5.6.0
@capacitor/ios: 5.6.0

Platform(s)

Android

Current Behavior

When setting it up, i added all the activity-alias. When running on my android device; i get tons of icons, one for each alias.

Expected Behavior

Only the main icon should be shown

AppIcon.change('icon_name') returns -1

Describe the bug

I'm using @capacitor-community/app-icon version 3.1.0-beta.0 in my android project.
Following code returns -1 as response:

AppIcon.change({name: 'ic_launcher2', suppressNotification: true}).then(response =>{
console.log(response);
});

And app icon doesn't change.

I added activity and activity-alias to AndroidManifest.xml like this:

  <activity
        android:exported="true"
        android:name="pro.lifa.app.MainActivity"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
        android:hardwareAccelerated="true"
        android:label="@string/title_activity_main"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBarLaunch"
        android:supportsPictureInPicture="true"
        android:windowSoftInputMode="adjustResize"
         tools:targetApi="n">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>

            <data android:host="web.lifa.pro"
                  android:scheme="https"/>

            <data android:host="web.lifa.pro"
                  android:scheme="http"/>
        </intent-filter>
    </activity>



    <activity-alias
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:name=".ic_launcher"
        android:enabled="true"
        android:exported="true"
        android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity-alias>




    <activity-alias
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher2"
        android:roundIcon="@mipmap/ic_launcher2_round"
        android:name=".ic_launcher2"
        android:enabled="false"
        android:exported="true"
        android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity-alias>

Expected behavior
AppIcon.change('icon_name') must change the app icon.

Screenshots
Console log:
Screenshot 2023-01-16 at 12 08 29 PM

Smartphone

  • Device: Pixel 6 Emulator
  • OS: android API 31

Additional context

  • minSdkVersion = 22
  • compileSdkVersion = 32
  • targetSdkVersion = 32

Any help is appreciated.

iOS icon glitch when minimizing app

Describe the bug
Once the app icon has been changed, it seems to refresh itself each time the app is sent to the background.

To Reproduce
Steps to reproduce the behavior:

  1. Open app on iOS (once app icon has been changed)
  2. Send app to background to display home screen
  3. Home screen briefly displays the default iOS icon before showing the new icon (see attached screen recording)

Expected behavior
The new icon should be displayed

Screenshots
https://user-images.githubusercontent.com/3749268/215489214-79eb0e60-3b55-4bab-a68d-36f4d9ceb869.mov

Smartphone (please complete the following information):

  • Device: iPhone 12
  • OS: iOS
  • Version: 16.3

Additional context
Add any other context about the problem here.

Capacitor 5

Capacitor 5 released, can this plugin be updated? Thanks in advance!

Capacitor Web Plugin Deprecated

Describe the bug
When running locally the plugin throws an error about deprecated for Web Plugin function.

Expected behavior
Plugin won't work in browser which is understandable, however, no error should be thrown by the plugin regarding deprecated function use.

Screenshots
Screen Shot 2021-06-29 at 5 17 54 pm

Additional context
Using latest plugin version 2.0.1
Angular 12.0.5
Ionic 5.33.1

Capacitor 3 Support

Is your feature request related to a problem? Please describe.

The Capacitor 3 RC is out! ๐ŸŽ‰ This library should support the new version

Describe the solution you'd like

Follow the plugin upgrade guide here: https://capacitorjs.com/docs/v3/updating/plugins/3-0

Additional context

The migration is pretty easy, I've done it for a couple plugins. Happy to assist if you need assisting!

I see you already have a v3 branch. Do you have plans on merging that into main or are you waiting on the full release?

Support for system wide icons

This plugin is currently not following Apple's Alternate App Icon guidelines.

Add support for changing the app icon system wide.

4.6 Alternate App Icons
Apps may display customized icons, for example, to reflect a sports team preference, provided that each change is initiated by the user and the app includes settings to revert to the original icon. All icon variants must relate to the content of the app and changes should be consistent across all system assets, so that the icons displayed in Settings, Notifications, etc. match the new springboard icon. This feature may not be used for dynamic, automatic, or serial changes, such as to reflect up-to-date weather information, calendar notifications, etc.

Capacitor 4 Support

Hi, Capacitor 4 is the latest official version now.
I'm not sure if any changes in the codebase are required or not.

When installing through npm, I get the following error

Could not resolve dependency:
npm ERR! peer  @capacitor/core@"^3.0.1" from @capacitor-community/[email protected]

Thanks

Android Change Icon Bugs

When I change the app icon on my code, the app closed show App Keeps Stopping message, but after closing app icon changes.

Screenshot 2023-12-18 141718

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.