兔子--The method setLatestEventInfo(Context, CharSequence, CharSequence, PendingIntent) from the type

本文主要是介绍兔子--The method setLatestEventInfo(Context, CharSequence, CharSequence, PendingIntent) from the type,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

   notification.setLatestEventInfo(context, title, message, pendingIntent);     不建议使用




低于API Level 11版本,也就是Android 2.3.3以下的系统中,setLatestEventInfo()函数是唯一的实现方法。 

Intent  intent = new Intent(this,MainActivity);  
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);  
notification.setLatestEventInfo(context, title, message, pendingIntent);          
manager.notify(id, notification);  

    高于API Level 11,低于API Level 16 (Android 4.1.2)版本的系统中,可使用Notification.Builder来构造函数。但要使用getNotification()来使notification实现。前面版本在notification中设置的Flags,icon等属性都已经无效,要在builder里面设置。
Notification.Builder builder = new Notification.Builder(context)  
            .setAutoCancel(true)  
            .setContentTitle("title")  
            .setContentText("describe")  
            .setContentIntent(pendingIntent)  
            .setSmallIcon(R.drawable.ic_launcher)  
            .setWhen(System.currentTimeMillis())  
            .setOngoing(true);  
notification=builder.getNotification();  

    高于API Level 16的版本,就可以用Builder和build()函数来配套的方便使用notification了。
Notification notification = new Notification.Builder(context)    
         .setAutoCancel(true)    
         .setContentTitle("title")    
         .setContentText("describe")    
         .setContentIntent(pendingIntent)    
         .setSmallIcon(R.drawable.ic_launcher)    
         .setWhen(System.currentTimeMillis())    
         .build();   
我的实例:
package com.example.mynotification;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.os.Bundle;import android.text.NoCopySpan.Concrete;
import android.view.View;import android.widget.Button;import android.widget.TextView;public class MainActivity extends Activity {Button m_Button1;TextView m_txtView;NotificationManager mNotificationManager;Notification mNotification;Intent mIntent;PendingIntent mPendingIntent;Context context;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);context = this;final Notification notification;mNotificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);m_Button1 = (Button) this.findViewById(R.id.button1);// 点击通知时转移内容mIntent = new Intent(MainActivity.this, MainActivity1.class);mPendingIntent = PendingIntent.getActivity(MainActivity.this, 0,mIntent, 0);notification = new Notification.Builder(context).setAutoCancel(true).setContentTitle("qq正在运行").setContentText("qq,让交流更多方便").setContentIntent(mPendingIntent).setSmallIcon(R.drawable.ic_launcher).setWhen(System.currentTimeMillis()).build();m_Button1.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {mNotificationManager.notify(0, notification);}});}
}



这篇关于兔子--The method setLatestEventInfo(Context, CharSequence, CharSequence, PendingIntent) from the type的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1144815

相关文章

模版方法模式template method

学习笔记,原文链接 https://refactoringguru.cn/design-patterns/template-method 超类中定义了一个算法的框架, 允许子类在不修改结构的情况下重写算法的特定步骤。 上层接口有默认实现的方法和子类需要自己实现的方法

Oracle type (自定义类型的使用)

oracle - type   type定义: oracle中自定义数据类型 oracle中有基本的数据类型,如number,varchar2,date,numeric,float....但有时候我们需要特殊的格式, 如将name定义为(firstname,lastname)的形式,我们想把这个作为一个表的一列看待,这时候就要我们自己定义一个数据类型 格式 :create or repla

Caused by: org.hibernate.MappingException: Could not determine type for: org.cgh.ssh.pojo.GoodsType,

MappingException:这个主要是类映射上的异常,Could not determine type for: org.cgh.ssh.pojo.GoodsType,这句话表示GoodsType这个类没有被映射到

context:component-scan使用说明!

<!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 --> <context:component-scan base-package="com.yuanls"/> 在xml配置了这个标签后,spring可以自动去扫描base-pack下面或者子包下面的java文件,如果扫描到有@Component @Controll

React的context学习总结

context是干什么的?为什么会存在这么一个东西? context字面意思是上下文,在react中存在是为了解决深层次组件传值困难的问题 这里涉及到组件的传值问题,大体商说分三总:兄弟间传值(通过父组件),父往子传值(通过props),子往父传(props函数回调),这是基础的传值问题,但是如果组件嵌套的太深,那么传值就变的非常麻烦,为了解决这样的问题才产生了context  这是cont

兔子--Notification的使用

<span style="font-size:18px;color:#ff0000;"></span> <span style="font-size:18px;color:#ff0000;">使用步骤:</span><p><span style="font-size:18px;color:#ff0000;">1 获取通知管理器NotificationManager,它也是一个系统服务</sp

兔子--PendingIntent与Intent的区别

pendingIntent是一种特殊的Intent。 主要的区别在于Intent的执行立刻的,而pendingIntent的执行不是立刻的。 pendingIntent执行的操作实质上是参数传进来的Intent的操作, 但是使用pendingIntent的目的在于它所包含的Intent的操作的执行是需要满足某些条件的。 主要的使用的地方和例子:通知Notificatio

兔子--背景透明度设置

背景透明度设置:ee是透明度 android:background="#ee6c6c6c"

兔子--Android Support v4,Android Support v7,Android Support v13

Android Support Library package用于高版本的特性的向下兼容。 (fragement,ViewPager) Android Support v4:  这个包是为了照顾1.6及更高版本而设计的,这个包是使用最广泛的,eclipse新建工程时,都默认 带有了。 Android Support v7:  这个包是为了考虑照顾2.1及以上版本而设计的,

兔子--Android Support v4包丢失的解决办法

在开发中,Android Support v4包丢失的解决办法: Project->properties->Java Build Path->Libraries->Add External Jars 中加入sdk目录下的extras/android/support/v4/android-support-v4.jar (如果找不到,则需要用sdk manager下载andro