当前位置:  编程技术>移动开发
本页文章导读:
    ▪APKTool打包的一个小疑点        APKTool打包的一个小问题 0x01,又开始写blog了,好久没有网络了,最近终于可以开始继续研究技术了。           今天的问题是大家再用到APKTool时估计常见的一个问题,           在windows.........
    ▪ varnish实现装置检测        varnish实现设备检测 原文出处:https://www.varnish-cache.org/docs/3.0/tutorial/devicedetection.html   设备检测室根据用户请求的User-Agent来判断返回正确的内容。   这样的例子包括对于手机用户这样小屏幕.........
    ▪ 检测usb是不是连接pc       检测usb是否连接pc IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = context.registerReceiver(null, ifilter); int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); boolean isCharg.........

[1]APKTool打包的一个小疑点
    来源: 互联网  发布时间: 2014-02-18
APKTool打包的一个小问题

0x01,又开始写blog了,好久没有网络了,最近终于可以开始继续研究技术了。

          今天的问题是大家再用到APKTool时估计常见的一个问题,

          在windows下,用APKTool进行打包时,有时会爆这个错误,甚至我们在反编译完没经过任何改动的时候,直接重打包也会遇到

          

I: Smaling...
I: Building resources...
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [aapt, p, --min-sdk-version, 10, --target-sdk-version, 10, -F, C:\Users\ice\AppData\Local\Temp\APKTOOL5697750537225709497.tmp, -0, arsc, -I, C:\Users\ice\apktool\framework\1.apk, -S, F:\webattack\android\result\decompile\res, -M, F:\webattack\android\result\decompile\AndroidManifest.xml]
	at brut.androlib.Androlib.buildResourcesFull(Androlib.java:358)
	at brut.androlib.Androlib.buildResources(Androlib.java:283)
	at brut.androlib.Androlib.build(Androlib.java:206)
	at brut.androlib.Androlib.build(Androlib.java:176)
	at brut.apktool.Main.cmdBuild(Main.java:228)
	at brut.apktool.Main.main(Main.java:79)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [aapt, p, --min-sdk-version, 10, --target-sdk-version, 10, -F, C:\Users\lenovo\AppData\Local\Temp\APKTOOL5697750537225709497.tmp, -0, arsc, -I, C:\Users\lenovo\apktool\framework\1.apk, -S, F:\webattack\android\result\decompile\res, -M, F:\webattack\android\result\decompile\AndroidManifest.xml]
	at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:357)
	at brut.androlib.Androlib.buildResourcesFull(Androlib.java:336)
	... 5 more
Caused by: brut.common.BrutException: could not exec command: [aapt, p, --min-sdk-version, 10, --target-sdk-version, 10, -F, C:\Users\lenovo\AppData\Local\Temp\APKTOOL5697750537225709497.tmp, -0, arsc, -I, C:\Users\lenovo\apktool\framework\1.apk, -S, F:\webattack\android\result\decompile\res, -M, F:\webattack\android\result\decompile\AndroidManifest.xml]
	at brut.util.OS.exec(OS.java:93)
	at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:355)
	... 6 more
Caused by: java.io.IOException: Cannot run program "aapt": CreateProcess error=2, ?????????
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
	at java.lang.Runtime.exec(Runtime.java:593)
	at java.lang.Runtime.exec(Runtime.java:466)
	at brut.util.OS.exec(OS.java:84)
	... 7 more
Caused by: java.io.IOException: CreateProcess error=2, ?????????
	at java.lang.ProcessImpl.create(Native Method)
	at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
	at java.lang.ProcessImpl.start(ProcessImpl.java:30)
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
	... 10 more

 

 

0x 02  顾名思义,就是aapt.exe创建失败了,为什么呢,大家可以看到在apktool.bat路径下,aapt.exe好好存在着。。经过研究发现,主要是apktool.bat的调用里面大家可以发现是这样的

@echo off
set PATH=%CD%;%PATH%;
java -jar "%~dp0\apktool.jar" %1 %2 %3 %4 %5 %6 %7 %8 %9

 

