zoukankan      html  css  js  c++  java
  • 手机安全卫士开发系列(7)——知识点整理(1)

    一.      理解 application的图标和 桌面activity的图标

    在清单文件中对应的节点配置.

        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <uses-library android:name="android.test.runner" />
    
            <activity
                android:icon="@drawable/icon5"
                android:label="@string/app_name"
                android:name=".ui.SplashActivity" >

    二、      Splash全屏显示

    1、去掉标题栏

            (1)也一般入门的时候经常使用的一种方法

    //取消标题栏

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    //完成窗体的全屏显示 //取消掉状态栏

           getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

                  WindowManager.LayoutParams.FLAG_FULLSCREEN

             (2)在AndroidManifest.xml文件中定义

    <application android:icon="@drawable/icon" 
            android:label="@string/app_name" 
            android:theme="@android:style/Theme.NoTitleBar">

         (3) 这种在一般的应用中不常用,就是在res/values目录下面新建一个style.xml的文件

    <?xml version="1.0" encoding="UTF-8" ?>
    <resources>
        <style name="notitle">
            <item name="android:windowNoTitle">true</item>
        </style> 
    </resources>


    这样,我们就自定义了一个style,就相当于一个主题,然后在AndroidManifest.xml文件中定义

    <application android:icon="@drawable/icon" 
            android:label="@string/app_name" 
            android:theme="@style/notitle">

    总结:
    第一种,有的时候我们会看到,会先出现标题栏,然后再消失,因为我们只是在activity的oncreate方法中定义的,第二种相对第一种比较好一些,不会出现这种情况,第三种我个人感觉最好,这样把功能分开,便于维护和扩展

    2、全屏显示

    第一种

     

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

     

    第二种

     

    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

     

    第三种

    application android:icon ="@drawable/icon"
    android:label
    ="@string/app_name"
    android:theme
    ="@style/fullscreem"

    三、  pull解析xml

    	/**
    	 * 
    	 * @param urlid 服务器路径string对应的id
    	 * @return 更新的信息
    	 */
    	public UpdataInfo getUpdataInfo(int urlid) throws Exception{
    		String path = context.getResources().getString(urlid);
    		URL url = new URL(path);
    		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    		conn.setConnectTimeout(2000);
    		conn.setRequestMethod("GET");
    		InputStream is = conn.getInputStream();
    		return  UpdataInfoParser.getUpdataInfo(is);
    	}
    	/**
    	 * 
    	 * @param is
    	 *            解析的xml的inputstream
    	 * @return updateinfo
    	 */
    	public static UpdataInfo getUpdataInfo(InputStream is) throws Exception {
    		XmlPullParser parser = Xml.newPullParser();
    		UpdataInfo info = new UpdataInfo();
    		parser.setInput(is, "utf-8");
    		int type = parser.getEventType();
    
    		while (type != XmlPullParser.END_DOCUMENT) {
    			switch (type) {
    			case XmlPullParser.START_TAG:
    				if("version".equals(parser.getName())){
    					String version = parser.nextText();
    					info.setVersion(version);
    				}else if("description".equals(parser.getName())){
    					String description = parser.nextText();
    					info.setDescription(description);
    				}else if("apkurl".equals(parser.getName())){
    					String apkurl = parser.nextText();
    					info.setApkurl(apkurl);
    				}
    				
    				break;
    
    			}
    
    			type = parser.next();
    		}
    		return info;
    	}

    URL代表统一资源定位器,它是一个指向互联网“资源”的指针。

    通常情况下,URL可以由协议名、主机、端口和资源组成。如下格式:

           protocal://host:port/resourceName

           例如:http://www.baidu.com/index.jsp

          JDK中提供了一个URL类,该类代表一个统一资源标识符,URL包含一个可以打开到该资源的输入流。

          URL的openConnection方法返回一个URLConnection对象,通过该对象可以发送URL请求。

          如果只是GET方式请求、使用connect方法建立远程资源之间的实际连接即可;如果需要发送POST请求,需要获取URLConnection实例对应的输出流来发送请求参数。

    四、  URL httpUrlConnection

    	/**
    	 * 
    	 * @param path 服务器文件路径
    	 * @param filepath 本地文件路径 
    	 * @return 本地文件对象
    	 * @throws Exception
    	 */
    	public static File getFile(String path,String filepath,ProgressDialog pd) throws Exception{
    		URL url = new URL(path);
    		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    		conn.setRequestMethod("GET");
    		conn.setConnectTimeout(5000);
    		if(conn.getResponseCode() == 200){
    			int total =  conn.getContentLength();
    			pd.setMax(total);
    			InputStream is = conn.getInputStream();
    			File file = new File(filepath);
    			FileOutputStream fos = new FileOutputStream(file);
    			byte[] buffer = new byte[1024];
    			int len = 0;
    			int process = 0;
    			while((len = is.read(buffer))!=-1){
    				fos.write(buffer, 0, len);
    				process +=len;
    				pd.setProgress(process);
    			}
    			fos.flush();
    			fos.close();
    			is.close();
    			
    			return file;
    		}
    		return null;
    	}

    HttpURLConnection是URLConnection的子类、在URLConnection类的基础上做了进一步的改进、增加了一些用于操作HTTP资源的便捷方法。

    五、 获取当前客户端版本号

    	/**
    	 * 获取当前应用程序的版本号
    	 * 
    	 * @return
    	 */
    	private String getVersion() {
    		try {
    			PackageManager manager = getPackageManager();
    			PackageInfo info = manager.getPackageInfo(getPackageName(), 0);
    			return info.versionName;
    		} catch (Exception e) {
    
    			e.printStackTrace();
    			return "版本号未知";
    		}
    	}

    PackageManager  getPackageManager();  //得到系统的包管理服务

    [java] view plaincopy
     
    1. /** 
    2.      * PackageManager介绍: 
    3.      * 本类API是对所有基于加载信息的数据结构的封装,包括以下功能:  
    4.      * 安装,卸载应用 查询permission相关信息 查询Application相关 
    5.      * 信息(application,activity,receiver,service,provider及相应属性等) 
    6.      * 查询已安装应用 增加,删除permission 清除用户数据、缓存,代码段等 非查询相关的API需要特定的权限。 
    7.      * 主要包含了,安装在当前设备上的应用包的相关信息 
    8.      * 如下:获取已经安装的应用程序的信息 
    9.      */  
    10.     private HashMap<String, String> installPackagesInfo(){  
    11.         // 获取packageManager对象  
    12.         PackageManager packageManager = this.getPackageManager();  
    13.         /*getInstalledApplications 返回当前设备上安装的应用包集合 
    14.          * ApplicationInfo对应着androidManifest.xml中的application标签。通过它可以获取该application对应的信息 
    15.          */  
    16.         List<ApplicationInfo> applicationInfos = packageManager.getInstalledApplications(0);  
    17.         HashMap<String, String> resultMap = new HashMap<String, String>();  
    18.         Iterator<ApplicationInfo> iterator = applicationInfos.iterator();  
    19.         while(iterator.hasNext()){  
    20.             ApplicationInfo applicationInfo = iterator.next();  
    21.             String packageName = applicationInfo.packageName;// 包名  
    22.             String packageLabel = packageManager.getApplicationLabel(applicationInfo).toString();//获取label  
    23.             resultMap.put(packageLabel, packageName);  
    24.         }  
    25.           
    26.         return resultMap;  
    27.           
    28.     }  



  • 相关阅读:
    消息中间件——RabbitMQ(六)理解Exchange交换机核心概念!
    消息中间件——RabbitMQ(五)快速入门生产者与消费者,SpringBoot整合RabbitMQ!
    消息中间件——RabbitMQ(四)命令行与管控台的基本操作!
    消息中间件——RabbitMQ(三)理解RabbitMQ核心概念和AMQP协议!
    LayUI的基本使用
    Git报错:Your branch is up to date with 'origin/master'.
    Git报错:Please tell me who you are.
    Git报错:Permission denied (publickey)
    在 windows 上安装 git 2.22
    在 windows 上安装 git 2.15
  • 原文地址:https://www.cnblogs.com/riskyer/p/3306262.html
Copyright © 2011-2022 走看看