import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void click(View v){
//1.获取到手机系统里面的通知管理器
NotificationManager nm = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
//2.实例化Notification,表示通知的内容
Notification notification = new Notification
(R.drawable.ic_launcher,"我是一个Notification",
System.currentTimeMillis());
//点击之后自动取消
notification.flags = Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:110"));
PendingIntent contentIntent = PendingIntent.getActivity
(this, 0, intent, 0);
notification.setLatestEventInfo(this, "我是Notification的标题",
"我是Notification的内容", contentIntent);
// Notification.Builder builder = new Notification.Builder(this);
//
// builder.setContentTitle("我是Notification的标题 " )
// .setContentText("我是Notification的内容")
// .setSmallIcon(R.drawable.ic_launcher)
// .setLargeIcon(BitmapFactory.decodeResource(getResources(),
// R.drawable.ic_launcher));
// Notification notification = builder.build();
//
nm.notify(0,notification);
}
}
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void click(View v){
//1.获取到手机系统里面的通知管理器
NotificationManager nm = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
//2.实例化Notification,表示通知的内容
Notification notification = new Notification
(R.drawable.ic_launcher,"我是一个Notification",
System.currentTimeMillis());
//点击之后自动取消
notification.flags = Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:110"));
PendingIntent contentIntent = PendingIntent.getActivity
(this, 0, intent, 0);
notification.setLatestEventInfo(this, "我是Notification的标题",
"我是Notification的内容", contentIntent);
// Notification.Builder builder = new Notification.Builder(this);
//
// builder.setContentTitle("我是Notification的标题 " )
// .setContentText("我是Notification的内容")
// .setSmallIcon(R.drawable.ic_launcher)
// .setLargeIcon(BitmapFactory.decodeResource(getResources(),
// R.drawable.ic_launcher));
// Notification notification = builder.build();
//
nm.notify(0,notification);
}
}