处理传的地址有空格以及调试的使用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. 在一个服务中调试 有时候断电不能固定

android.os.Debug.waitForDebugger();
public class SoftKeyboard extends InputMethodService 
        implements KeyboardView.OnKeyboardActionListener {
        
    @Override
        public void onConfigurationChanged(Configuration newConfig) {
        Log.d("SoftKeyboard", "onConfigurationChanged()");
 
        /* now let's wait until the debugger attaches */
        android.os.Debug.waitForDebugger();
        
        super.onConfigurationChanged(newConfig);
        
        /* do something useful... */
                
        }
 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值