暖冬阳😁 liu331258440
关注数: 11 粉丝数: 18 发帖数: 269 关注贴吧数: 30
求助。Notification问题,程序一运行就崩溃,找不到原因。 package com.LiuPan.liupan_notification; import android.support.v7.app.ActionBarActivity; import android.app.Notification; import android.app.NotificationManager; import android.content.Context; import android.graphics.BitmapFactory; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends ActionBarActivity { private Notification notification; private NotificationManager manager; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notification = new Notification.Builder(this) .setTicker("接收到一个Notification") .setContentTitle("Notification") .setContentText("这是一条Notification") .setAutoCancel(true) .setDefaults(Notification.DEFAULT_SOUND) .setSmallIcon(android.R.drawable.ic_notification_clear_all) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) .setWhen(System.currentTimeMillis()) .build(); button = (Button) findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub manager.notify(1, notification);//发送一条通知 } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
1 下一页