首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

小弟我的一些代码

2012-08-02 
我的一些代码public class TestNotifycationActivity extends Activity {private NotificationManager mNo

我的一些代码
public class TestNotifycationActivity extends Activity {
private NotificationManager mNotificationManager;
public static final int NOTIFICATION_ID=11;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        sendNotification(this);
        IntentFilter myfi = new IntentFilter("wangqianwangqian");
        this.registerReceiver(new MyBroad(), myfi);
    }
   
    public  void sendNotification(Context con){
    mNotificationManager = (NotificationManager) con.getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.my, "All Backup",System.currentTimeMillis());
//notification.flags = Notification.FLAG_ONGOING_EVENT;
//notification.defaults =Notification.DEFAULT_SOUND;
//notification.defaults =Notification.DEFAULT_ALL;
notification.flags = Notification.FLAG_AUTO_CANCEL;
Intent intent;
intent= new Intent();
intent.setAction("wangqianwangqian");
//intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(con, 0,intent,PendingIntent.FLAG_CANCEL_CURRENT);
RemoteViews views = new RemoteViews(con.getPackageName(), R.layout.notify);
PendingIntent contentIntent1 = PendingIntent.getBroadcast(con, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
views.setOnClickPendingIntent(R.id.myClear, contentIntent1);
notification.contentView = views;
//notification.contentView = contentView;
//notification.contentIntent = contentIntent;
//notification.setLatestEventInfo(con, "ArchermindMusic", musicName, contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, notification);
    }
   
    public class MyBroad extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {
    if(intent.getAction().equals("wangqianwangqian")){
    mNotificationManager.cancel(NOTIFICATION_ID);
    }
   
    }
    }



public static boolean isNetWork(Context context){
ConnectivityManager manager =(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
if(manager!=null){
NetworkInfo info = manager.getActiveNetworkInfo();
if(info!=null && info.isConnected()){
if(info.getState() == NetworkInfo.State.CONNECTED){
return true;
}
}
}
return false;

}

热点排行