Notification通知
Notification显示通知内容 package com.example.test; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class MainActivity extends Activity implements OnClickListener { private TextView textView1; private TextView textVie w2; private Button button1; private String title; private String content; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView1 = (TextView) findViewById(R.id.textView1); textView2 = (TextView) findViewById(R.id.textView2); button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(this); } @Override public void onClick(View v) { send(); } private void send() { title = textView1.getText().toString(); content = textView2.getText().toString(); NotificationManager mn = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification n = new Notification(R.drawable.image, "通知", System.currentTimeMillis()); Intent intent = new Intent(this, MainActivity.class); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); n.setLatestEventInfo(this, title, content, pi); n.defaults = Notification.DEFAULT_SOUND; mn.notify(1, n); } } w2; private Button button1; private String title; private String content; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView1 = (TextView) findViewById(R.id.textView1); textView2 = (TextView) findViewById(R.id.textView2); button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(this); } @Override public void onClick(View v) { send(); } private void send() { title = textView1.getText().toString(); content = textView2.getText().toString(); NotificationManager mn = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification n = new Notification(R.drawable.image, "通知", System.currentTimeMillis()); Intent intent = new Intent(this, MainActivity.class); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); n.setLatestEventInfo(this, title, content, pi); n.defaults = Notification.DEFAULT_SOUND; mn.notify(1, n); } }
用户评论
newLXYRa 2018-12-27 07:35:24
有用,不错。。。