android第二十二步发送状态栏通知

Notification状态栏通知设置类

Notification notification = new Notification(icon,strremark,System.currentTimeMillis());图标和时间
notification.setLatestEventInfo(this, strtitlek, strcontent, pendingIntent);上下文、标题、内容、点击后出发的意图过滤器
notification.defaults=Notification.DEFAULT_SOUND;通知声音
notification.flags=Notification.FLAG_AUTO_CANCEL;点击后自动在状态栏消失
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);获取系统的状态类通知
manager.notify(100, notification);id、notification 

本例是点击通知后打一个电话

public class MainActivity extends Activity {

    private EditText remarktext;
    private EditText titletext;
    private EditText contentext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        remarktext = (EditText)this.findViewById(R.id.remark);
        titletext = (EditText)this.findViewById(R.id.title);
        contentext = (EditText)this.findViewById(R.id.content);
    }
    public void send(View v){
        String strremark=remarktext.getText().toString();
        String strtitlek=titletext.getText().toString();
        String strcontent=contentext.getText().toString();
        int icon = android.R.drawable.stat_notify_chat;
        Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:1234"));
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 10, intent, 0);
        Notification notification = new Notification(icon,strremark,System.currentTimeMillis());
        notification.setLatestEventInfo(this, strtitlek, strcontent, pendingIntent);
        notification.defaults=Notification.DEFAULT_SOUND;
        notification.flags=Notification.FLAG_AUTO_CANCEL;
        NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(100, 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;
    }

}

 

posted @ 2014-04-16 11:34  东方小花猪  阅读(250)  评论(0编辑  收藏  举报