现在的位置: 首页 > 综合 > 正文

判断android设备是否支持硬解码

2018年05月01日 ⁄ 综合 ⁄ 共 1037字 ⁄ 字号 评论关闭

参考:http://blog.chinaunix.net/uid-686647-id-3979372.html

      //读取系统配置文件/system/etc/media_codecc.xml
      File file = new File("/system/etc/media_codecs.xml");
      InputStream in = null;
      try {
    	  in = new FileInputStream(file);
      } catch (Exception e) {
	    // TODO: handle exception
      }
      if(in == null)
      {
    	  android.util.Log.i("xp", "in == null");
      }else{
    	  android.util.Log.i("xp", "in != null");
      }
      
      
      boolean isHardcode = false;
      XmlPullParserFactory pullFactory;
		try {
			pullFactory = XmlPullParserFactory.newInstance();
			XmlPullParser xmlPullParser = pullFactory.newPullParser();
			xmlPullParser.setInput(in, "UTF-8");
			int eventType = xmlPullParser.getEventType();
			while (eventType != XmlPullParser.END_DOCUMENT) {
				String tagName = xmlPullParser.getName();
				switch (eventType) {
				case XmlPullParser.START_TAG:
					if ("MediaCodec".equals(tagName)) {
						String componentName = xmlPullParser.getAttributeValue(0);
						android.util.Log.i("xp", componentName);
						if(componentName.startsWith("OMX."))
						{
							if(!componentName.startsWith("OMX.google."))
							{
								isHardcode = true;
							}
						}
					}
				}
				eventType = xmlPullParser.next();
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		android.util.Log.i("xp", ""+isHardcode);

抱歉!评论已关闭.