亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

揭秘雙十一手機(jī)淘寶圖標(biāo)如何被動(dòng)態(tài)更換

 更新時(shí)間:2021年08月24日 11:43:50   作者:pangjl1982  
這篇文章主要介紹了每到雙十一十二的時(shí)候Android手機(jī)動(dòng)態(tài)更換手機(jī)圖標(biāo)的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1、Android如何動(dòng)態(tài)更換桌面圖標(biāo)

1.1使用場景

      APP,在中國電商行業(yè)中,某寶和某東是行業(yè)的標(biāo)桿。其中有一點(diǎn)挺讓人好奇的,那就是在雙十一臨近之時(shí),他們的APP桌面圖標(biāo)突然變成了帶有雙十一字樣的圖標(biāo)??赡芫褪潜緛砭蛢?nèi)置了雙十一的圖標(biāo),等快到雙十一的時(shí)候在動(dòng)態(tài)更換,然后過了雙十一那段時(shí)間,又將APP的桌面圖標(biāo)變成普通的icon。

1.2知識(shí)點(diǎn)

      動(dòng)態(tài)更換APP 桌面icon的引述;
      activity組件及定義“同盟”組件activity-alias;
      PackageManager類進(jìn)行啟用/禁用組件;
      PackageInfo的簡介;
      新名詞記錄{PackageInfo:Androidmanifest.xml文件描述類}

1.3使用Activity-alias

<activity
    android:name="com.aliasicon.MainActivity"
    android:enabled="false"
    android:exported="true"
    >
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>


<activity-alias
    android:name="com.zztzt.android.simple.activity.tztCommHeadPageGenearlActivity"
    android:configChanges="orientation|keyboardHidden|fontScale|screenSize"
    android:enabled="true"
    android:exported="true"
    android:icon="@drawable/tzt_icon"
    android:label="@string/app_general_name"
    android:screenOrientation="portrait"
    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:name="com.zztzt.android.simple.activity.tztCommHeadPageLicaiActivity"
    android:configChanges="orientation|keyboardHidden|fontScale|screenSize"
    android:enabled="false"
    android:exported="true"
    android:icon="@drawable/tzt_icon_licai"
    android:label="@string/app_licai_name"
    android:screenOrientation="portrait"
    android:targetActivity=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity-alias>
String systemPath = "com.aliasicon.MainActivity";
String springPath = "com.zztzt.android.simple.activity.tztCommHeadPageAliasActivity";
String licaiPath = "com.zztzt.android.simple.activity.tztCommHeadPageLicaiActivity";
String genearlPath = "com.zztzt.android.simple.activity.tztCommHeadPageGenearlActivity";
String finalPath = "";
ComponentName genearlComponent;
ComponentName licaiComponent;
ComponentName springComponent;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    genearlComponent = new ComponentName(getApplication(), genearlPath);
    licaiComponent = new ComponentName(getApplication(), licaiPath);
    springComponent = new ComponentName(getApplication(), springPath);

	//第一個(gè)默認(rèn)按鈕
    Button btnDefault = (Button) findViewById(R.id.tztToDefault);
    btnDefault.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            disableComponent(MainActivity.this, licaiComponent);
            disableComponent(MainActivity.this, springComponent);
            enableComponent(MainActivity.this, genearlComponent);
        }
    });
    //理財(cái)按鈕
    Button btnLiCai = (Button) findViewById(R.id.tztToLiCai);
    btnLiCai.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            disableComponent(MainActivity.this, genearlComponent);
            disableComponent(MainActivity.this, springComponent);
            enableComponent(MainActivity.this, licaiComponent);
        }
    });
    //春節(jié)按鈕
    Button btnSpring = (Button) findViewById(R.id.tztToSpring);
    btnSpring.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            disableComponent(MainActivity.this, genearlComponent);
            disableComponent(MainActivity.this, licaiComponent);
            enableComponent(MainActivity.this, springComponent);
        }
    });
}

/**
 * 啟用組件 * 
 * @param componentName
 * 重要方法
 */
