앱 실행기 아이콘에서 알림 수를 표시하는 방법
삼성 갤럭시 노트 2 안드로이드 버전 4.1.2
이 질문은 전에 질문한 것이고 답변이 불가능한 것으로 알고 있습니다.
Android에서 응용 프로그램 실행기 아이콘 위에 풍선 카운터를 표시하는 방법
그럼에도 불구하고 어제 페이스북 앱을 업데이트했더니 읽지 않은 메시지의 카운터가 개인 메시지로 표시되기 시작했습니다.왜 페이스북 앱은 할 수 있고 내 앱은 할 수 없습니까?
삼성 갤럭시 노트 2 안드로이드 버전 4.1.2
Android("vanilla" Android는 사용자 지정 런처 및 터치 인터페이스가 없는 안드로이드)는 응용 프로그램 아이콘의 변경을 허용하지 않습니다. 이는 응용 프로그램 아이콘이 에 봉인되어 있기 때문입니다..apk
프로그램이 컴파일되면 엄격하게.표준 API를 사용하여 프로그래밍 방식으로 '드로잉 가능'으로 변경할 수는 없습니다.아이콘 대신 위젯을 사용하여 목표를 달성할 수 있습니다.위젯은 사용자 지정할 수 있습니다.http://www.cnet.com/8301-19736_1-10278814-251.html 과 http://developer.android.com/guide/topics/appwidgets/index.html 을 읽어보시기 바랍니다.또한 여기를 보십시오. https://github.com/jgilfelt/android-viewbadger .도움이 될 수 있습니다.
배지 번호에 대해서는.제가 전에 말했듯이 - 이것을 하기 위한 표준적인 방법은 없습니다.하지만 Android는 개방형 운영 체제이며 원하는 모든 것을 할 수 있기 때문에 배지 번호를 추가할 수 있는 유일한 방법은 타사 앱이나 맞춤형 런처를 사용하거나 프런트 엔드 터치 인터페이스인 Samsung TouchWiz 또는 Sony Xperia의 인터페이스를 사용하는 것입니다.다른 답변에서는 이 기능을 사용하며 스택 오버플로에서 이 기능을 검색할 수 있습니다(예: 여기).하지만 다시 한 번 말씀드리지만, 이것에 대한 표준 API는 없으며 저는 이것이 나쁜 관행이라고 말하고 싶습니다.앱의 아이콘 알림 배지는 iOS 패턴이므로 안드로이드 앱에서 사용하면 안 됩니다.Andrioid에는 다음과 같은 목적을 위한 상태 표시줄 알림이 있습니다. http://developer.android.com/guide/topics/ui/notifiers/notifications.html 따라서 Facebook이나 다른 사람이 이것을 사용한다면, 이것은 우리가 고려해야 할 일반적인 패턴이나 추세가 아닙니다.하지만 굳이 홈 스크린 위젯을 사용하고 싶지 않다면 여기를 보십시오.
페이스북은 안드로이드에서 앱 아이콘에 배지 번호를 어떻게 추가합니까?
보시다시피 이것은 실제 페이스북 앱이 아닙니다. 바로 터치위즈입니다.바닐라 안드로이드에서는 Nova Launcher http://forums.androidcentral.com/android-applications/199709-how-guide-global-badge-notifications.html 에서 이를 달성할 수 있습니다. 따라서 어딘가에 아이콘 배지가 표시되면 타사 런처 또는 터치 인터페이스(프론트 엔드 래퍼)인지 확인하십시오.Google은 표준 Android API에 이 기능을 추가할 것입니다.
삼성 터치위즈 런처에서 작동합니다.
public static void setBadge(Context context, int count) {
String launcherClassName = getLauncherClassName(context);
if (launcherClassName == null) {
return;
}
Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
intent.putExtra("badge_count", count);
intent.putExtra("badge_count_package_name", context.getPackageName());
intent.putExtra("badge_count_class_name", launcherClassName);
context.sendBroadcast(intent);
}
public static String getLauncherClassName(Context context) {
PackageManager pm = context.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resolveInfos) {
String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
if (pkgName.equalsIgnoreCase(context.getPackageName())) {
String className = resolveInfo.activityInfo.name;
return className;
}
}
return null;
}
ShortcutBadger는 장치 브랜드와 현재 런처 위에 추상화 계층을 추가하는 라이브러리로, 훌륭한 결과를 제공합니다.LG, 소니, 삼성, HTC 및 기타 맞춤형 런처와 함께 작동합니다.
Pure Android 장치 데스크톱에 배지 수를 표시하는 방법도 있습니다.
애플리케이션 아이콘의 배지 수를 업데이트하는 것은 다음을 호출하는 것만큼 쉽습니다.
int badgeCount = 1;
ShortcutBadger.applyCount(context, badgeCount);
동작을 테스트할 수 있는 데모 응용 프로그램이 포함되어 있습니다.
저는 이것이 소니 기기에 어떻게 적용되는지 알아냈습니다.
저는 여기에 그것에 대해 블로그에 올렸습니다.저는 이에 대한 별도의 SO 질문을 여기에 올렸습니다.
는 Sony 치는이지클사래용다니합를스정된라는 클래스를 합니다.BadgeReciever
.
을 합니다.
com.sonyericsson.home.permission.BROADCAST_BADGE
파일의 : 매페스파의권한:브로드캐스트 an
Intent
에▁BadgeReceiver
:Intent intent = new Intent(); intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE"); intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", "com.yourdomain.yourapp.MainActivity"); intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true); intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", "99"); intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", "com.yourdomain.yourapp"); sendBroadcast(intent);
이 . 이번에 한번.
Intent
프로그램 아이콘에 배지가 표시되어야 합니다.배지를 다시 제거하려면 새 브로드캐스트를 보내십시오. 이번에는
SHOW_MESSAGE
falsefalse로 :intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", false);
답을 짧게 하기 위해 어떻게 이것을 찾았는지에 대한 자세한 내용은 제외했지만, 모두 블로그에서 확인할 수 있습니다.누군가에게는 흥미로운 읽을거리가 될 수도 있습니다.
이것은 알림 시작 아이콘에 배지를 표시하는 샘플이자 가장 좋은 방법입니다.
응용프로그램에 이 클래스 추가
public class BadgeUtils {
public static void setBadge(Context context, int count) {
setBadgeSamsung(context, count);
setBadgeSony(context, count);
}
public static void clearBadge(Context context) {
setBadgeSamsung(context, 0);
clearBadgeSony(context);
}
private static void setBadgeSamsung(Context context, int count) {
String launcherClassName = getLauncherClassName(context);
if (launcherClassName == null) {
return;
}
Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
intent.putExtra("badge_count", count);
intent.putExtra("badge_count_package_name", context.getPackageName());
intent.putExtra("badge_count_class_name", launcherClassName);
context.sendBroadcast(intent);
}
private static void setBadgeSony(Context context, int count) {
String launcherClassName = getLauncherClassName(context);
if (launcherClassName == null) {
return;
}
Intent intent = new Intent();
intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", launcherClassName);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", String.valueOf(count));
intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", context.getPackageName());
context.sendBroadcast(intent);
}
private static void clearBadgeSony(Context context) {
String launcherClassName = getLauncherClassName(context);
if (launcherClassName == null) {
return;
}
Intent intent = new Intent();
intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", launcherClassName);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", false);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", String.valueOf(0));
intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", context.getPackageName());
context.sendBroadcast(intent);
}
private static String getLauncherClassName(Context context) {
PackageManager pm = context.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resolveInfos) {
String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
if (pkgName.equalsIgnoreCase(context.getPackageName())) {
String className = resolveInfo.activityInfo.name;
return className;
}
}
return null;
}
}
==> MyGcmListenerService.java 알림이 오면 BadgeUtils 클래스를 사용합니다.
public class MyGcmListenerService extends GcmListenerService {
private static final String TAG = "MyGcmListenerService";
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("Msg");
String Type = data.getString("Type");
Intent intent = new Intent(this, SplashActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.BigTextStyle bigTextStyle= new NotificationCompat.BigTextStyle();
bigTextStyle .setBigContentTitle(getString(R.string.app_name))
.bigText(message);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(getNotificationIcon())
.setContentTitle(getString(R.string.app_name))
.setContentText(message)
.setStyle(bigTextStyle)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
int color = getResources().getColor(R.color.appColor);
notificationBuilder.setColor(color);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int unOpenCount=AppUtill.getPreferenceInt("NOTICOUNT",this);
unOpenCount=unOpenCount+1;
AppUtill.savePreferenceLong("NOTICOUNT",unOpenCount,this);
notificationManager.notify(unOpenCount /* ID of notification */, notificationBuilder.build());
// This is for bladge on home icon
BadgeUtils.setBadge(MyGcmListenerService.this,(int)unOpenCount);
}
private int getNotificationIcon() {
boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
return useWhiteIcon ? R.drawable.notification_small_icon : R.drawable.icon_launcher;
}
}
기본 설정 및 배지 수에 대한 알림 지우기
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
AppUtill.savePreferenceLong("NOTICOUNT",0,this);
BadgeUtils.clearBadge(this);
}
}
<uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE" />
언급URL : https://stackoverflow.com/questions/17565307/how-to-display-count-of-notifications-in-app-launcher-icon
'programing' 카테고리의 다른 글
테이블을 가로질러 결합할 때 객체의 인덱스/분해를 최적화하는 방법은 무엇입니까? (0) | 2023.08.15 |
---|---|
Python CSV 오류: 줄에 NULL 바이트가 포함되어 있습니다. (0) | 2023.08.15 |
매개 변수를 사용하여 mySql에서 프로시저 만들기 (0) | 2023.08.15 |
Excel 시트를 열지 않고 계산(openpyxl 또는 xlwt) (0) | 2023.08.15 |
일반 테이블 재쿼리 (0) | 2023.08.15 |