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

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

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

    隨筆-1  評論-68  文章-98  trackbacks-0

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

    日期:2010/11/22

    網址:http://www.anymobile.org

    QQ的狀態欄通知機制:當所有QQ的UI Activity切換到后臺后,添加狀態通知;切換回來后,刪除該狀態通知。

    飛信的狀態欄通知方式:運行軟件后,圖標一直顯示在狀態欄的通知欄中;顯示退出軟件則刪除該狀態通知。

    似乎QQ的更有點技術含量,多個程序切換到后臺的處理而已;以飛信的模式,做個類似的測試,案例如下:

    程序路徑:org.anymobile.im

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

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

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

    所以,通過Notification,需可以回到im項目的上一個界面程序,LoginActivity / MainActivity,這里就要參考Launcher應用的相關實現,Intent的flag設置。

    測試代碼,新建一個android項目,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,開始測試狀態欄的通知功能:

    1、LoginActivity.onCreate() 調用showNotification()方法,創建一個通知圖標;

    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. }  
     

     

    測試OK?。?/p>

    posted on 2010-12-14 23:08 Xu Jianxiang 閱讀(4711) 評論(0)  編輯  收藏 所屬分類: Android
    主站蜘蛛池模板: 免费精品久久天干天干| 亚洲国产乱码最新视频| 综合亚洲伊人午夜网| 亚洲第一视频在线观看免费| 国产精品深夜福利免费观看| 美女被免费视频网站a国产 | 亚洲精品第一国产综合亚AV| 亚洲精品伊人久久久久| 免费不卡在线观看AV| 久久久久久久久久国产精品免费| 免费毛片a线观看| 日韩插啊免费视频在线观看| 免费人成在线观看网站品爱网 | 亚洲av最新在线观看网址| 亚洲Av永久无码精品一区二区| 亚洲a∨国产av综合av下载| 国产偷国产偷亚洲高清在线| 特级毛片A级毛片100免费播放| 日韩a毛片免费观看| 搡女人免费免费视频观看| 亚洲国产精品成人AV在线| 国产亚洲人成在线播放| 免费精品国自产拍在线播放| 国产高潮流白浆喷水免费A片 | 最近中文字幕大全免费版在线| 免费无码一区二区三区| 国产h视频在线观看免费| 青青草国产免费久久久91| 亚洲视频在线精品| 亚洲国产女人aaa毛片在线| 亚洲人xxx日本人18| 深夜a级毛片免费视频| 国产午夜免费高清久久影院| 亚洲香蕉免费有线视频| 在线观看亚洲免费视频| 99热免费在线观看| 夭天干天天做天天免费看| 亚洲无码日韩精品第一页| 亚洲最新永久在线观看| 亚洲午夜国产精品无码老牛影视| 亚洲AV本道一区二区三区四区|