当前位置:操作系统 > 安卓/Android >>

Notification温馨小提示

例如:
Java代码 
@Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
        Button btn = (Button)findViewById(R.id.button1); 
        btn.setOnClickListener(new OnClickListener() { 
            @Override 
            public void onClick(View v) { 
                NotificationManager man = (NotificationManager) 
                    getSystemService(NOTIFICATION_SERVICE); 
                PendingIntent in = PendingIntent.getActivity 
                    (ToastView.this, 0, new Intent 
                            (ToastView.this,ToastView.class), 0); 
                Notification no = new Notification 
(R.drawable.icon,"温馨提示",System.currentTimeMillis()); 
                no.setLatestEventInfo(ToastView.this, "后台菜单标题",  
                        "后台菜单内容", in); 
                no.defaults = Notification.DEFAULT_SOUND; 
                //100ms延迟后,震动250ms,停止100ms后震动500ms 
                no.vibrate = new long[]{100,250,100,500}; 
                man.notify(R.layout.main, no); 
            } 
        }); 

PS:以上代码是一个按钮,点击后将出现温馨小提示,拖拉后台菜单,将显示标题和内容。
Notification.DEFAULT_SOUND是点击提示的时候伴随声音
Notification.DEFAULT_VIBRATE是点击提示的时候伴随震动
Notification.DEFAULT_ALL是点击提示的时候伴随声音和震动
使用震动必须在AndroidMainfest.xml中加入震动权限:
Java代码 
<users-permission  android:name="Android.permission.VIBRATE" /> 

作者“rayln”
 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,