当前位置: 首页 > news >正文

范湖网站建设哪家便宜天津网络优化推广公司

范湖网站建设哪家便宜,天津网络优化推广公司,网站企业优化,网站建设前规划客户要在app中自由切换动态,静态方法,直接把系统jar-api给他搞了半天搞不定,只有在系统里给他实现一个接口,方法如下: Index: packages/apps/Settings/AndroidManifest.xml--- packages/apps/Settings/AndroidManifes…

客户要在app中自由切换动态,静态方法,直接把系统jar-api给他搞了半天搞不定,只有在系统里给他实现一个接口,方法如下:

Index: packages/apps/Settings/AndroidManifest.xml
===================================================================
--- packages/apps/Settings/AndroidManifest.xml	(revision 868)
+++ packages/apps/Settings/AndroidManifest.xml	(revision 869)
@@ -5,7 +5,7 @@android:sharedUserId="android.uid.system"><original-package android:name="com.android.settings" />
-
+     <uses-permission android:name="android.net.action.ETHERNET_IP_CHANGED"/><uses-permission android:name="android.permission.REQUEST_NETWORK_SCORES" /><uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" /><uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
@@ -3504,6 +3504,14 @@</intent-filter>/></receiver>+	<receiver android:name=".ethernet.EtherentBoardcastReceiver"
+			 android:enabled="true"
+			 android:exported="true">
+             <intent-filter android:priority="1000">
+                <action android:name="android.net.action.ETHERNET_IP_CHANGED" />
+            </intent-filter>
+        </receiver>
+<!-- This is the longest AndroidManifest.xml ever. --></application></manifest>
Index: packages/apps/Settings/src/com/android/settings/ethernet/EtherentBoardcastReceive.java
===================================================================
--- packages/apps/Settings/src/com/android/settings/ethernet/EtherentBoardcastReceive.java     (nonexistent)
+++ packages/apps/Settings/src/com/android/settings/ethernet/EtherentBoardcastReceive.java     (revision 869)
@@ -0,0 +1,220 @@
+package com.android.settings.ethernet;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.admin.DevicePolicyManager;
+import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.os.SystemProperties;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.PreferenceScreen;
+import android.provider.SearchIndexableResource;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+import android.util.Log;
+import android.content.Intent;
+
+import androidx.preference.SwitchPreference;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.File;
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import java.util.regex.Pattern;
+import java.lang.Integer;
+import java.net.InetAddress;
+import java.net.Inet4Address;
+import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.Preference.OnPreferenceClickListener;
+
+import com.android.settings.SettingsPreferenceFragment.SettingsDialogFragment;
+
+
+/*for 5.0*/
+import android.net.EthernetManager;
+import android.net.IpConfiguration;
+import android.net.IpConfiguration.IpAssignment;
+import android.net.IpConfiguration.ProxySettings;
+import android.net.wifi.SupplicantState;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.net.StaticIpConfiguration;
+import android.net.NetworkUtils;
+import android.net.LinkAddress;
+import android.net.LinkProperties;
+import android.widget.Toast;
+//import android.preference.ListPreference;
+//import com.android.internal.logging.MetricsProto.MetricsEvent;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+
+
+import com.android.settings.ethernet.ethernet_static_ip_dialog;
+public class EtherentBoardcastReceiver extends BroadcastReceiver  {
+	private static final String TAG = "EtherentBoardcastReceiver";
+	 
+	private  static String mEthMode = null
+    private  static String mEthIpAddress = null;
+    private  static String mEthNetmask = null;
+    private  static String mEthGateway = null;
+    private  static String mEthdns1 = null;
+    private  static String mEthdns2 = null;
+
+    private final static String nullIpInfo = "0.0.0.0";
+	private String mIfaceName;
+	 @Override
+    public void onReceive(Context context, Intent intent) {
+
+			IpConfiguration mIpConfiguration;
+			StaticIpConfiguration mStaticIpConfiguration;
+			String action = intent.getAction();
+		    Log.i(TAG, "receive a new action : " + action);
+			
+			EthernetManager mEthManager = (EthernetManager) context.getSystemService(Context.ETHERNET_SERVICE);
+			if(mEthManager == null){
+				Log.i(TAG, "fail to getSystemService :  "+Context.ETHERNET_SERVICE);
+			}
+
+		  mStaticIpConfiguration =new StaticIpConfiguration();
+		  getNetConfigFromIntent(intent);
+		 /*
+		  * get ip address, netmask,dns ,gw etc.
+		  */
+		String[] ifaces = mEthManager.getAvailableInterfaces();
+        if (ifaces.length > 0) {
+            mIfaceName = ifaces[0];//"eth0";
+        }
+        if (null == mIfaceName) {
+            Log.e(TAG, "get ethernet ifaceName failed");
+            
+        }
+
+
+		if (mEthMode  == null ||mEthMode.equals("static"))
+		{
+			 Inet4Address inetAddr = getIPv4Address(this.mEthIpAddress);
+			int prefixLength = maskStr2InetMask(this.mEthNetmask); 
+			InetAddress gatewayAddr = getIPv4Address(this.mEthGateway); 
+			InetAddress dnsAddr1 = getIPv4Address(this.mEthdns1);
+			InetAddress dnsAddr2 = getIPv4Address(this.mEthdns2);
+			if(inetAddr ==null || gatewayAddr == null || prefixLength <= 0  ){
+				  Log.e(TAG,"ip,mask or dnsAddr is wrong");
+				  return ;
+			}
+			if (inetAddr.getAddress().toString().isEmpty() || prefixLength ==0 || gatewayAddr.toString().isEmpty()
+			  ) {
+				   Log.e(TAG,"ip,mask or dnsAddr is wrong");
+				  return ;
+			}
+			  
+			mStaticIpConfiguration.ipAddress = new LinkAddress(inetAddr, prefixLength);
+			mStaticIpConfiguration.gateway=gatewayAddr;
+			if(dnsAddr1 != null && !dnsAddr1.toString().isEmpty())
+				mStaticIpConfiguration.dnsServers.add(dnsAddr1);
+			if(dnsAddr2 != null && !dnsAddr2.toString().isEmpty())
+				mStaticIpConfiguration.dnsServers.add(dnsAddr2);
+		
+			mIpConfiguration=new IpConfiguration(IpAssignment.STATIC, ProxySettings.NONE,mStaticIpConfiguration,null);  
+			mEthManager.setConfiguration(mIfaceName, mIpConfiguration); 
+		}else{
+			mEthManager.setConfiguration(mIfaceName, new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE,null,null));
+		}
+       
+		//
+		
+    }
+	
+	private void getNetConfigFromIntent(Intent intent){
+		Bundle bundle = intent.getExtras();
+        if (bundle.getString("netMode") != null)
+			this.mEthMode = bundle.getString("netMode");
+		if (bundle.getString("ipaddr") != null)
+			this.mEthIpAddress = bundle.getString("ipaddr");
+		if (bundle.getString("netMask")!= null)
+			this.mEthNetmask = bundle.getString("netMask");
+		if (bundle.getString("gateway")!= null)
+			this.mEthGateway = bundle.getString("gateway");
+		if (bundle.getString("dns1") != null)
+			this.mEthdns1 = bundle.getString("dns1");
+		if (bundle.getString("dns2") != null)
+			this.mEthdns2 = bundle.getString("dns2");
+	}
+	 private Inet4Address getIPv4Address(String text) {
+        try {
+            return (Inet4Address) NetworkUtils.numericToInetAddress(text);
+        } catch (IllegalArgumentException|ClassCastException e) {
+            return null;
+        }
+    }
+
+	 /*
+     * convert subMask string to prefix length
+     */
+    private int maskStr2InetMask(String maskStr) {
+    	StringBuffer sb ;
+    	String str;
+    	int inetmask = 0; 
+    	int count = 0;
+    	/*
+    	 * check the subMask format
+    	 */
+      	Pattern pattern = Pattern.compile("(^((\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])$)|^(\\d|[1-2]\\d|3[0-2])$");
+    	if (pattern.matcher(maskStr).matches() == false) {
+    		Log.e(TAG,"subMask is error");
+    		return 0;
+    	}
+    	
+    	String[] ipSegment = maskStr.split("\\.");
+    	for(int n =0; n<ipSegment.length;n++) {
+    		sb = new StringBuffer(Integer.toBinaryString(Integer.parseInt(ipSegment[n])));
+    		str = sb.reverse().toString();
+    		count=0;
+    		for(int i=0; i<str.length();i++) {
+    			i=str.indexOf("1",i);
+    			if(i==-1)  
+    				break;
+    			count++;
+    		}
+    		inetmask+=count;
+    	}
+    	return inetmask;
+    }
+
+
+
+}
+
http://www.shuangfujiaoyu.com/news/30975.html

