Example usage for android.content.res AssetManager open

List of usage examples for android.content.res AssetManager open

Introduction

In this page you can find the example usage for android.content.res AssetManager open.

Prototype

public @NonNull InputStream open(@NonNull String fileName) throws IOException 

Source Link

Document

Open an asset using ACCESS_STREAMING mode.

Usage

From source file:com.becapps.easydownloader.ShareActivity.java

private void downloadThumbnail(String fileUrl) {
    InputStream is = null;/*w w w. j a  v  a2 s . c o m*/
    URL myFileUrl = null;
    try {
        myFileUrl = new URL(fileUrl);
    } catch (MalformedURLException e) {
        try {
            myFileUrl = new URL("http://zevienin.com/easy320.png");
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        }
        e.printStackTrace();
    }
    try {
        HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
        conn.setDoInput(true);
        conn.connect();
        is = conn.getInputStream();

        img = BitmapFactory.decodeStream(is);
    } catch (IOException e) {
        InputStream assIs = null;
        AssetManager assMan = getAssets();
        try {
            assIs = assMan.open("placeholder.png");
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        img = BitmapFactory.decodeStream(assIs);
    }
}

From source file:org.deviceconnect.android.profile.restful.test.FailFileProfileTestCase.java

/**
 * ????./*  www  .  ja  va2 s .  c  om*/
 * 
 * @return ????
 */
private MultipartEntity getEntity() {
    AssetManager manager = getApplicationContext().getAssets();
    String name = "test.png";
    MultipartEntity entity = new MultipartEntity();
    try {
        entity.addPart(FileProfileConstants.PARAM_DATA, new InputStreamBody(manager.open(name), name));
    } catch (IOException e) {
        fail("Failed to obtain the file: " + e.getMessage());
    }
    return entity;
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????./*from  ww  w.j  av a 2s  .  c  o m*/
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional016() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????.//from  w  w  w  .  j  a  va  2s.c  o m
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&dir=auto
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional017() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_DIR + "=auto");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????.//ww  w.ja v  a 2s . c om
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&lang=jp-JP
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional018() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_LANG + "=jp-JP");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????.//  w ww  .ja  v a  2 s .c  o  m
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&body=test_body
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional020() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_BODY + "=test_body");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????.//  www.  ja  v a2  s  .com
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&tag=tag1,tag2,tag3
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional024() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TAG + "=tag1,tag2,tag3");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????./*from w ww .  j a v a 2  s.c  om*/
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&dir=auto&lang=jp-JP
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional019() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_DIR + "=auto");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_LANG + "=jp-JP");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????./*  w  w w .j  a  v a 2 s. c  om*/
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&dir=auto&body=test_body
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional021() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_DIR + "=auto");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_BODY + "=test_body");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????.// ww w . java  2s  .c  om
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&lang=jp-JP&body=test_body
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional022() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_LANG + "=jp-JP");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_BODY + "=test_body");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}