很明显,程序的查找路径只有当前目录和Path,如果你不在apktool的所在目录调用apktool.bat的话,那么对apktool.jar对aapt.exe的间接调用就会发生找不到的问题。

 

0x03 解决就很简单了,要么把命令行定位到apktool的目录,要么一劳永逸的把apktool的路径直接加到环境变量path中去。

 

0x04  很简单吧。。。。。。

         其实人家官网写了这步。。。。



 

    

就这些了


    
[2] varnish实现装置检测
    来源: 互联网  发布时间: 2014-02-18
varnish实现设备检测

原文出处:https://www.varnish-cache.org/docs/3.0/tutorial/devicedetection.html

 

设备检测室根据用户请求的User-Agent来判断返回正确的内容。

 

这样的例子包括对于手机用户这样小屏幕并且高延迟网络发送压缩的文件,或者提供客户端能辨认的流媒体编码格式。

 

有几种策略来处理这样的用户请求:1)redirect到其他的URL. 2) 对于特殊的用户使用不同的后台;3)改变后台的请求以保证后台发送处理过的内容。

 

To make the examples easier to understand, it is assumed in this text that all the req.http.X-UA-Device header is present and unique per client class that content is to be served to.

Setting this header can be as simple as:

sub vcl_recv {
    if (req.http.User-Agent ~ "(?i)iphone" {
        set req.http.X-UA-Device = "mobile-iphone";
    }
}

There are different commercial and free offerings in doing grouping and identifiying clients in further detail than this. For a basic and community based regular expression set, see https://github.com/varnish/varnish-devicedetect/ .

Serve the different content on the same URL

The tricks involved are: 1. Detect the client (pretty simple, just include devicedetect.vcl and call it) 2. Figure out how to signal the backend what client class this is. This includes for example setting a header, changing a header or even changing the backend request URL. 3. Modify any response from the backend to add missing Vary headers, so Varnish' internal handling of this kicks in. 4. Modify output sent to the client so any caches outside our control don't serve the wrong content.

All this while still making sure that we only get 1 cached object per URL per device class.

Example 1: Send HTTP header to backend

The basic case is that Varnish adds the X-UA-Device HTTP header on the backend requests, and the backend mentions in the response Vary header that the content is dependant on this header.

Everything works out of the box from Varnish' perspective.

VCL:

sub vcl_recv {
    # call some detection engine that set req.http.X-UA-Device
}
# req.http.X-UA-Device is copied by Varnish into bereq.http.X-UA-Device

# so, this is a bit conterintuitive. The backend creates content based on
# the normalized User-Agent, but we use Vary on X-UA-Device so Varnish will
# use the same cached object for all U-As that map to the same X-UA-Device.
#
# If the backend does not mention in Vary that it has crafted special
# content based on the User-Agent (==X-UA-Device), add it.
# If your backend does set Vary: User-Agent, you may have to remove that here.
sub vcl_fetch {
    if (req.http.X-UA-Device) {
        if (!beresp.http.Vary) { # no Vary at all
            set beresp.http.Vary = "X-UA-Device";
        } elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary
            set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device";
        }
    }
    # comment this out if you don't want the client to know your
    # classification
    set beresp.http.X-UA-Device = req.http.X-UA-Device;
}

# to keep any caches in the wild from serving wrong content to client #2
# behind them, we need to transform the Vary on the way out.
sub vcl_deliver {
    if ((req.http.X-UA-Device) && (resp.http.Vary)) {
        set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent");
    }
}
Example 2: Normalize the User-Agent string

Another way of signaling the device type is to override or normalize the User-Agent header sent to the backend.

For example

User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; nb-no; HTC Desire Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

becomes:

User-Agent: mobile-android

when seen by the backend.

This works if you don't need the original header for anything on the backend. A possible use for this is for CGI scripts where only a small set of predefined headers are (by default) available for the script.

VCL:

sub vcl_recv {
    # call some detection engine that set req.http.X-UA-Device
}

