zoukankan      html  css  js  c++  java
  • android 发送通知栏消息,点击后打开指定网页

    package com.eboy.testnotification;

    import android.app.Activity;
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.View;

    public class MainActivity extends Activity {
        private static final String edtShortTitle = "edtShortTitle";
        private static final String edtTitle = "edtTitle";
        private static final String edtContent = "http://www.985dy.com";

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
        
        public void sendNotification1(View v){
            int icon = android.R.drawable.stat_notify_error;
            Notification notification = new Notification(icon, edtShortTitle, System.currentTimeMillis());
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(edtContent));
            
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);        
            notification.setLatestEventInfo(this, edtTitle, edtContent, pendingIntent);    
            notification.defaults = Notification.DEFAULT_SOUND;
            notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_AUTO_CANCEL; //不可清除,自动取消 
            NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(100, notification);
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);        
            return true;
        }
    }
  • 相关阅读:
    Google 开源的 Python 命令行库:深入 fire(二)
    开启 Django 博客的 RSS 功能
    MongoDB 分片键的选择与案例
    Log4Net写入到数据库配置过程中的一些小问题备忘
    《WCF服务编程第三版》知识点摘录
    Android调用基于.net的WebService
    心跳包实现的另一种机制
    无法加载一个或多个请求的类型。有关更多信息,请检索 LoaderExceptions 属性。
    解决SaveChanges会Hold住之前的错误的问题
    memcached工作原理与优化建议
  • 原文地址:https://www.cnblogs.com/jxgxy/p/2635508.html
Copyright © 2011-2022 走看看