代码:
package com.example.custemviewtry;
import javax.security.auth.PrivateCredentialPermission;
import com.example.custemviewtry.view.GoodGame;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.SimpleAdapter.ViewBinder;
public class MainActivity extends Activity implements OnClickListener
{
private GoodGame goodGame;
private Notification.Builder mBuilder;
private NotificationManager notificationManager;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
goodGame = (GoodGame) findViewById(R.id.goodgame);
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
initNotifcation();
goodGame.setOnClickListener(this);
}
@SuppressLint("NewApi")
private void initNotifcation()
{
mBuilder = new Notification.Builder(this);
mBuilder.setContentTitle("title").setContentText("this is text").setTicker("通知来了")
.setSmallIcon(R.drawable.ic_launcher).setContentInfo("this is info ");
}
@SuppressLint("NewApi")
@Override
public void onClick(View v)
{
notificationManager.notify(10, mBuilder.build());
}
}
总结:
1,NotificationManager
2,Notification.Builder
3,mBuilder.setContent….
4,notificationManager.notify(id,mBuilder.build());
注意:
id是自己用就行了,不需要通告给别人,作用是如果statusBar已经存在相同id的通知,那么当前的就会替换以前的。