# تغيير أيقونة تطبيق أندرويد

لتغيير أيقونة التطبيق بناءً على عدد الإشعارات في مركز الإشعارات، اتبع الخطوات أدناه.

1. أضف أيقونة جديدة إلى مشروعك في مجلد 'mipmap'.

<img src="/android-notification-customisation-change-android-app-icon-1.webp" alt="لقطة شاشة توضح بنية مجلد mipmap في Android Studio مع إضافة ملف أيقونة جديد"/>

2. أنشئ فئة Activity جديدة.

```java
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivityAlias extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }
}
```

3. **أنشئ فئة تحتوي على منطق تغيير الأيقونة.**

```java
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;

public class MyPushReceiver  {

    public static void changeAppIcon(Context context, int count) {
        PackageManager pm = context.getPackageManager();
        if (count > 0) {
            pm.setComponentEnabledSetting(
                    new ComponentName(context, "com.example.app.MainActivityAlias"),
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                    PackageManager.DONT_KILL_APP
            );
            pm.setComponentEnabledSetting(
                    new ComponentName(context, "com.example.app.MainActivity"),
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP
            );
        } else {
            pm.setComponentEnabledSetting(
                    new ComponentName(context, "com.example.app.MainActivity"),
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                    PackageManager.DONT_KILL_APP
            );
            pm.setComponentEnabledSetting(
                    new ComponentName(context, "com.example.app.MainActivityAlias"),
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP
            );
        }
    }
}
```

4. **في فئة `NotificationServiceExtension` الخاصة بك، قم بتنفيذ تتبع استلام/حذف إشعارات الدفع.**

```java
@Override
public boolean onMessageReceived(final PushMessage message) {
	super.onMessageReceived(message);

	if (!message.isSilent()) {
		/**
		 * في هذا المثال، يتم الإشارة ببساطة إلى عدد عشوائي من الإشعارات.
		 * تحتاج إلى تنفيذ منطق حساب الإشعارات بنفسك.
		 */
		int notificationCount = 1;

		if (getApplicationContext() != null) {
			MyPushReceiver.changeAppIcon(getApplicationContext(), notificationCount);
		}
	}
}

/**
* رد نداء Pushwoosh لتتبع إزالة إشعارات الدفع من مركز الإشعارات.
*/
@Override
protected void onMessageCanceled(PushMessage message) {
	super.onMessageCanceled(message);

	if (!message.isSilent()) {
		/**
		* في هذا المثال، يتم الإشارة ببساطة إلى عدد عشوائي من الإشعارات.
		* تحتاج إلى تنفيذ منطق حساب الإشعارات بنفسك.
		*/
		int notificationCount = 0;

		if (getApplicationContext() != null) {
			MyPushReceiver.changeAppIcon(getApplicationContext(), notificationCount);
		}
	}
}
```

5. **تم!**

### مثال على كيفية ظهوره على الجهاز

<video src="/android-notification-customisation-change-android-app-icon-2.webm" title="عرض متحرك يوضح تغيير أيقونة التطبيق ديناميكيًا عند استلام الإشعارات أو إزالتها" autoplay loop muted playsinline />