Example usage for android.os Build MODEL

List of usage examples for android.os Build MODEL

Introduction

In this page you can find the example usage for android.os Build MODEL.

Prototype

String MODEL

To view the source code for android.os Build MODEL.

Click Source Link

Document

The end-user-visible name for the end product.

Usage

From source file:me.willowcheng.makerthings.ui.OpenHABMainActivity.java

private void gcmRegisterBackground() {
    // We need settings
    if (mSettings == null)
        return;/*from  w ww  .  j  av a  2s.  c om*/
    // We need remote URL, username and password, without them we can't connect to my.openHAB
    String remoteUrl = mSettings.getString(Constants.PREFERENCE_ALTURL, null);
    if (TextUtils.isEmpty(remoteUrl) || TextUtils.isEmpty(openHABUsername)
            || TextUtils.isEmpty(openHABPassword))
        return;
    // We need remote URL to be my.oh
    if (!remoteUrl.toLowerCase().startsWith("https://my.openhab.org"))
        return;
    mIsMyOpenHAB = true;
    // Finally, all sanity is done
    Crittercism.setUsername(openHABUsername);
    if (mGcm == null)
        mGcm = GoogleCloudMessaging.getInstance(getApplicationContext());
    new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(Void... params) {
            try {
                mRegId = mGcm.register(GCM_SENDER_ID);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        String deviceModel = null;
                        try {
                            deviceModel = URLEncoder.encode(Build.MODEL, "UTF-8");
                            String deviceId = Settings.Secure.getString(getContentResolver(),
                                    Settings.Secure.ANDROID_ID);
                            String regUrl = "https://my.openhab.org/addAndroidRegistration?deviceId=" + deviceId
                                    + "&deviceModel=" + deviceModel + "&regId=" + mRegId;
                            mAsyncHttpClient.get(getApplicationContext(), regUrl,
                                    new AsyncHttpResponseHandler() {
                                        @Override
                                        public void onFailure(int statusCode, Header[] headers,
                                                byte[] responseBody, Throwable error) {
                                            Log.e(TAG, "GCM reg id error: " + error.getMessage());
                                            if (responseBody != null)
                                                Log.e(TAG, "Error response = " + new String(responseBody));
                                        }

                                        @Override
                                        public void onSuccess(int statusCode, Header[] headers,
                                                byte[] responseBody) {
                                            Log.d(TAG, "GCM reg id success");
                                        }
                                    });
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }

                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
                Log.e(TAG, e.getMessage());
            }
            return mRegId;
        }

        @Override
        protected void onPostExecute(String regId) {
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
}

From source file:org.chromium.android_webview.test.AwSettingsTest.java

@SmallTest
@Feature({ "AndroidWebView", "Preferences" })
public void testUserAgentStringDefault() throws Throwable {
    final TestAwContentsClient contentClient = new TestAwContentsClient();
    final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentClient);
    final AwContents awContents = testContainerView.getAwContents();
    AwSettings settings = getAwSettingsOnUiThread(awContents);
    final String actualUserAgentString = settings.getUserAgentString();
    assertEquals(actualUserAgentString, AwSettings.getDefaultUserAgent());
    final String patternString = "Mozilla/5\\.0 \\(Linux;( U;)? Android ([^;]+);( (\\w+)-(\\w+);)?"
            + "\\s?(.*)\\sBuild/(.+)\\) AppleWebKit/(\\d+)\\.(\\d+) \\(KHTML, like Gecko\\) "
            + "Version/\\d+\\.\\d Chrome/\\d+\\.\\d+\\.\\d+\\.\\d+" + "( Mobile)? Safari/(\\d+)\\.(\\d+)";
    final Pattern userAgentExpr = Pattern.compile(patternString);
    Matcher patternMatcher = userAgentExpr.matcher(actualUserAgentString);
    assertTrue(/*from ww w.ja  v a 2s.c  o m*/
            String.format("User agent string did not match expected pattern. %nExpected "
                    + "pattern:%n%s%nActual:%n%s", patternString, actualUserAgentString),
            patternMatcher.find());
    // No country-language code token.
    assertEquals(null, patternMatcher.group(3));
    if ("REL".equals(Build.VERSION.CODENAME)) {
        // Model is only added in release builds
        assertEquals(Build.MODEL, patternMatcher.group(6));
        // Release version is valid only in release builds
        assertEquals(Build.VERSION.RELEASE, patternMatcher.group(2));
    }
    assertEquals(Build.ID, patternMatcher.group(7));
}

From source file:org.anurag.file.quest.FileQuestHD.java

/**
 * this function finds the device information and sets in drawer menu....
 *//* w  ww  .  j  a va 2s.  c om*/
