Android系統 小米/三星/索尼快鍵表徵圖BadgeNumber數字提醒

來源:互聯網
上載者:User

標籤: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數字提醒

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.