瀏覽代碼

Modify User Agent string

masensio 10 年之前
父節點
當前提交
6d3bbd8bf3
共有 1 個文件被更改,包括 19 次插入1 次删除
  1. 19 1
      src/com/owncloud/android/MainApp.java

+ 19 - 1
src/com/owncloud/android/MainApp.java

@@ -22,6 +22,8 @@ package com.owncloud.android;
 
 
 import android.app.Application;
 import android.app.Application;
 import android.content.Context;
 import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
 
 
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
@@ -119,6 +121,22 @@ public class MainApp extends Application {
 
 
     // user agent
     // user agent
     public static String getUserAgent() {
     public static String getUserAgent() {
-        return getAppContext().getResources().getString(R.string.user_agent);
+        String appString = getAppContext().getResources().getString(R.string.user_agent);
+        String packageName = getAppContext().getPackageName();
+        PackageInfo pInfo = null;
+        try {
+            pInfo = getAppContext().getPackageManager().getPackageInfo(packageName, 0);
+        } catch (PackageManager.NameNotFoundException e) {
+
+        }
+        String version = "";
+        if (pInfo != null) {
+            version = pInfo.versionName;
+        }
+
+        // Mozilla/5.0 (Android) ownCloud /1.7.0
+        String userAgent = "Mozilla/5.0 "+ appString + "/" + version;
+
+        return userAgent;
     }
     }
 }
 }