惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LINUX DO - 最新话题
Recorded Future
Recorded Future
月光博客
月光博客
博客园 - 【当耐特】
博客园 - 叶小钗
宝玉的分享
宝玉的分享
量子位
雷峰网
雷峰网
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
Vercel News
Vercel News
L
LangChain Blog
B
Blog
Y
Y Combinator Blog
爱范儿
爱范儿
GbyAI
GbyAI
S
Security @ Cisco Blogs
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
博客园 - Franky
P
Palo Alto Networks Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
Scott Helme
Scott Helme
I
Intezer
T
The Exploit Database - CXSecurity.com
MyScale Blog
MyScale Blog
T
Tor Project blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Troy Hunt's Blog
N
News and Events Feed by Topic
大猫的无限游戏
大猫的无限游戏
F
Fortinet All Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
Security Affairs
Cyberwarzone
Cyberwarzone
PCI Perspectives
PCI Perspectives
小众软件
小众软件
D
DataBreaches.Net
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Know Your Adversary
Know Your Adversary
Forbes - Security
Forbes - Security
S
Securelist
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
The Last Watchdog
The Last Watchdog

博客园 - CoderDream

[设计模式]单例模式 [设计模式]模板模式 Windows8下通过IPv4地址访问Tomcat RESTful最佳实践之基于 jersey 的增删改查 Maven 版 JPA 最佳实践 Android项目实战手机安全卫士(02) 推荐十一个很酷的实用网站 类 ObjectOutputStream的writeObject()方法的中英文对照 2006.08.21网摘 20060818网摘 20060702 长沙职位信息 20060702 网摘 20060630 网摘 Eclipse 入门与提高 第01章 基础知识 今天答辩, 第二阶段(标准阶段)已经过去了! 只剩下最后4个月了! 亿阳信通股份有限公司 J2EE软件设计工程师 上海掌上灵通咨询有限公司 Java软件开发工程师 20060519网摘
Android项目实战手机安全卫士(01)
CoderDream · 2014-11-11 · via 博客园 - CoderDream

目录

  • 项目结构图
  • 源代码
  • 运行结果

项目结构图

V0100_01

源代码

SplashActivity.java

package com.coderdream.mobilesafe.activity;

import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.coderdream.mobilesafe.R;

public class SplashActivity extends Activity {
	private TextView tv_splash_version;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 设置为无标题栏
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		// 设置为全屏模式
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);

		setContentView(R.layout.activity_splash);
		tv_splash_version = (TextView) findViewById(R.id.tv_splash_version);
		tv_splash_version.setText("版本号:" + getVersion());
	}

	/**
	 * <pre>
	 * 获取当前应用程序的版本号。 
	 * 版本号存在于我们的APK中对应的清单文件中(直接解压APK后,即可看到对应的清单文件),
	 * 版本号是manifest节点中的android:versionName="1.0" 
	 * 当一个应用程序被装到手机后 ,该apk拷贝到手机的data/app目录下(也就是系统中),
	 * 如图6。所以想得到版本号,我们需要拿到与系统相关的服务,就可以得到apk中的信息了
	 * 
	 * </pre>
	 * 
	 * @return
	 */
	private String getVersion() {
		// 得到系统的包管理器。已经得到了apk的面向对象的包装
		PackageManager pm = this.getPackageManager();
		try {
			// 参数一:当前应用程序的包名 参数二:可选的附加消息,这里我们用不到 ,可以定义为0
			PackageInfo info = pm.getPackageInfo(getPackageName(), 0);
			// 返回当前应用程序的版本号
			return info.versionName;
		} catch (Exception e) {// 包名未找到的异常,理论上, 该异常不可能会发生
			e.printStackTrace();
			return "";
		}
	}
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.coderdream.mobilesafe"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.coderdream.mobilesafe.activity.SplashActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

运行结果

V0100_02