wang_peng1 发表于 2013-1-28 18:59:33

处理传的地址有空格以及调试的使用debug

通常我们在传递一个地址时如果有空格
String myString = "http://myhost.com/media/mp3s/9/Agenda of swine - 13. Persecution Ascension_ leave nothing standing.mp3"; 
URI myUri = new URI(myString); 
结果会抛出异常
java.net.URISyntaxException: Illegal character in path at index X 
 
其实很简单 只要把空格转换成别的字符就可以了
这里加设有空格的只在最后一个\ 后面
URI uri = new URI(string.replace(' ', '+')); 
或者
URI uri = new URI(string.replace(" ", "%20")); 
然后
int pos = string.lastIndexOf('/') + 1; 
URI uri = new URI(string.substring(0, pos) + URLEncoder.encode(string.substring(pos), "UTF-8")); 

2.
<application android:icon="@drawable/icon"  
    android:name=".SomeApp" 
    android:label="@string/app_name" android:debuggable="true"> 
if(Log.isLoggable(TAG, Log.DEBUG)) { 
    Log.d(TAG, "some log statement"); 
}
 
3. 在一个服务中调试 有时候断电不能固定
<div class="de1">android.os.Debug.waitForDebugger();
页: [1]
查看完整版本: 处理传的地址有空格以及调试的使用debug