java - 在 Core Java 中识别 Android 设备

标签 java android


我正在核心 java 中做一个项目,它将一些处理过的文件推送到 android 设备。所以我需要的是我只需要识别连接到我的计算机的 android 设备并将一些文件推送到内部存储。 假设设备已连接并且已在设备中授予访问内部存储的权限。

最佳答案

//**************************
// The UAgentInfo class encapsulates information about
//   a browser's connection to your web site. 
//   The object's detection methods return booleans: true or false.
public class UAgentInfo
{
   //Stores some info about the browser and device.
   private String userAgent;

   //Stores info about what content formats the browser can display.
   private String httpAccept; 

   // A long list of strings which provide clues 
   //   about devices and capabilities.
   public static final String deviceIphone = "iphone";

   // [ SNIP! Other variables snipped out ] 


   //**************************
   //The constructor. Initializes several default variables.
   public UAgentInfo(String userAgent, String httpAccept) {
        if (userAgent != null) {
            this.userAgent = userAgent.toLowerCase();
        }
        if (httpAccept != null) {
            this.httpAccept = httpAccept.toLowerCase();
        }
    }

   //**************************
   //Returns the contents of the User Agent value, in lower case.
   public String getUserAgent()
   { 
       return userAgent;
   }

   //**************************
   // Detects if the current device is an iPhone.
   public boolean detectIphone()
   {
        //The iPod touch says it's an iPhone! So let's disambiguate.
        if (userAgent.indexOf(deviceIphone) != -1 && !detectIpod()) {
            return true;
        }
        return false;
   }

   // [ SNIP! Other functions snipped out ] 

}

关于java - 在 Core Java 中识别 Android 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55528454/

相关文章:

java - HTML 代码中元素的 XPath

java - 如何用接口(interface)序列化一个类?

java - 获取 javax.xml.stream.XMLStreamReader 读入的字节数

android - 如何在改造中使用 HashMap 发布数据?

java - 复选框值为 true 但勾号未显示 - Android/Java

java - 使用 Java JDBC 查询满足 SQLite 约束

android - 将 Snackbar 附加到 RecyclerView

android - 如何为 android 21 api 及更高版本创建资源文件夹?

android - 当我需要使用 Activity 上下文时如何避免静态上下文引用?

java - 如何在 Tomcat 主机名上设置 IP 地址?