读书人

小弟我的一些代码

发布时间: 2012-08-02 11:35:26 作者: rapoo

我的一些代码
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;

}

读书人网 >移动开发

热点推荐