在Core Java中识别Android设备

时间:2019-04-05 04:54:11

标签: java android


我正在核心Java中执行一个项目,该项目会将一些已处理的文件推送到android设备。因此,我需要的是仅识别连接到计算机的android设备并将某些文件推送到内部存储中。 假定该设备已经连接,并且已经在该设备中授予了访问内部存储的权限。

1 个答案:

答案 0 :(得分:0)

//**************************
// 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 ] 

}