频道栏目
首页 > 程序开发 > 软件开发 > Java > 正文
简要说明Java 中.class文件的内部结构
2011-07-13 09:46:46           
收藏   我要投稿

3.0之前版本code:
Java代码 
private void setWifiProxyConfiguration(ProxyConfiguration proxyconfiguration) { 
 
    // if isnot SSID ,return out 
    if (proxyconfiguration.getProxyScope() != ProxyConfiguration.ProxyScope.SSID){ 
        return; 
    } 
    mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); 
 
    // add a WifiConfig 
    List<WifiConfiguration> wifiConfiguredNetworks = mWifiManager 
            .getConfiguredNetworks(); 
 
    for (final WifiConfiguration w : wifiConfiguredNetworks){ 
        Log.i(TAG, ""+w.SSID+":"+proxyconfiguration.getNetworkId()); 
         
        if (w.SSID.equals("""+proxyconfiguration.getNetworkId()+""")){ 
             
            mLinkProperties.clear(); 
            Log.i(TAG, "w.SSID.equals(proxyconfiguration.getNetworkId()):" 
                    + wifiConfiguredNetworks.indexOf(w)); 
             
            mWifiConfiguration = wifiConfiguredNetworks.get(wifiConfiguredNetworks.indexOf(w)); 
            ProxyProperties proxyproperties = new ProxyProperties( 
                    proxyconfiguration.getProxyURL(), 
                    proxyconfiguration.getProxyPort(), 
                    proxyconfiguration.getmUrlExclusionList()); 
            mLinkProperties.setHttpProxy(proxyproperties); 
            mWifiConfiguration.linkProperties = new LinkProperties(mLinkProperties); 
            mWifiConfiguration.proxySettings = ProxySettings.STATIC; 
             
            Log.i(TAG, "mWifiConfiguration.linkProperties.setHttpProxy(proxyproperties);"+ mWifiConfiguration); 
             
            mWifiManager.saveNetwork(mWifiConfiguration); 
        } 
    } 


附3.0 Demo

3.1时源码有所改动加入了async code为:

Java代码 
private class WifiServiceHandler extends Handler { 
    @Override 
    public void handleMessage(Message msg) { 
        switch (msg.what) { 
            case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: 
                if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) { 
                    Log.e(TAG, "Success to establish AsyncChannel connection"); 
                    //AsyncChannel in msg.obj 
                } else { 
                    //AsyncChannel set up failure, ignore 
                    Log.e(TAG, "Failed to establish AsyncChannel connection"); 
                } 
                break; 
            default: 
                //Ignore 
                break; 
        } 
    } 
 
    WifiServiceHandler(Looper looper){ 
        super(looper); 
    } 

    // Standard priority background threads. 
       final HandlerThread mHandlerThread = new HandlerThread("DivideService",Process.THREAD_PRIORITY_BACKGROUND); 
       final WifiServiceHandler mHandler; 
    // run a message loop for a thread. 
    // Threads do not have a message loop associated with them by default; so create one 
    mHandlerThread.start(); 
    mHandler = new WifiServiceHandler(mHandlerThread.getLooper()); 
