下载管理中Notification的使用
来源:互联网 发布:网络大电影怎么宣传 编辑:程序博客网 时间:2024/06/07 23:31
点击下载按钮,通知用户下载任务已添加到下载列表中
主程序代码:
说明:转载请注明出处!
布局文件如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:background="@drawable/page"android:layout_height="wrap_content" android:orientation="vertical"><Button android:id="@+id/down"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="下载文件"/><Button android:id="@+id/newdown"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="新建下载任务"/></LinearLayout>
主程序代码:
package com.cloay.down.activity;import java.util.HashMap;import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import com.cloay.down.R;import com.cloay.down.service.MainService;import com.cloay.down.utils.Task;/** * 模拟下载网页上的下载按钮 * DownloadActivity.java * @author cloay * 2011-11-18 */public class DownloadActivity extends Activity {private Button download; private Button newdownload;private NotificationManager notificationManager;private PendingIntent pendingIntent; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent = new Intent("com.cloay.down.service.MainService"); this.startService(intent); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent intent1 = new Intent(this, DownLoadManager.class); pendingIntent = PendingIntent.getActivity(this, 0, intent1, PendingIntent.FLAG_ONE_SHOT); download = (Button) findViewById(R.id.down); download.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {startLoadTask("http://taoke.youkk.net/Mine.mp3");}}); newdownload = (Button) findViewById(R.id.newdown); newdownload.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {startLoadTask("http://mp3.jayie.com/38.mp3");}}); } private void startLoadTask(String url) {//使用service后台下载HashMap<String, String> parm = new HashMap<String, String>();parm.put("url", url);Task task = new Task(Task.LOAD_FILE, parm);MainService.newTask(task);Notification notification = new Notification();notification.icon = R.drawable.download_notification;notification.tickerText = "下载任务已添加到下载列表中,点击查看!";notification.defaults = Notification.DEFAULT_SOUND;notification.setLatestEventInfo(DownloadActivity.this, "下载任务已启动", "下载任务已添加到下载列表中!", pendingIntent);notificationManager.notify(0, notification);}}
说明:转载请注明出处!
- 下载管理中Notification的使用
- Notification实现下载提醒和管理 不需要使用downloadProvider
- Android中Notification的使用
- Android中Notification的使用
- Android中Notification的使用
- Android中使用Notification实现应用更新显示下载进度
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- 浅谈ios开发中notification的使用
- Android中通知的使用-----Notification详解
- Android中Notification的使用以及自定义
- Android中通知的使用-----Notification详解
- android中通知栏notification的使用
- Android开发中Notification的使用
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- 在分线程更新主线程的Ui界面方法
- 让C#智能注释时显示更加明晰
- eclipse更新SDK后版本控制的错误
- chrome 浏览器中关于media player11插件的安装
- 30分钟掌握STL [转载]
- 下载管理中Notification的使用
- C#.net视频教程 急求~~
- 游戏数据分析公司Playtomic为开发者推出免费分析工具
- 关于ArcSDE的学习经验总结
- difference between updateDisplaylist() and CommitProperties()
- linux播放音频、视频需要的包
- flex3.0中打包的方法swc
- Hibernate -annotation 学习笔记 1 马士兵
- Spring配置文件总结