public static String generateUserAgent ( Context context ) { StringBuilder ua = new StringBuilder ( "api-client/" ) ; ua . append ( VERSION ) ; String packageName = context . getApplicationContext ( ) . getPackageName ( ) ; ua . append ( " " ) ; ua . append ( packageName ) ; PackageInfo pi = null ; try { pi = context . getPackageManager ( ) . getPackageInfo ( packageName , 0 ) ; } catch ( PackageManager . NameNotFoundException e ) { e . printStackTrace ( ) ; } if ( pi != null ) { ua . append ( "/" ) ; ua . append ( pi . versionName ) ; ua . append ( "(" ) ; ua . append ( pi . versionCode ) ; ua . append ( ")" ) ; } ua . append ( " Android/" ) ; ua . append ( Build . VERSION . SDK_INT ) ; try { ua . append ( " " ) ; ua . append ( Build . PRODUCT ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } try { ua . append ( " " ) ; ua . append ( Build . MANUFACTURER ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } try { ua . append ( " " ) ; ua . append ( Build . MODEL ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return ua . toString ( ) ; }
build the default User - Agent