android 之推送(本地推送远程推送)

在现在的app中推送技术很普遍,推送可以提高用户活跃度,也可以进行一些活动推送,今天就跟大家聊一下推送

推送分为远程推送和本地推送,都可以通过推送消息跳转到一些应用或者活动界面,本地推送几行代码就可以实现,远程推送就需要借助一些平台的力量

(1)本地推送


NotificationManager nm=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        String title = "通知标题" ;

        String content = "通知内容" ;

        //1.实例化一个通知,指定图标、概要、时间

        Notification n=new Notification(R.drawable.ic_launcher,"这是通知,早上好",1000);

        //2.指定通知的标题、内容和intent

        Intent intent = new Intent(this, MainActivity.class);

//设置跳转到的页面 ,时间等内容

        PendingIntent pi= PendingIntent.getActivity(this, 0, intent, 1000);

        n.setLatestEventInfo(this, title, content, pi);
      //3.指定声音
      n.defaults = Notification.DEFAULT_SOUND;
      //4.发送通知
      nm.notify(1, n);

(2)远程推送

远程推送方面我用的是极光推送做的调研,参考的http://blog.csdn.net/heynine/article/details/8140000  这里面就写的很详细









你可能感兴趣的:(android 之推送(本地推送远程推送))