我在某些设备上遇到问题,例如某些android盒子或华为手机 如果用户使用数据包监视器应用程序,那么我需要保护我的应用程序,如果用户在设备上启用了vpn而不请求jsonparse,我要做的就是 但是即使vpn处于非活动状态,有些设备也无法运行jsonparse。
这是我的代码
public static boolean isVpnConnectionActive() {
List<String> networks = new ArrayList<>();
try {
for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
if (networkInterface.isUp()) {
networks.add(networkInterface.getName());
}if (networkInterface.getName().contains("tun0")|| networkInterface.getName().contains("ppp0")) {
System.exit(1);
}
}
} catch (Exception ignored) {
}
return networks.contains("tun0");
}
我在启动和创建时请求jsonParse,以避免用户启动我的应用程序后激活VPN
@Override
protected void onStart() {
super.onStart();
if (isVpnConnectionActive()) {
}else { jsonParse();}}
我以此方式请求json解析
private void jsonParse() {
final String url = "http://example.dns.net/json.php";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("employees");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject employee = jsonArray.getJSONObject(i);
String Urlx = employee.getString("urlx");
String Urlc = employee.getString("urlc");
String Urlb = employee.getString("urlb");
String TextBar = employee.getString("TextBar");
DFG_1 = Urlx;
DFG_2 = Urlc;
DFG_3 = Urlb;
Text_Bar = TextBar;
text2.setText(TextBar);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mQueue.add(request);
}
为什么android pie和某些设备无法通过这种方式工作?
答案 0 :(得分:0)
您是否有理由不使用<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5433/logistica</property>
<property name="hibernate.connection.username">testUser</property>
<property name="hibernate.connection.password">pass</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL9Dialect</property>
<mapping class="com.log.iei.logistica.data.entities.ClientEntity" />
<mapping class="com.log.iei.logistica.data.entities.ContractEntity" />
<mapping class="com.log.iei.logistica.data.entities.ContainerEntity" />
<mapping class="com.log.iei.logistica.data.entities.VehicleEntity" />
<mapping class="com.log.iei.logistica.data.entities.TransactionEntity" />
</session-factory>
</hibernate-configuration>
,请参阅https://developer.android.com/reference/android/net/NetworkCapabilities#hasTransport(int)?
使用此功能,您可以使用org.hibernate.HibernateException: Error accessing stax stream
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:107)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:165)
at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at org.hibernate.cfg.Configuration.configure(Configuration.java:244)
at com.log.iei.logistica.managers.HibernateSessionManager.getSessionFactory(HibernateSessionManager.java:18)
at com.log.iei.logistica.data.controllers.Services.GenericDao.getSession(GenericDao.java:78)
at com.log.iei.logistica.data.controllers.Services.GenericDao.findAll(GenericDao.java:58)
at com.log.iei.logistica.data.controllers.Services.VehicleService.findAll(VehicleService.java:50)
at com.log.iei.logistica.gui.cargo.CargoPage.init(CargoPage.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
.........
.......
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,2]
Message: The markup declarations contained or pointed to by the document type declaration must be well-formed.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:604)
at com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl.java:276)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:103)
... 36 more
检查“网络是否使用VPN传输”。