標籤:android style http io ar os 使用 sp java
Android系統 小米,三星,索尼手機發送案頭快鍵提醒數字表徵圖,在Android系統中,眾所周知不支援BadgeNumber,雖然第三方控制項BadgeView可以實現應用內的數字提醒,但對於系統的表徵圖,特別是app的logo表徵圖很難實現數字標誌,即使是繪圖的方式不斷修改,但這種方式天生弊端,實用性很差。
我們現在來實現案頭logo或者說icon右上方的表徵圖,先來看2張圖,第一張來自互連網,第二張來自個人實踐!(由於實驗條件youxia)
好了,上代碼
public class MainActivity extends Activity { //必須使用,Activity啟動頁 private final static String lancherActivityClassName = Welcome.class.getName(); @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.common_listview_layout);}@Overrideprotected void onResume() {super.onResume();sendBadgeNumber();}private void sendBadgeNumber() {String number = "35";if (TextUtils.isEmpty(number)) {number = "";} else {int numInt = Integer.valueOf(number);number = String.valueOf(Math.max(0, Math.min(numInt, 99)));}if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")) {sendToXiaoMi(number);} else if (Build.MANUFACTURER.equalsIgnoreCase("samsung")) {sendToSony(number);} else if (Build.MANUFACTURER.toLowerCase().contains("sony")) {sendToSamsumg(number);} else {Toast.makeText(this, "Not Support", Toast.LENGTH_LONG).show();}}private void sendToXiaoMi(String number) {try {Class miuiNotificationClass = Class.forName("android.app.MiuiNotification");Object miuiNotification = miuiNotificationClass.newInstance();Field field = miuiNotification.getClass().getDeclaredField("messageCount");field.setAccessible(true);field.set(miuiNotification, number);// 設定資訊數-->這種發送必須是miui 6才行} catch (Exception e) { e.printStackTrace(); //miui 6之前的版本 Intent localIntent = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE"); localIntent.putExtra("android.intent.extra.update_application_component_name",getPackageName() + "/"+ lancherActivityClassName ); localIntent.putExtra("android.intent.extra.update_application_message_text",number); sendBroadcast(localIntent);}}private void sendToSony(String number) {boolean isShow = true;if ("0".equals(number)) {isShow = false;}Intent localIntent = new Intent();localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE",isShow);//是否顯示localIntent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME",lancherActivityClassName );//啟動頁localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", number);//數字localIntent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME",getPackageName());//包名sendBroadcast(localIntent);Toast.makeText(this, "Sony," + "isSendOk", Toast.LENGTH_LONG).show();}private void sendToSamsumg(String number) {Intent localIntent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");localIntent.putExtra("badge_count", number);//數字localIntent.putExtra("badge_count_package_name", getPackageName());//包名localIntent.putExtra("badge_count_class_name",lancherActivityClassName ); //啟動頁sendBroadcast(localIntent);Toast.makeText(this, "Samsumg," + "isSendOk", Toast.LENGTH_LONG).show();}}
注意lancherActivityClassName 必須被配置為 啟動頁 android.intent.category.LAUNCHER
<activity android:name="com.sample.activites.Welcome" android:configChanges="locale|keyboard|screenSize" android:label="@string/app_name" android:screenOrientation="portrait" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.CREATE_SHORTCUT" /> </intent-filter> </activity>
try doing it
Android系統 小米/三星/索尼快鍵表徵圖BadgeNumber數字提醒