Search in sources :

Example 11 with LaunchSession

use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.

the class NetcastTVService method launchApplication.

private void launchApplication(final String appName, final String auid, final String contentId, final Launcher.AppLaunchListener listener) {
    JSONObject jsonObj = new JSONObject();
    try {
        jsonObj.put("id", auid);
        jsonObj.put("title", appName);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            LaunchSession launchSession = LaunchSession.launchSessionForAppId(auid);
            launchSession.setAppName(appName);
            launchSession.setService(NetcastTVService.this);
            launchSession.setSessionType(LaunchSessionType.App);
            Util.postSuccess(listener, launchSession);
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    String requestURL = getUDAPRequestURL(UDAP_PATH_APPTOAPP_COMMAND);
    Map<String, String> params = new HashMap<String, String>();
    params.put("name", "AppExecute");
    params.put("auid", auid);
    if (appName != null) {
        params.put("appname", appName);
    }
    if (contentId != null) {
        params.put("contentid", contentId);
    }
    String httpMessage = getUDAPMessageBody(UDAP_API_COMMAND, params);
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, requestURL, httpMessage, responseListener);
    request.send();
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 12 with LaunchSession

use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.

the class NetcastTVService method launchNetflix.

@Override
public void launchNetflix(final String contentId, final Launcher.AppLaunchListener listener) {
    if (!serviceDescription.getModelNumber().equals("4.0")) {
        launchApp("Netflix", listener);
        return;
    }
    final String appName = "Netflix";
    getApplication(appName, new AppInfoListener() {

        @Override
        public void onSuccess(final AppInfo appInfo) {
            JSONObject jsonObj = new JSONObject();
            try {
                jsonObj.put("id", appInfo.getId());
                jsonObj.put("name", appName);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            ResponseListener<Object> responseListener = new ResponseListener<Object>() {

                @Override
                public void onSuccess(Object response) {
                    LaunchSession launchSession = LaunchSession.launchSessionForAppId(appInfo.getId());
                    launchSession.setAppName(appName);
                    launchSession.setService(NetcastTVService.this);
                    launchSession.setSessionType(LaunchSessionType.App);
                    Util.postSuccess(listener, launchSession);
                }

                @Override
                public void onError(ServiceCommandError error) {
                    Util.postError(listener, error);
                }
            };
            String requestURL = getUDAPRequestURL(UDAP_PATH_APPTOAPP_COMMAND);
            Map<String, String> params = new HashMap<String, String>();
            params.put("name", "SearchCMDPlaySDPContent");
            params.put("content_type", "1");
            params.put("conts_exec_type", "20");
            params.put("conts_plex_type_flag", "N");
            params.put("conts_search_id", "2023237");
            params.put("conts_age", "18");
            params.put("exec_id", "netflix");
            params.put("item_id", "-Q m=http%3A%2F%2Fapi.netflix.com%2Fcatalog%2Ftitles%2Fmovies%2F" + contentId + "&amp;source_type=4&amp;trackId=6054700&amp;trackUrl=https%3A%2F%2Fapi.netflix.com%2FAPI_APP_ID_6261%3F%23Search%3F");
            params.put("app_type", "");
            String httpMessage = getUDAPMessageBody(UDAP_API_COMMAND, params);
            ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(NetcastTVService.this, requestURL, httpMessage, responseListener);
            request.send();
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    });
}
Also used : LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) AppInfo(com.connectsdk.core.AppInfo) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 13 with LaunchSession

use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.

the class NetcastTVService method launchAppStore.

@Override
public void launchAppStore(final String appId, final AppLaunchListener listener) {
    if (!serviceDescription.getModelNumber().equals("4.0")) {
        // TODO: this will not work in Korea, use Korean name instead
        launchApp("LG Smart World", listener);
        return;
    }
    String targetPath = getUDAPRequestURL(ROAP_PATH_APP_STORE);
    Map<String, String> params = new HashMap<String, String>();
    params.put("name", "SearchCMDPlaySDPContent");
    params.put("content_type", "4");
    params.put("conts_exec_type", "");
    params.put("conts_plex_type_flag", "");
    params.put("conts_search_id", "");
    params.put("conts_age", "12");
    params.put("exec_id", "");
    params.put("item_id", HttpMessage.encode(appId));
    params.put("app_type", "S");
    String httpMessage = getUDAPMessageBody(UDAP_API_COMMAND, params);
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            LaunchSession launchSession = LaunchSession.launchSessionForAppId(appId);
            // TODO: this will not work in Korea, use Korean name instead
            launchSession.setAppName("LG Smart World");
            launchSession.setService(NetcastTVService.this);
            launchSession.setSessionType(LaunchSessionType.App);
            Util.postSuccess(listener, launchSession);
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(this, targetPath, httpMessage, responseListener);
    command.send();
}
Also used : HashMap(java.util.HashMap) LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 14 with LaunchSession

use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.

the class WebOSTVService method launchWebApp.

public void launchWebApp(final String webAppId, final JSONObject params, final WebAppSession.LaunchListener listener) {
    if (webAppId == null || webAppId.length() == 0) {
        Util.postError(listener, new ServiceCommandError(-1, "You need to provide a valid webAppId.", null));
        return;
    }
    final WebOSWebAppSession _webAppSession = mWebAppSessions.get(webAppId);
    String uri = "ssap://webapp/launchWebApp";
    JSONObject payload = new JSONObject();
    try {
        payload.put("webAppId", webAppId);
        if (params != null)
            payload.put("urlParams", params);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(final Object response) {
            JSONObject obj = (JSONObject) response;
            LaunchSession launchSession = null;
            WebOSWebAppSession webAppSession = _webAppSession;
            if (webAppSession != null)
                launchSession = webAppSession.launchSession;
            else {
                launchSession = LaunchSession.launchSessionForAppId(webAppId);
                webAppSession = new WebOSWebAppSession(launchSession, WebOSTVService.this);
                mWebAppSessions.put(webAppId, webAppSession);
            }
            launchSession.setService(WebOSTVService.this);
            launchSession.setSessionId(obj.optString("sessionId"));
            launchSession.setSessionType(LaunchSessionType.WebApp);
            launchSession.setRawData(obj);
            Util.postSuccess(listener, webAppSession);
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, payload, true, responseListener);
    request.send();
}
Also used : JSONObject(org.json.JSONObject) LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONException(org.json.JSONException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) JSONObject(org.json.JSONObject) WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 15 with LaunchSession

use of com.connectsdk.service.sessions.LaunchSession in project butter-android by butterproject.

the class WebOSTVService method connectToApp.

/* Connect to a native/installed webOS app */
public void connectToApp(String appId, final WebAppSession.LaunchListener listener) {
    LaunchSession launchSession = LaunchSession.launchSessionForAppId(appId);
    launchSession.setSessionType(LaunchSessionType.App);
    launchSession.setService(this);
    final WebOSWebAppSession webAppSession = webAppSessionForLaunchSession(launchSession);
    connectToWebApp(webAppSession, false, new ResponseListener<Object>() {

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }

        @Override
        public void onSuccess(Object object) {
            Util.postSuccess(listener, webAppSession);
        }
    });
}
Also used : LaunchSession(com.connectsdk.service.sessions.LaunchSession) JSONObject(org.json.JSONObject) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) WebOSWebAppSession(com.connectsdk.service.sessions.WebOSWebAppSession)

Aggregations

LaunchSession (com.connectsdk.service.sessions.LaunchSession)17 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)12 JSONObject (org.json.JSONObject)10 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)9 ServiceCommand (com.connectsdk.service.command.ServiceCommand)9 JSONException (org.json.JSONException)6 HashMap (java.util.HashMap)4 AppInfo (com.connectsdk.core.AppInfo)2 WebOSWebAppSession (com.connectsdk.service.sessions.WebOSWebAppSession)2 IOException (java.io.IOException)2 PListBuilder (com.connectsdk.service.airplay.PListBuilder)1 CastWebAppSession (com.connectsdk.service.sessions.CastWebAppSession)1 WebAppSession (com.connectsdk.service.sessions.WebAppSession)1 ApplicationMetadata (com.google.android.gms.cast.ApplicationMetadata)1 ApplicationConnectionResult (com.google.android.gms.cast.Cast.ApplicationConnectionResult)1 LaunchOptions (com.google.android.gms.cast.LaunchOptions)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1