private void enableComponent(Activity activity, ComponentName componentName) {
    PackageManager pm = activity.getPackageManager();
    int state = pm.getComponentEnabledSetting(componentName);
    if (PackageManager.COMPONENT_ENABLED_STATE_ENABLED == state) {
        //已經(jīng)啟用
        return;
    }
    pm.setComponentEnabledSetting(componentName,
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
}

/**
 * 禁用組件 * 
 * @param componentName
 * 重要方法
 */
private void disableComponent(Activity activity, ComponentName componentName) {
    PackageManager pm = activity.getPackageManager();
    int state = pm.getComponentEnabledSetting(componentName);
    if (PackageManager.COMPONENT_ENABLED_STATE_DISABLED == state) {
        //已經(jīng)禁用
        return;
    }
    pm.setComponentEnabledSetting(componentName,
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
            PackageManager.DONT_KILL_APP);
}

public void saveData(String savePath) {
    SharedPreferences sp = getSharedPreferences("Icon", Context.MODE_PRIVATE);
    //獲取到edit對象
    SharedPreferences.Editor edit = sp.edit();
    //通過editor對象寫入數(shù)據(jù)
    edit.putString("Value", savePath);
    //提交數(shù)據(jù)存入到xml文件中
    edit.commit();
}

public String getData() {
    SharedPreferences sp = getSharedPreferences("Icon", Context.MODE_PRIVATE);
    return sp.getString("Value", "");
}

2、巨坑

      通過上面的程序能夠?qū)崿F(xiàn)卻換圖標(biāo);如果代碼里通過節(jié)假日的時(shí)間進(jìn)行控制,則客戶打開app會(huì)自動(dòng)的切換圖標(biāo);

      是不是很神奇?先別高興太早。

2.1App的覆蓋

      任何App都會(huì)更新,進(jìn)行覆蓋安裝。覆蓋安裝的Manifest的配置不當(dāng)導(dǎo)致出現(xiàn)難以挽回的問題。

      1、從上面的xml里配置可見,一個(gè)Activity和兩個(gè)Activity-alisa的配置情況:

            Activity的android:enabled="false"
            第一個(gè)Activity-alias的android:enabled="true"
            第二個(gè)Activity-alias的android:enabled="false"

            所以App打開,桌面上默認(rèn)的就是使用第一個(gè)Activity-alias的名字和圖標(biāo)。

      2、如果新版本的配置還是按照這個(gè)配置(即使添加了新的alias,只要默認(rèn)的Activity-alias不發(fā)生變化)客戶端額升級覆蓋安裝,是不會(huì)出現(xiàn)錯(cuò)誤的。

      3、我們稱之為“方案一”

2.2桌面上出現(xiàn)兩個(gè)圖標(biāo)的問題

      1、如果新版本把Activity的enable設(shè)置為true(方案二),則桌面上除了原來的Activity-alias圖標(biāo)之外,還擁有了該Activity的圖標(biāo),即有了兩個(gè)圖標(biāo);

      Activity的android:enabled="true"
      第一個(gè)Activity-alias的android:enabled="false"
      第二個(gè)Activity-alias的android:enabled="false"

      3、如果試圖使用使用上面的代碼里的disableComponent方法或者android:enabled="false"隱藏顯示的Activity-alias圖標(biāo),則導(dǎo)致兩個(gè)圖標(biāo)都消失;

2.3桌面上圖標(biāo)消失的問題

      1、方案二會(huì)出現(xiàn)兩個(gè)圖標(biāo),如果再使用方案一進(jìn)行覆蓋,則兩個(gè)圖標(biāo)都消失。

      2、如果再次使用方案二進(jìn)行覆蓋,則圖標(biāo)還是能重新顯示出來的。

2.4總結(jié)

      1、如果使用方案一進(jìn)行覆蓋安裝,不管圖標(biāo)怎么動(dòng)態(tài)的變換,再使用方案一進(jìn)行覆蓋安裝,是正常的;

      2、如果使用方案二進(jìn)行覆蓋安裝,不管配置的圖標(biāo)是什么樣的,再使用方案二進(jìn)行覆蓋安裝,也是正常的;

      3、如果使用方案一進(jìn)行覆蓋安裝,如果圖標(biāo)沒有動(dòng)態(tài)切換的情況下,再使用方案二進(jìn)行覆蓋安裝,也是正常的;

      4、如果使用方案一進(jìn)行覆蓋安裝,如果圖標(biāo)已經(jīng)經(jīng)過動(dòng)態(tài)切換的情況下,再使用方案二進(jìn)行覆蓋安裝,會(huì)出現(xiàn)雙圖標(biāo)的;

      5、如果使用方案一進(jìn)行覆蓋安裝,如果圖標(biāo)已經(jīng)經(jīng)過動(dòng)態(tài)切換的情況下,再使用方案二進(jìn)行覆蓋安裝,會(huì)出現(xiàn)雙圖標(biāo)的;如果在進(jìn)行使用代碼試圖隱藏其中一個(gè),則兩個(gè)圖標(biāo)都消失;

      6、如果使用方案一進(jìn)行覆蓋安裝,如果圖標(biāo)沒有動(dòng)態(tài)切換的情況下,再使用方案二進(jìn)行覆蓋安裝,也是正常的,再使用方案一進(jìn)行覆蓋安裝,也是正常的;

