package wanxian.notification;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button mButton01,mButton02,mButton03,mButton04;
private NotificationManager nm;
private Intent mIntent;
private Notification mNotification;
private PendingIntent mPendingIntent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mButton01=(Button) findViewById(R.id.button01);
mButton02=(Button) findViewById(R.id.button02);
mButton03=(Button) findViewById(R.id.button03);
mButton04=(Button) findViewById(R.id.button04);
mIntent = new Intent(MainActivity.this,MyTest.class);
mPendingIntent = PendingIntent.getActivity(MainActivity.this, 0, mIntent, 0);
mNotification = new Notification();
mButton01.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mNotification.icon=R.drawable.ic_launcher;
mNotification.tickerText="Button01通知内容";
mNotification.defaults=Notification.DEFAULT_SOUND;
mNotification.setLatestEventInfo(MainActivity.this, "Button01", "Button01通知", mPendingIntent);
nm.notify(0,mNotification);
}
});
}
}
Notifition与NotifitionManager的使用与学习
最新推荐文章于 2021-05-27 20:09:20 发布