# override the header before it is sent to the backend
sub vcl_miss { if (req.http.X-UA-Device) { set bereq.http.User-Agent = req.http.X-UA-Device; } }
sub vcl_pass { if (req.http.X-UA-Device) { set bereq.http.User-Agent = req.http.X-UA-Device; } }

# standard Vary handling code from previous examples.
sub vcl_fetch {
    if (req.http.X-UA-Device) {
        if (!beresp.http.Vary) { # no Vary at all
            set beresp.http.Vary = "X-UA-Device";
        } elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary
            set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device";
        }
    }
    set beresp.http.X-UA-Device = req.http.X-UA-Device;
}
sub vcl_deliver {
    if ((req.http.X-UA-Device) && (resp.http.Vary)) {
        set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent");
    }
}
Example 3: Add the device class as a GET query parameter

If everything else fails, you can add the device type as a GET argument.

http://example.com/article/1234.html --> http://example.com/article/1234.html?devicetype=mobile-iphone

The client itself does not see this classification, only the backend request is changed.

VCL:

sub vcl_recv {
    # call some detection engine that set req.http.X-UA-Device
}

sub append_ua {
    if ((req.http.X-UA-Device) && (req.request == "GET")) {
        # if there are existing GET arguments;
        if (req.url ~ "\?") {
            set req.http.X-get-devicetype = "&devicetype=" + req.http.X-UA-Device;
        } else {
            set req.http.X-get-devicetype = "?devicetype=" + req.http.X-UA-Device;
        }
        set req.url = req.url + req.http.X-get-devicetype;
        unset req.http.X-get-devicetype;
    }
}

# do this after vcl_hash, so all Vary-ants can be purged in one go. (avoid ban()ing)
sub vcl_miss { call append_ua; }
sub vcl_pass { call append_ua; }

# Handle redirects, otherwise standard Vary handling code from previous
# examples.
sub vcl_fetch {
    if (req.http.X-UA-Device) {
        if (!beresp.http.Vary) { # no Vary at all
            set beresp.http.Vary = "X-UA-Device";
        } elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary
            set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device";
        }

        # if the backend returns a redirect (think missing trailing slash),
        # we will potentially show the extra address to the client. we
        # don't want that.  if the backend reorders the get parameters, you
        # may need to be smarter here. (? and & ordering)

        if (beresp.status == 301 || beresp.status == 302 || beresp.status == 303) {
            set beresp.http.location = regsub(beresp.http.location, "[?&]devicetype=.*$", "");
        }
    }
    set beresp.http.X-UA-Device = req.http.X-UA-Device;
}
sub vcl_deliver {
    if ((req.http.X-UA-Device) && (resp.http.Vary)) {
        set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent");
    }
}
Different backend for mobile clients

If you have a different backend that serves pages for mobile clients, or any special needs in VCL, you can use the X-UA-Device header like this:

backend mobile {
    .host = "10.0.0.1";
    .port = "80";
}

sub vcl_recv {
    # call some detection engine

    if (req.http.X-UA-Device ~ "^mobile" || req.http.X-UA-device ~ "^tablet") {
        set req.backend = mobile;
    }
}
sub vcl_hash {
    if (req.http.X-UA-Device) {
        hash_data(req.http.X-UA-Device);
    }
}
Redirecting mobile clients

If you want to redirect mobile clients you can use the following snippet.

VCL:

sub vcl_recv {
    # call some detection engine

    if (req.http.X-UA-Device ~ "^mobile" || req.http.X-UA-device ~ "^tablet") {
        error 750 "Moved Temporarily";
    }
}

sub vcl_error {
    if (obj.status == 750) {
        set obj.http.Location = "http://m.example.com" + req.url;
        set obj.status = 302;
        return(deliver);
    }
}

    
[3] 检测usb是不是连接pc
    来源: 互联网  发布时间: 2014-02-18
检测usb是否连接pc
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, ifilter);


int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                 status == BatteryManager.BATTERY_STATUS_FULL;


int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
 isCharging 和 usbCharge =true连接到pc

 


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
oracle iis7站长之家
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3