2.5最終方案(方案一)

      采用方案一的方案,即通過代碼動(dòng)態(tài)變動(dòng)圖標(biāo),一定要注意以下事項(xiàng):

      1、Activity的android:enabled="false"

            如果設(shè)置為true了,則會(huì)出現(xiàn)雙圖標(biāo);

      2、Activity-alias的android:enabled="true"的默認(rèn)顯示的項(xiàng)不要中途進(jìn)行變動(dòng),如果確實(shí)需要使用新的默認(rèn)值,則使用代碼進(jìn)行動(dòng)態(tài)變換;

      3、Activity-alias的android:enabled="true"的不要設(shè)置為多個(gè),否則會(huì)出現(xiàn)多個(gè)圖標(biāo),如果試圖通過代碼進(jìn)行隱藏其中的一個(gè)或者幾個(gè),可能會(huì)出現(xiàn)圖標(biāo)消失的情況。

到此這篇關(guān)于揭秘雙十一手機(jī)淘寶圖標(biāo)如何被動(dòng)態(tài)更換的文章就介紹到這了,更多相關(guān)動(dòng)態(tài)更換手機(jī)圖標(biāo)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android中ScrollView監(jiān)聽滑動(dòng)距離案例講解

    Android中ScrollView監(jiān)聽滑動(dòng)距離案例講解

    這篇文章主要介紹了Android中ScrollView監(jiān)聽滑動(dòng)距離案例講解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • Android?側(cè)滑按鈕的實(shí)現(xiàn)代碼

    Android?側(cè)滑按鈕的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Android?側(cè)滑按鈕的實(shí)現(xiàn),本文結(jié)合示例代碼圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • Android Activity狀態(tài)與操作探究

    Android Activity狀態(tài)與操作探究

    Activity作為Android四大組件之一,他的啟動(dòng)絕對沒有那么簡單。這里涉及到了系統(tǒng)服務(wù)進(jìn)程,啟動(dòng)過程細(xì)節(jié)很多,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值
    2022-12-12
  • android 日志文件LogUtils實(shí)例

    android 日志文件LogUtils實(shí)例

    這篇文章主要介紹了android 日志文件LogUtils實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • Android編程實(shí)現(xiàn)TCP、UDP客戶端通信功能示例

    Android編程實(shí)現(xiàn)TCP、UDP客戶端通信功能示例

    這篇文章主要介紹了Android編程實(shí)現(xiàn)TCP、UDP客戶端通信功能,結(jié)合實(shí)例形式分析了Android實(shí)現(xiàn)TCP與UDP通訊功能的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下
    2016-10-10
  • Kotlin中的對象表達(dá)式和對象聲明的具體使用

    Kotlin中的對象表達(dá)式和對象聲明的具體使用

    這篇文章主要介紹了Kotlin中的對象表達(dá)式和對象聲明的具體使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • Android實(shí)現(xiàn)一對一藍(lán)牙聊天APP

    Android實(shí)現(xiàn)一對一藍(lán)牙聊天APP

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)一對一藍(lán)牙聊天APP,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Android編程實(shí)現(xiàn)ImageView圖片拋物線動(dòng)畫效果的方法

    Android編程實(shí)現(xiàn)ImageView圖片拋物線動(dòng)畫效果的方法

    這篇文章主要介紹了Android編程實(shí)現(xiàn)ImageView圖片拋物線動(dòng)畫效果的方法,實(shí)例分析了Android實(shí)現(xiàn)拋物線運(yùn)動(dòng)的算法原理與相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • 丟失Android系統(tǒng)庫或者Conversion to Dalvik format failed with error 1錯(cuò)誤的解決方法

    丟失Android系統(tǒng)庫或者Conversion to Dalvik format failed with error

    這篇文章主要介紹了丟失Android系統(tǒng)庫或者Conversion to Dalvik format failed with error 1錯(cuò)誤的解決方法,分析了Android系統(tǒng)庫丟失及版本問題的處理技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-12-12
  • Android學(xué)習(xí)筆記--通過Application傳遞數(shù)據(jù)代碼示例

    Android學(xué)習(xí)筆記--通過Application傳遞數(shù)據(jù)代碼示例

    使用Application傳遞數(shù)據(jù)步驟如下:創(chuàng)建新class,取名MyApp,繼承android.app.Application父類,并在MyApp中定義需要保存的屬性
    2013-06-06

最新評論