private void init_with_device_id() {
    TextView devId = (TextView) findViewById(R.id.dev_id);
    String dev = Build.MODEL;
    String man = Build.MANUFACTURER;
    if (dev.length() == 0 || dev == null)
        dev = getString(R.string.unknown);
    else {
        if (!dev.contains(man))
            dev = man + " " + dev;
        char a = dev.charAt(0);
        if (!Character.isUpperCase(a)) {
            dev = Character.toUpperCase(a) + dev.substring(1);
        }
    }
    devId.setText(dev);
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static String generateBrowserUserAgent() {
    return String.format(UA_TEMPLATE, Build.VERSION.RELEASE, Build.MODEL, Build.ID);
}

From source file:github.why168.swipeback.view.SwipeBackLayout.java

/**
 * ??// ww  w.j  a  va2  s. c om
 *
 * @param activity
 * @return
 */
public boolean checkDeviceHasNavigationBar(Activity activity) {
    boolean hasNavigationBar = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        if (TextUtils.equals("Nexus 4".toLowerCase().trim(), Build.MODEL.toLowerCase().trim())) {
            hasNavigationBar = false;
        } else {
            hasNavigationBar = newCheckDeviceHasNavigationBar(activity);
        }
    } else {
        hasNavigationBar = oldCheckDeviceHasNavigationBar(activity);
    }
    return hasNavigationBar;
}

From source file:com.jaredrummler.android.device.DeviceName.java

/**
 * Get the {@link DeviceInfo} for the current device. Do not run on the UI thread, as this may
 * download JSON to retrieve the {@link DeviceInfo}. JSON is only downloaded once and then
 * stored to {@link SharedPreferences}.//from  w  ww .j  av a 2  s .co  m
 *
 * @param context
 *     the application context.
 * @return {@link DeviceInfo} for the current device.
 */
public static DeviceInfo getDeviceInfo(Context context) {
    return getDeviceInfo(context.getApplicationContext(), Build.DEVICE, Build.MODEL);
}

From source file:com.jaredrummler.android.device.DeviceName.java

/** Get the device name from the generated JSON files created from Google's device list. */
private static DeviceInfo getDeviceInfo(Context context, String codename, String model) {
    SharedPreferences prefs = context.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
    String key = String.format("%s:%s", codename, model);
    String savedJson = prefs.getString(key, null);
    if (savedJson != null) {
        try {//w w  w.j  a v a  2s.com
            return new DeviceInfo(new JSONObject(savedJson));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    // check if we have an internet connection
    int ret = context.checkCallingOrSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE);
    boolean isConnectedToNetwork = false;
    if (ret == PackageManager.PERMISSION_GRANTED) {
        ConnectivityManager connMgr = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected()) {
            isConnectedToNetwork = true;
        }
    } else {
        // assume we are connected.
        isConnectedToNetwork = true;
    }

    if (isConnectedToNetwork) {
        try {
            String url = String.format(DEVICE_JSON_URL, codename.toLowerCase(Locale.ENGLISH));
            String jsonString = downloadJson(url);
            JSONArray jsonArray = new JSONArray(jsonString);
            for (int i = 0, len = jsonArray.length(); i < len; i++) {
                JSONObject json = jsonArray.getJSONObject(i);
                DeviceInfo info = new DeviceInfo(json);
                if ((codename.equalsIgnoreCase(info.codename) && model == null)
                        || codename.equalsIgnoreCase(info.codename) && model.equalsIgnoreCase(info.model)) {
                    // Save to SharedPreferences so we don't need to make another request.
                    SharedPreferences.Editor editor = prefs.edit();
                    editor.putString(key, json.toString());
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
                        editor.apply();
                    } else {
                        editor.commit();
                    }
                    return info;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    if (codename.equals(Build.DEVICE) && model.equals(Build.MODEL)) {
        return new DeviceInfo(Build.MANUFACTURER, getDeviceName(), codename, model); // current device
    }

    return new DeviceInfo(null, null, codename, model); // unknown device
}

From source file:com.grazerss.EntryManager.java

public boolean shouldHWZoomControlsBeDisabled() {

    if (DEVICE_MODEL_DROID_INCREDIBLE.equals(Build.MODEL) && (SDKVersionUtil.getVersion() < 8)) {
        return true;
    }/*from   w w  w  .  j a  v  a 2s .  c  om*/

    if (DEVICE_MODEL_EVO.equals(Build.MODEL) && (SDKVersionUtil.getVersion() < 8)) {
        return true;
    }

    if (DEVICE_MODEL_DESIRE.equals(Build.MODEL) && (SDKVersionUtil.getVersion() < 8)) {
        return true;
    }

    return false;
}

From source file:com.grazerss.EntryManager.java

public boolean shouldSyncInProgressNotificationBeDisabled() {

    if (true) {/*  w  w  w .  j av  a 2s  .  c om*/
        return false;
    }
    if (DEVICE_MODEL_DROID_INCREDIBLE.equals(Build.MODEL) && (SDKVersionUtil.getVersion() < 8)) {
        return true;
    }

    if (DEVICE_MODEL_EVO.equals(Build.MODEL) && (SDKVersionUtil.getVersion() < 8)) {
        return true;
    }

    if (DEVICE_MODEL_DESIRE.equals(Build.MODEL) && (SDKVersionUtil.getVersion() < 8)) {
        return true;
    }

    return false;

}

From source file:com.newsrob.EntryManager.java

public int getMaxArticlesInArticleList() {
    if (DEVICE_MODEL_ARCHOS_7.equals(Build.MODEL) && SDKVersionUtil.getVersion() < 4
            || "HTC Gratia A6380".equals(Build.MODEL))
        return 200;
    return MAX_ARTICLES_IN_ARTICLE_LIST;
}