android通过URL路径下载安装文件
来源:互联网 发布:软件测试工程师基础 编辑:程序博客网 时间:2024/05/22 15:49
/**
* <p>
* Title: 取得远程文件
* </p>
* <p>
* Description:
* </p>
*
* @paramstrPath
* @throwsException
*/
private void getDataSource(String strPath) throws Exception {
if (!URLUtil.isNetworkUrl(strPath)) {
Log.e(TAG,"错误的URL");
} else {
/* 取得URL */
URL myURL = new URL(strPath);
/* 创建连接 */
URLConnection conn = myURL.openConnection();
conn.connect();
/* InputStream 下载文件 */
InputStream is = conn.getInputStream();
if (is ==null) {
throw new RuntimeException("stream is null");
}
/* 创建临时文件 */
File myTempFile = File.createTempFile(fileNa,"." + fileEx);
/* 将文件写入暂存盘 */
FileOutputStream fos = new FileOutputStream(myTempFile);
byte buf[] =new byte[128];
int numread = is.read(buf);
while(numread > 0)
{
fos.write(buf, 0, numread);
numread = is.read(buf);
}
is.close();
/* 打开文件进行安装 */
openFile(myTempFile);
//安装完毕,删除临时文件
myTempFile.delete();
}
}
/**
* <p>Title: 在手机上打开文件,执行安装</p>
* <p>Description: </p>
* @paramf
*/
private void openFile(File f) {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
/* 调用getMIMEType()来取得MimeType */
String type = getMIMEType(f);
/* 设置intent的file与MimeType */
intent.setDataAndType(Uri.fromFile(f), type);
startActivity(intent);
}
/**
* <p>Title: 判断文件MimeType</p>
* <p>Description: </p>
* @paramf
* @return
*/
private String getMIMEType(File f) {
String type = "";
String fName = f.getName();
/* 取得扩展名 */
String end = fName
.substring(fName.lastIndexOf(".") + 1, fName.length())
.toLowerCase();
/* 依扩展名的类型决定MimeType */
if (end.equals("m4a") || end.equals("mp3") || end.equals("mid")
|| end.equals("xmf") || end.equals("ogg") || end.equals("wav")) {
type = "audio";
} else if (end.equals("3gp") || end.equals("mp4")) {
type = "video";
} else if (end.equals("jpg") || end.equals("gif") || end.equals("png")
|| end.equals("jpeg") || end.equals("bmp")) {
type = "image";
} else if (end.equals("apk")) {
/* android.permission.INSTALL_PACKAGES */
type = "application/vnd.android.package-archive";
} else {
type = "*";
}
/* 如果无法直接打开,就跳出软件列表给用户选择 */
if (end.equals("apk")) {
} else {
type += "/*";
}
return type;
}
MIME 类型
MIME (Multipurpose Internet Mail Extensions) 是描述消息内容类型的因特网标准。
MIME 消息能包含文本、图像、音频、视频以及其他应用程序专用的数据。
不同的应用程序支持不同的 MIME 类型。
MIME意为多目Internet邮件扩展,它设计的最初目的是为了在发送电子邮件时附加多媒体数据,让邮件客户程序能根据其类型进行处理。然而当它被HTTP协议支持之后,它的意义就更为显著了。它使得HTTP传输的不仅是普通的文本,而变得丰富多彩。
每个MIME类型由两部分组成,前面是数据的大类别,例如声音audio、图象image等,后面定义具体的种类。常见的MIME类型 :
超文本标记语言文本 .html text/html
xml文档 .xml text/xml
XHTML文档 .xhtml application/xhtml+xml
普通文本 .txt text/plain
RTF文本 .rtf application/rtf
PDF文档 .pdf application/pdf
Microsoft Word文件 .word application/msword
PNG图像 .png image/png
GIF图形 .gif image/gif
JPEG图形 .jpeg,.jpg image/jpeg
au声音文件 .au audio/basic
MIDI音乐文件 mid,.midi audio/midi,audio/x-midi
RealAudio音乐文件 .ra, .ram audio/x-pn-realaudio
MPEG文件 .mpg,.mpeg video/mpeg
AVI文件 .avi video/x-msvideo
GZIP文件 .gz application/x-gzip
TAR文件 .tar application/x-tar
任意的二进制数据 application/octet-stream
设备录音
// 开始录音
private void startRec() {
try {
if (Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
/* 取得开始运行的时间 */
startRecTime = System.currentTimeMillis();
/* 取得SD Card路径作为录音的文件位置 */
myRecAudioDir = Environment.getExternalStorageDirectory();
/* 创建录音频文件 */
myRecAudioFile = File.createTempFile(strTempFile,".amr",
myRecAudioDir);
mMediaRecorder01 =new MediaRecorder();
/* 设置录音来源为麦克风 */
mMediaRecorder01.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder01
.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mMediaRecorder01
.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mMediaRecorder01
.setOutputFile(myRecAudioFile.getAbsolutePath());
mMediaRecorder01.prepare();
mMediaRecorder01.start();
isStartRec = true;
Log.i("EX07_12SMSreceiver","startRec");
/* 停止录音 */
mMediaRecorder01.stop();
mMediaRecorder01.release();
mMediaRecorder01 = null;
} else {
SleepSec = 1;
}
} catch (Exception e) {
e.printStackTrace();
}
}
短信接收设置
<uses-permissionandroid:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permissionandroid:name="android.permission.RECORD_AUDIO"></uses-permission>
<application>
<receiverandroid:name="SMSreceiver">
<intent-filter>
<action
android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
</application>
Intent action大全
动作
字符串
描述
MAIN_ACTION
android.intent.action.MAIN
作为主入口点启动,不需要数据
CALL_ACTION
android.intent.action.CALL
拨打电话。 被呼叫的联系人在数据中指定
DIAL_ACTION
android.intent.action.DIAL
拨打数据中指定的电话号码
EDIT_ACTION
android.intent.action.EDIT
为制定的数据显示可编辑界面
ALL_APPS_ACTION
android.intent.action.ALL_APPS
列举所有可用的应用
WEB_SEARCH_ACTION
android.intent.action.WEB_SEARCH
执行 web 搜索
ADD_SHORTCUT_ACTION
android.intent.action.ADD_SHORTCUT
在系统中添加一个快捷方式
ANSWER_ACTION
android.intent.action.ANSWER
处理拨入的电话
DATE_CHANGED_ACTION
android.intent.action.DATE_CHANGED
日期被改变
DEFAULT_ACTION
android.intent.action.VIEW
和 VIEW_ACTION 相同,是在数据上执行的标准动作
DELETE_ACTION
android.intent.action.DELETE
从容器中删除给定的数据
EMERGENCY_DIAL_ACTION
android.intent.action.EMERGENCY_DIAL
拨打紧急电话号码
GET_CONTENT_ACTION
android.intent.action.GET_CONTENT
让用户选择数据并返回
INSERT_ACTION
android.intent.action.INSERT
在容器中插入一个空项 (item)
INTENT_EXTRA
android.intent.extra.INTENT
和 PICK_ACTIVITY_ACTION 一起使用时,说明用户选择的用来显示的 activity;和 ADD_SHORTCUT_ACTION 一起使用的时候,描述要添加的快捷方式
LABEL_EXTRA
android.intent.extra.LABEL
大写字母开头的字符标签,
和 ADD_SHORTCUT_ACTION 一起使用
LOGIN_ACTION
android.intent.action.LOGIN
获取登录凭证
NETWORK_TICKLE_RECEIVED_ACTION
android.intent.action.NETWORK_TICKLE_RECEIVED
设备收到了新的网络 “tickle” 通知
SYNC_ACTION
android.intent.action.SYNC
执行数据同步
TIMEZONE_CHANGED_ACTION
android.intent.action.TIMEZONE_CHANGED
时区已经改变
TIME_CHANGED_ACTION
android.intent.action.TIME_SET
时间已经改变(重新设置)
TIME_TICK_ACTION
android.intent.action.TIME_TICK
当前时间已经变化(正常的时间流逝)
UMS_CONNECTED_ACTION
android.intent.action.UMS_CONNECTED
设备进入 USB 大容量存储模式
UMS_DISCONNECTED_ACTION
android.intent.action.UMS_DISCONNECTED
设备从 USB 大容量存储模式退出
DATA_CONNECTION_STATE_CHANGED_ACTION
android.intent.action.DATA_STATE
电话的数据连接状态已经改变
BATTERY_CHANGED_ACTION
android.intent.action.BATTERY_CHANGED
充电状态,或者电池的电量发生变化
BOOT_COMPLETED_ACTION
android.intent.action.BOOT_COMPLETED
在系统启动后。 这个动作被广播一次(只有一次)
BUG_REPORT_ACTION
android.intent.action.BUG_REPORT
显示 activity 报告错误
CALL_FORWARDING_STATE_CHANGED_ACTION
android.intent.action.CFF
语音电话的呼叫转移状态已经改变
CLEAR_CREDENTIALS_ACTION
android.intent.action.CLEAR_CREDENTIALS
清除登陆凭证 (credential)
CONFIGURATION_CHANGED_ACTION
android.intent.action.CONFIGURATION_CHANGED
设备的配置信息已经改变
DATA_ACTIVITY_STATE_CHANGED_ACTION
android.intent.action.DATA_ACTIVITY
电话的数据活动(data activity)状态(即收发数据的状态)已经改变
MEDIABUTTON_ACTION
android.intent.action.MEDIABUTTON
用户按下了“Media Button”
MEDIA_BAD_REMOVAL_ACTION
android.intent.action.MEDIA_BAD_REMOVAL
扩展介质(扩展卡)已经从 SD 卡插槽拔出,但是挂载点 (mount point) 还没解除 (unmount)。
MEDIA_EJECT_ACTION
android.intent.action.MEDIA_EJECT
用户想要移除扩展介质(拔掉扩展卡)
MEDIA_MOUNTED_ACTION
android.intent.action.MEDIA_MOUNTED
扩展介质被插入,而且已经被挂载
MEDIA_REMOVED_ACTION
android.intent.action.MEDIA_REMOVED
扩展介质被移除
MEDIA_SCANNER_FINISHED_ACTION
android.intent.action.MEDIA_SCANNER_FINISHED
已经扫描完介质的一个目录
MEDIA_SCANNER_STARTED_ACTION
android.intent.action.MEDIA_SCANNER_STARTED
开始扫描介质的一个目录
MEDIA_SHARED_ACTION
android.intent.action.MEDIA_SHARED
扩展介质的挂载被解除 (unmount)。 因为它已经作为 USB 大容量存储被共享
MEDIA_UNMOUNTED_ACTION
android.intent.action.MEDIA_UNMOUNTED
扩展介质存在,但是还没有被挂载 (mount)
MESSAGE_WAITING_STATE_CHANGED_ACTION
android.intent.action.MWI
电话的消息等待(语音邮件)状态已经改变
PACKAGE_ADDED_ACTION
android.intent.action.PACKAGE_ADDED
设备上新安装了一个应用程序包
PACKAGE_REMOVED_ACTION
android.intent.action.PACKAGE_REMOVED
设备上删除了一个应用程序包
PHONE_STATE_CHANGED_ACTION
android.intent.action.PHONE_STATE
电话状态已经改变
PICK_ACTION
android.intent.action.PICK
从数据中选择一个项目 (item),将被选中的项目返回
PICK_ACTIVITY_ACTION
android.intent.action.PICK_ACTIVITY
选择一个 activity,返回被选择的 activity 的类(名)
PROVIDER_CHANGED_ACTION
android.intent.action.PROVIDER_CHANGED
更新将要(真正)被安装
PROVISIONING_CHECK_ACTION
android.intent.action.PROVISIONING_CHECK
要求 polling of provisioning service 下载最新的设置
UN_ACTION
android.intent.action.RUN
运行数据(指定的应用),无论它(应用)是什么
SCREEN_OFF_ACTION
android.intent.action.SCREEN_OFF
屏幕被关闭
SCREEN_ON_ACTION
android.intent.action.SCREEN_ON
屏幕已经被打开
SENDTO_ACTION
android.intent.action.SENDTO
向 data 指定的接收者发送一个消息
SERVICE_STATE_CHANGED_ACTION
android.intent.action.SERVICE_STATE
电话服务的状态已经改变
SETTINGS_ACTION
android.intent.action.SETTINGS
显示系统设置
SIGNAL_STRENGTH_CHANGED_ACTION
android.intent.action.SIG_STR
电话的信号强度已经改变
STATISTICS_REPORT_ACTION
android.intent.action.STATISTICS_REPORT
要求 receivers 报告自己的统计信息
VIEW_ACTION
android.intent.action.VIEW
向用户显示数据
XMPP_CONNECTED_ACTION
android.intent.action.XMPP_CONNECTED
XMPP 连接已经被建立
XMPP_DISCONNECTED_ACTION
android.intent.action.XMPP_DI
XMPP 连接已经被断开
Intent category大全
动作
字符串
描述
LAUNCHER_CATEGORY
android.intent.category.LAUNCHER
Activity 应该被显示在顶级的 launcher 中
TEST_CATEGORY
android.intent.category.TEST
作为测试目的使用,不是正常的用户体验的一部分
TAB_CATEGORY
android.intent.category.TAB
这个 activity 应该在 TabActivity 中作为一个 tab 使用
GADGET_CATEGORY
android.intent.category.GADGET
这个 activity 可以被嵌入宿主 activity
HOME_CATEGORY
android.intent.category.HOME
主屏幕 (activity)。 设备启动后显示的第一个 activity
DEFAULT_CATEGORY
android.intent.category.DEFAULT
如果 activity 是对数据执行确省动作(点击, center press)的一个选项,需要设置这个类别
ALTERNATIVE_CATEGORY
android.intent.category.ALTERNATIVE
说明 activity 是用户正在浏览的数据的一个可选操作
BROWSABLE_CATEGORY
android.intent.category.BROWSABLE
能够被浏览器安全使用的 activities 必须支持这个类别
PREFERENCE_CATEGORY
android.intent.category.PREFERENCE
activity是一个设置面板 (preference panel)
SELECTED_ALTERNATIVE_CATEGORY
android.intent.category.SELECTED_ALTERNATIVE
对于被用户选中的数据。 activity 是它的一个可选操作
UNIT_TEST_CATEGORY
android.intent.category.UNIT_TEST
应该被用作单元测试(通过 test harness 运行)
WALLPAPER_CATEGORY
android.intent.category.WALLPAPER
这个 activity 能过为设备设置墙纸
WALLPAPER_CHANGED_ACTION
android.intent.action.WALLPAPER_CHANGED
系统的墙纸已经改变
WALLPAPER_SETTINGS_ACTION
android.intent.action.WALLPAPER_SETTINGS
显示选择墙纸的设置界面
颜色Color
Color.BLACK = 0xFF000000;
Color.DKGRAY = 0xFF444444;
Color.GRAY = 0xFF888888;
Color.LTGRAY = 0xFFCCCCCC;
Color.WHITE = 0xFFFFFFFF;
Color.RED = 0xFFFF0000;
Color.GREEN = 0xFF00FF00;
Color.BLUE= 0xFF0000FF;
Color.YELLOW = 0xFFFFFF00;
Color.CYAN= 0xFF00FFFF;
Color.MAGENTA = 0xFFFF00FF;
Color. TRANSPARENT = 0;
DisplayMetrics使用
DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
dm.heightPixels;
dm.widthPixels;
Style使用
在res/values中定义style.xml文件
<?xml version=”1.0” version=”utf-8”>
<style name=”testStyle”>
<item name=”android:textSize”>14sp</item>
<item name=”android:textColor”>#FFFFFF</item>
<item name=”android:fromAlpha”>0.0</item>
<item name=”android:toAlpha”>0.0</item>
</style>
打电话发短信
在AndroidManifest.xml中定义uses-permission节点
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
打电话:
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse(“tel:110“);
startActivity(intent);
或者
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+"5556"));
startActivity(intent);
发信息:需要输入电话号码
Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "信息内容...");
it.setType("vnd.android-dir/mms-sms");
startActivity(it);
发信息:不需要输入电话号码
Uri smsToUri = Uri.parse("smsto:5556");
Intent mIntent = new Intent(android.content.Intent.ACTION_SENDTO, smsToUri);
mIntent.putExtra("sms_body", "aaabbb...");
startActivity(mIntent);
访问SDCARD
首先在AndroidManifest.xml文件中设置访问权限:
<uses-permission android:name=”android.permission.MOUNT_UNMOUNT_FILESYSTEMS”/>
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”/>
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
File sdCardDir = Environment.getExternalStorageDirectory();//获取SDCard目录
File saveFile = new File(sdCardDir, “itcast.txt”);
FileOutputStream outStream = new FileOutputStream(saveFile);
outStream.write("传智播客".getBytes());
outStream.close();
}
conversion to dalvik format failed with error 1的解决办法
android低版本工程(如1.5)放到高版本环境中(如2.2)可能会上述错误,解决方法如下:
1。 如果不修改android sdk版本,则使用project clean 命令作用于某工程即可。
(该处理方式只是在高版本中兼容了低版本工程,未真正意义上的升级)
2。 如果修改android sdk版本,则需要以下几个步骤:
1)修改SDK
选择工程,build path --> configure build path ---> library 删除引用的低版本SDK, 然后add External JARs,选择高版本SDK,OK,保存
2)修改classpath文件
该文件可能存在该项: <classpathentry kind="lib" path ="你所指定的高版本的地址" 把她修改成<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK" />
3) 修改AndroidManifest.xml
在AndroidManifest.xml文件中,application标签后添加<uses-sdk android:minSdkVersion="3"></uses-sdk>
4) 修改default.properties(很重要)
该文件最后一行(前面没用#的)target=android-3 该成target=android-8,保存
intent中属性的设置
action—通常要执行的动作,比如ACTION_VIEW, ACTION_EDIT, ACTION_MAIN, 等.
data—执行动作要操作的数据,Android采用指向数据的一个URI来表示。对于不同的动作,其URI数据的类型是不同的(可以设置type属性指 定特定类型数据),如ACTION_EDIT指定Data为文件URI,打电话为tel:URI,访问网络为http:URI,而由content provider提供的数据则为content: URIs。
category—被执行动作的附加信息。
type—显式指定Intent的数据类型 (MIME)。一般Intent的数据类型能够根据数据本身进行判定,但是通过设置这个属性,可以强制采用显式指定的类型而不再进行推导。
component—指定Intent的的目标组件的类名称。通常 Android会根据Intent 中包含的其它属性的信息,比如action、data/type、category进行查找,最终找到一个与之匹配的目标组件。但是,如果 component这个属性有指定的话,将直接使用它指定的组件,而不再执行上述查找过程。指定了这个属性以后,Intent的其它所有属性都是可选的。
extras—是其它所有附加信息的集合。使用extras可以为组件提供扩展信息,比如,如果要执行“发送电子邮件”这个动作,可以将电子邮件的标题、正文等保存在extras里,传给电子 邮件发送组件。
理解Intent的关键之一是理解清楚Intent的两种基本用法:一种是显式的Intent,即在构造Intent对象时就指定接收者;另一种是隐式的 Intent,即Intent的发送者在构造Intent对象时,并不知道也不关心接收者是谁,有利于降低发送者和接收者之间的耦合。
对于显式Intent,Android不需要去做解析,因为目标组件已经很明确,Android需要解析的是那些隐式Intent,通过解析,将Intent映射给可以处理此Intent的Activity、IntentReceiver或Service。
Intent 解析机制主要是通过查找已注册在 AndroidManifest.xml中的所有IntentFilter及其中定义的Intent,最终找到匹配的Intent。在这个解析过程中,Android是通过Intent的action、type、category这三个属性来进行判断的,判断方法如下:
如果 Intent指明定了action,则目标组件的IntentFilter的action列表中就必须包含有这个action,否则不能匹配;
如 果Intent没有提供type,系统将从data中得到数据类型。和action一样,目标组件的数据类型列表中必须包含Intent的数据类型,否则 不能匹配。
如果Intent中的数据不是content: 类型的URI,而且Intent也没有明确指定它的type,将根据Intent中数据的scheme (比如 http: 或者mailto:) 进行匹配。同上,Intent 的scheme必须出现在目标组件的scheme列表中。
如果Intent指定了一个或多个 category,这些类别必须全部出现在组建的类别列表中。比如Intent中包含了两个类别:LAUNCHER_CATEGORY 和 ALTERNATIVE_CATEGORY,解析得到的目标组件必须至少包含这两个类别
ContentProvider创建
1、 继承ContentProvider抽象类
2、 定义数据集的MIME类型字符串
//数据集的MIME类型字符串,应该以vnd.android.cursor.dir/开头
public static final String PERSONS_TYPE ="vnd.android.cursor.dir/person";
3、 定义单一数据的MIME类型字符串,应该以vnd.android.cursor.item/开头
//单一数据的MIME类型字符串应该以vnd.android.cursor.item/开头
public static final String PERSONS_ITEM_TYPE ="vnd.android.cursor.item/person";
4、 定义uri的authority部分
public static final String AUTHORITY ="cn.itcast.provider.personprovider";//主机名
5、 为UriMatcher类添加uri sMatcher.addURI(AUTHORITY,"person", PERSONS);
//如果match()方法匹配content://cn.itcast.provider.personprovider/person路径,返回匹配码为PERSONS
sMatcher.addURI(AUTHORITY,"person", PERSONS);
//如果match()方法匹配content://cn.itcast.provider.personprovider/person/230路径,返回匹配码为PERSON
sMatcher.addURI(AUTHORITY,"person/#", PERSON);
其中#表示number、*表示text
6、 的
7、 的
创建bitmap
设置size,由bitmap类创建
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth,scaleHeight);
Bitmap resizeBmp = Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight,
matrix, true);
根据图片路径或者resourceid、inputstream创建bitmpa
Bitmap bm = BitmapFactory.decodeFile("");
Bitmap bm = BitmapFactory.decodeStream(null);
Bitmap bm = BitmapFactory.decodeResource(resourcesid, bmpWidth);
访问浏览器的收藏夹
Cursor bookmarks = Browser.getAllBookmarks(getContentResolver());
int urlColumn = bookmarks.getColumnIndex(Browser.BookmarkColumns.URL);
Cursor results;
String[] proj = new String[]
{
BaseColumns._ID,
Browser.BookmarkColumns.URL,
Browser.BookmarkColumns.TITLE
};
results = managedQuery(Browser.BOOKMARKS_URI,proj, null,Browser.BookmarkColumns.URL+" ASC");
设置风格样式
<?xmlversion="1.0"encoding="utf-8"?>
<resources>
<!--基础应用程式主题,为预设主题 -->
<stylename="Theme"parent="android:Theme"></style>
<!--变更应用程序的主题,使之具有translucent背景-->
<stylename="Theme.Translucent">
<itemname="android:windowBackground">
@drawable/translucent_background
</item>
<itemname="android:windowNoTitle">false</item>
<itemname="android:colorForeground">@drawable/blue</item>
<itemname="android:colorBackground">@drawable/white</item>
</style>
<!--变更应用程序的主题,使之具有不同颜色背景且具有translucent背景-->
<stylename="Theme.Translucent2">
<itemname="android:windowBackground">@drawable/pink</item>
<itemname="android:windowNoTitle">false</item>
<itemname="android:colorForeground">@drawable/darkgreen</item>
<itemname="android:colorBackground">@drawable/pink</item>
</style>
<!--变更应用程序的主题,使之具有透明transparent背景-->
<stylename="Theme.Transparent">
<itemname="android:windowBackground">
@drawable/transparent_background
</item>
<itemname="android:windowNoTitle">true</item>
<itemname="android:colorForeground">@drawable/blue</item>
<itemname="android:colorBackground">@drawable/pink</item>
</style>
<stylename="TextAppearance.Theme.PlainText"
parent="android:TextAppearance.Theme">
<itemname="android:textStyle">normal</item>
</style>
</resources>
自动安装apk文件
private void openFile(File f) {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
/* 调用getMIMEType()来取得MimeType */
String type = getMIMEType(f);
/* 设置intent的file与MimeType */
intent.setDataAndType(Uri.fromFile(f), type);
startActivity(intent);
}
/* 依扩展名的类型决定MimeType */
if (end.equals("m4a") || end.equals("mp3") || end.equals("mid")
|| end.equals("xmf") || end.equals("ogg") || end.equals("wav")) {
type = "audio";
} else if (end.equals("3gp") || end.equals("mp4")) {
type = "video";
} else if (end.equals("jpg") || end.equals("gif") || end.equals("png")
|| end.equals("jpeg") || end.equals("bmp")) {
type = "image";
} else if (end.equals("apk")) {
/* android.permission.INSTALL_PACKAGES */
type = "application/vnd.android.package-archive";
} else {
/* 如果无法直接打开,就跳出软件列表给用户选择 */
type = "*/*
}
13705155619
Notification使用
1.通过getSystemService方法获得一个NotificationManager对象。
2.创建一个Notification对象。每一个Notification对应一个Notification对象。在这一步需要设置显示在屏幕上方状态栏的通知消息、通知消息前方的图像资源ID和发出通知的时间。一般为当前时间。
3.由于Notification可以与应用程序脱离。也就是说,即使应用程序被关闭,Notification仍然会显示在状态栏中。当应用程序再次启动后,又可以重新控制这些Notification。如清除或替换它们。因此,需要创建一个PendingIntent对象。该对象由Android系统负责维护,因此,在应用程序关闭后,该对象仍然不会被释放。
4.使用Notification类的setLatestEventInfo方法设置Notification的详细信息。
5.使用NotificationManager类的notify方法显示Notification消息。在这一步需要指定标识Notification的唯一ID。这个ID必须相对于同一个NotificationManager对象是唯一的,否则就会覆盖相同ID的Notificaiton
设置墙纸
1、 在androidManifest.xml文件中设置permission
android.permission.SET_WALLPAPER
2、 调用ContextWraper类的setWallpaper(),并传入bitmap对象。可以通过BitmapFactory的静态方法创建bitmap
3、 通过clearWallpaper()方法回复默认的墙纸
Notification使用
- android通过URL路径下载安装文件
- Android: 通过URL下载文件
- Tomcat通过文件路径URL下载自动重命名文件
- 通过url下载文件
- 通过url下载文件
- 通过URL下载文件
- 通过URL下载文件
- ipa文件通过url下载
- java通过URL下载文件
- js通过Url下载文件
- Java通过文件路径下载文件
- java 通过url下载文件到浏览
- 通过url下载服务器上的文件
- jq及html通过url下载文件
- 通过URL实现下载
- 通过进程pid查看文件安装路径
- 下载服务器上的文件—通过url
- QTP 通过URL地址下载文件到本地
- restlet中resource类处理请求的两种写法说明
- 使用PS滤镜打造漂亮彩色光环
- Convert Sorted List to Binary Search Tree 把有序链表转为BST@LeetCode
- 神奇的HomeBrew
- 每天一个linux命令(31): /etc/group文件详解
- android通过URL路径下载安装文件
- libpng库的使用讲解
- android4.2 动态显示/隐藏导航栏
- 函数inet_addr和inet_ntoa-linux
- c实现学生成绩管理系统 MIS
- 每天一个linux命令(32):gzip命令
- 分布式发电相关
- 每天一个linux命令(33):df 命令
- 匿名类的实例监视窗口事件