<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-1  評(píng)論-68  文章-98  trackbacks-0

    編寫:徐建祥(netpirate@gmail.com)

    日期:2010/11/22

    網(wǎng)址:http://www.anymobile.org

    QQ的狀態(tài)欄通知機(jī)制:當(dāng)所有QQ的UI Activity切換到后臺(tái)后,添加狀態(tài)通知;切換回來后,刪除該狀態(tài)通知。

    飛信的狀態(tài)欄通知方式:運(yùn)行軟件后,圖標(biāo)一直顯示在狀態(tài)欄的通知欄中;顯示退出軟件則刪除該狀態(tài)通知。

    似乎QQ的更有點(diǎn)技術(shù)含量,多個(gè)程序切換到后臺(tái)的處理而已;以飛信的模式,做個(gè)類似的測(cè)試,案例如下:

    程序路徑:org.anymobile.im

    程序入口:org.anymobile.im.LoginActivity(Action:android.intent.action.MAIN;Category:android.intent.category.LAUNCHER)

    主界面程序:org.anymobile.im.MainActivity

    測(cè)試程序流程:未登錄的情況下,或者第一次運(yùn)行會(huì)打開LoginActivity程序;登陸后,一直停留在主界面MainActivity。

    所以,通過Notification,需可以回到im項(xiàng)目的上一個(gè)界面程序,LoginActivity / MainActivity,這里就要參考Launcher應(yīng)用的相關(guān)實(shí)現(xiàn),Intent的flag設(shè)置。

    測(cè)試代碼,新建一個(gè)android項(xiàng)目,TestNotification,入口程序:TestActivity,代碼如下:

    1. package org.anymobile.test;  
    2. import android.app.Activity;  
    3. import android.content.ComponentName;  
    4. import android.content.Intent;  
    5. import android.graphics.LightingColorFilter;  
    6. import android.os.Bundle;  
    7. import android.view.Menu;  
    8. import android.view.View;  
    9. import android.view.View.OnClickListener;  
    10. import android.widget.Button;  
    11. public class TestActivity extends Activity  
    12. {  
    13.     private static final int ADD_ID = 0;  
    14.     private static final int DEL_ID = 1;  
    15.       
    16.     /** Called when the activity is first created. */  
    17.     @Override  
    18.     public void onCreate(Bundle savedInstanceState)  
    19.     {  
    20.         super.onCreate(savedInstanceState);  
    21.         setContentView(R.layout.main);  
    22.           
    23.         Button button = (Button) this.findViewById(R.id.btn_menu);  
    24.         button.setOnClickListener(new OnClickListener()  
    25.         {  
    26.             public void onClick(View v)  
    27.             {  
    28. //              TestActivity.this.openOptionsMenu();  
    29.                 String packName = "org.anymobile.im";  
    30.                 String className = packName + ".LoginActivity";  
    31.                   
    32.                 Intent intent = new Intent();  
    33.                 ComponentName componentName = new ComponentName(packName, className);  
    34.                 intent.setComponent(componentName);  
    35.                   
    36.                 intent.setAction("android.intent.action.MAIN");  
    37.                 intent.addCategory("android.intent.category.LAUNCHER");  
    38.                 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
    39.                 intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);  
    40.                   
    41.                 TestActivity.this.startActivity(intent);  
    42.             }  
    43.         });  
    44. //        button.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);  
    45.         button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF0xFFAA0000));  
    46.     }  
    47.     @Override  
    48.     public boolean onCreateOptionsMenu(Menu menu)  
    49.     {  
    50.         menu.add(0, ADD_ID, 0"ADD");  
    51.         menu.add(0, DEL_ID, 0"DEL");  
    52.           
    53.         return super.onCreateOptionsMenu(menu);  
    54.     }  
    55.       
    56. }  
     

     

    OK,開始測(cè)試狀態(tài)欄的通知功能:

    1、LoginActivity.onCreate() 調(diào)用showNotification()方法,創(chuàng)建一個(gè)通知圖標(biāo);

    1. /** 
    2.    * The notification is the icon and associated expanded entry in the 
    3.    * status bar. 
    4.    */  
    5.   protected void showNotification()  
    6.   {  
    7.       CharSequence from = "IM";  
    8.       CharSequence message = "IM start up";  
    9.         
    10. Intent intent = new Intent();  
    11. ComponentName componentName = new ComponentName("com.longcheer.imm",   
    12.     "com.longcheer.imm.activitys.LoginActivity");  
    13. intent.setComponent(componentName);  
    14. intent.setAction("android.intent.action.MAIN");  
    15. intent.addCategory("android.intent.category.LAUNCHER");  
    16. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
    17. intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);  
    18.   
    19.       // The PendingIntent to launch our activity if the user selects this notification  
    20.       PendingIntent contentIntent = PendingIntent.getActivity(this0, intent, 0);  
    21.       // construct the Notification object.  
    22.       Notification notif = new Notification(R.drawable.icon, "IMM Still run background!",  
    23.               System.currentTimeMillis());  
    24.       notif.setLatestEventInfo(this, from, message, contentIntent);  
    25.         
    26.       // look up the notification manager service  
    27.       NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);  
    28.       nm.notify(R.string.app_name, notif);  
    29.   }  
     

     

    2、在LoginActivity / MainAcitivity的退出操作中cancel該通知。

    1. private void doExit()   
    2. {  
    3.     this.finish();  
    4.     NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);  
    5.        nm.cancel(R.string.app_name);  
    6. }  
     

     

    測(cè)試OK!!

    posted on 2010-12-14 23:08 Xu Jianxiang 閱讀(4711) 評(píng)論(0)  編輯  收藏 所屬分類: Android
    主站蜘蛛池模板: 日本无卡码免费一区二区三区| 亚洲一区二区三区AV无码| 亚洲1234区乱码| 91人人区免费区人人| 日韩亚洲人成在线综合日本| 乱爱性全过程免费视频| 国产免费小视频在线观看| 亚洲人成电影网站色www| 国产免费毛不卡片| 亚洲国产成人精品无码一区二区| 久久青草免费91线频观看站街| 国产亚洲成人久久| 一个人免费播放在线视频看片 | 亚洲精品成人片在线观看精品字幕| 日日狠狠久久偷偷色综合免费 | 亚洲人配人种jizz| 国产成人精品免费视频大全麻豆| 99re在线视频免费观看| 国产AV无码专区亚洲AWWW| 一区视频免费观看| 亚洲精品成人在线| 一区二区三区免费视频播放器| 亚洲av日韩片在线观看| 一个人看的www在线免费视频| 久久国产成人亚洲精品影院| 亚洲第一视频在线观看免费| 国产成人精品日本亚洲专区| 一区二区三区免费电影| 久久久久国产亚洲AV麻豆| 日批视频网址免费观看| 亚洲av无码乱码国产精品fc2| 少妇性饥渴无码A区免费 | 亚洲男人的天堂一区二区| 午夜免费国产体验区免费的| 亚洲国产一成久久精品国产成人综合| 美女被羞羞网站免费下载| 亚洲精品天堂成人片?V在线播放 | 国产在线jyzzjyzz免费麻豆| 亚洲男女性高爱潮网站| 免费99精品国产自在现线| 亚洲人成色777777老人头|