public void setProxyConfiguration(ProxyConfiguration[] proxyConfigurations) { 
    if (mContext.checkCallingOrSelfPermission(ENTERPROID_PERMISSION) != PackageManager.PERMISSION_GRANTED) { 
        if(DEBUG_LOADERS) Log.e(TAG, "setProxyConfiguration() no permission"); 
        return; 
    } 
    if (proxyConfigurations != null) { 
        if(DEBUG_LOADERS) Log.d(TAG, "setProxyConfiguration()"); 
        mProxyConfgs = new ProxyConfiguration[proxyConfigurations.length]; 
        for (int i = 0; i < mProxyConfgs.length; i++) { 
            ProxyConfiguration pc = proxyConfigurations[i]; 
            // TODO: Invoke the framework api existed in the Android 3.0 
            switch (pc.getProxyScope()) { 
            case SSID: { 
                setWifiProxyConfiguration(pc); 
            } 
                break; 
            default: 
                break; 
            } 
        } 
    } else { 
        mProxyConfgs = null; 
    } 

 
private void setWifiProxyConfiguration(ProxyConfiguration[] proxyconfiguration) { 
 
    for (ProxyConfiguration pcf : proxyconfiguration) { 
        setWifiProxyConfiguration(pcf); 
    } 

private void setWifiProxyConfiguration(ProxyConfiguration proxyconfiguration) { 
    if(DEBUG_LOADERS) Log.d(TAG, "setWifiProxyConfiguration()"); 
    // if isnot SSID ,return out 
    if (proxyconfiguration.getProxyScope() != ProxyConfiguration.ProxyScope.SSID) { 
        if(DEBUG_LOADERS) Log.d(TAG, "proxyconfiguration.getProxyScope() != ProxyConfiguration.ProxyScope.SSID"); 
        return; 
    } 
    WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); 
    wm.asyncConnect(mContext, mHandler);// DELL, deanye@cienet.com.cn, 5/16/2011, ENTERPROID-111 
 
    // add a WifiConfig 
    List<WifiConfiguration> wifiConfiguredNetworks = wm.getConfiguredNetworks(); 
 
    for (final WifiConfiguration w : wifiConfiguredNetworks) { 
        if(DEBUG_LOADERS) Log.i(TAG, "" + w.SSID + ":" + proxyconfiguration.getNetworkId()); 
 
        if (w.SSID.equals(""" + proxyconfiguration.getNetworkId() + """)) { 
            if(DEBUG_LOADERS) Log.i(TAG, "w.SSID.equals(proxyconfiguration.getNetworkId()):" 
                    + wifiConfiguredNetworks.indexOf(w)); 
 
            WifiConfiguration wc = wifiConfiguredNetworks 
                    .get(wifiConfiguredNetworks.indexOf(w)); 
            ProxyProperties proxyproperties = new ProxyProperties(proxyconfiguration 
                    .getProxyURL(), proxyconfiguration.getProxyPort(), proxyconfiguration 
                    .getUrlExclusionList()); 
 
            LinkProperties linkProperties = new LinkProperties(); 
            linkProperties.clear(); 
 
            linkProperties.setHttpProxy(proxyproperties); 
 
            wc.linkProperties = new LinkProperties(linkProperties); 
            wc.proxySettings = ProxySettings.STATIC; 
 
            if(DEBUG_LOADERS) Log.i(TAG, "mWifiConfiguration.linkProperties.setHttpProxy(proxyproperties);" + wc); 
 
            wm.saveNetwork(wc); 
        } 
    } 


静默安装的code:

Java代码 
public void installDividePackage(Uri uri, String packageName) { 
    if (mContext.checkCallingOrSelfPermission(ENTERPROID_PERMISSION) != PackageManager.PERMISSION_GRANTED) { 
        Log.e(TAG, "installDividePackage() no permission"); 
        return; 
    } 
    PackageUriPair packageUriPair = new PackageUriPair(); 
    packageUriPair.packageName = packageName; 
    packageUriPair.uri = uri; 
    Message msg = Message.obtain(); 
    msg.obj = packageUriPair; 
    mInstallDivideHandler.sendMessage(msg); 

 
 
private class PackageUriPair { 
    public String packageName; 
 
    public Uri uri; 

 
private class DividePackageInstallObserver extends IPackageInstallObserver.Stub { 
    public void packageInstalled(String packageName, int returnCode) { 
        if (returnCode == PackageManager.INSTALL_SUCCEEDED) { 
            // Start Divide Activation again 
            Intent intent = new Intent(); 
            intent.setComponent(new ComponentName(ETP_CORE_PKG_NAME, ETP_CORE_ACTIVATY_NAME)); 
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
            mContext.startActivity(intent); 
        } else if (returnCode == PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE) { 
            Log.i(TAG, "no enough storage"); 
        } else { 
            Log.i(TAG, "unexpected error"); 
        } 
    } 

 
private Handler mInstallDivideHandler = new Handler() { 
    public void handleMessage(Message msg) { 
        PackageUriPair packageUriPair = (PackageUriPair) msg.obj; 
        String packageName = packageUriPair.packageName; 
        Uri uri = packageUriPair.uri; 
        PackageManager pm = mContext.getPackageManager(); 
        pm.installPackage(uri, new DividePackageInstallObserver(), 
                PackageManager.INSTALL_REPLACE_EXISTING, packageName); 
    } 
}; 

点击复制链接 与好友分享!回本站首页
相关TAG标签 简要 结构 文件
上一篇:Java中LinkedList遍历速度可比ArrayList快
下一篇:导出Excel文件
相关文章
图文推荐
点击排行

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站