相关文章:

  • 公司网站建设怎么选择新闻稿件代发平台
  • 做爰视频网站今天发生的重大新闻5条
  • 服装公司介绍模板seo的作用
  • wordpress金馆长插件seo关键词优化公司哪家好
  • 总局网站建设管理规范网络营销工程师
  • 公司转让需要交哪些税合肥关键词排名优化
  • 官方制作网站百度大数据平台
  • 云服务器可以做多个网站性价比高的seo网站优化
  • 上海平台网站制作公司哪家好在线查询网站收录
  • 兼职网站平台有哪些百度客服怎么转人工电话
  • 网页设计企业网站设计的功能海外网站cdn加速
  • 如何看网站是用什么程序做的企业站seo案例分析
  • 微网站的建设模板有哪些最新资讯热点
  • 网站建站主题互联网推广销售
  • 山西建站推广东莞网络营销公司
  • 网站建设开票规格明细单位怎么写江苏网站开发
  • 用ps做美食网站网络服务网络推广
  • 私人让做彩票网站吗自己怎么优化我网站关键词
  • 网站上传图片加水印建站系统哪个好
  • 做网站的怎么办理营业执照关键词排名优化是什么意思
  • 秦皇岛哪家公司网站建设好百度推广客户端电脑版
  • win7 iis设置网站首页百度人工服务24小时电话
  • 庐江魅力网做网站号码网站seo诊断分析报告
  • 简历模板网站免费英文外链seo兼职
  • 塘厦东莞网站建设谷歌seo什么意思
  • 哪个网站做logo好乔拓云智能建站
  • 德州做网站的公司产品如何在网上推广
  • 怎么做最火的视频网站软文广告经典案例100字
  • 做网站的流程图营销策略ppt
  • 购物网站开发文献综述免费seo诊断