Tuesday, August 19, 2014

Android Slack send message example (Incoming WebHooks)

In slack, click "Configure Intergrations" and "Incoming WebHooks"
Create your application and "Incoming WebHooks" url with token.


Put "getInstance()"




/*
 * Made by ShakeJ (shakejj@gmail.com). Send message to slack's channel. Use
 * 'Incoming WebHooks' http://mnworld.co.kr Search 'ShakeJ' in google play :)
 */

public class SlackMessageUtil
{
  protected String siteUrl;
  private volatile static SlackMessageUtil uniqueInstance;
  
  
  private SlackMessageUtil(String incomingWebHookUrl)
  {
    this.siteUrl = incomingWebHookUrl;
  }
  
  
  public static SlackMessageUtil getInstance(Context context, String incomingWebHookUrl)
  {
    if (uniqueInstance == null)
      synchronized (SlackMessageUtil.class)
      {
        if (uniqueInstance == null)
          uniqueInstance = new SlackMessageUtil(incomingWebHookUrl);
      }
    return uniqueInstance;
  }
  
  
  @SuppressWarnings("unchecked")
  public void sendMessage(String channel, String message, String name)
  {
    JSONObject obj = new JSONObject();
    
    try
    {
      obj.put("channel", channel);
      obj.put("username", name);
      obj.put("text", message);
    }
    catch (JSONException e)
    {
      e.printStackTrace();
    }
    
    List params = new ArrayList();
    params.add(new BasicNameValuePair("payload", obj.toString()));
    new RequestAsyncTask().execute(params);
  }
  
  private class RequestAsyncTask extends AsyncTask, Integer, Boolean>
  {
    @Override
    protected Boolean doInBackground(List... params)
    {
      boolean result = false;
      try
      {
        DefaultHttpClient client = new DefaultHttpClient();
        HttpRequestBase requestBase = null;
        
        requestBase = new HttpPost(siteUrl);
        ((HttpPost) requestBase).setHeader("Content-Type", "application/x-www-form-urlencoded");
        ((HttpPost) requestBase).setEntity(new UrlEncodedFormEntity(params[0], "UTF-8"));
        HttpResponse response = client.execute(requestBase);
        
        if (response.getStatusLine().getStatusCode() < 400)
          result = true;
        else
          result = false;
        
        Log.w("WARN", "Send message to slack result : " + result);
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
      return result;
    }
  }
  
}

Tuesday, August 5, 2014

Android Wear music application 'Wear Music'

It is compatible with Android Wear.

Wear Music

Maybe Hear the music of the day that most of do with smartphones.
This app support more easily control your music with Wear.

With 'play', 'stop', 'pause', 'next track', 'prev track' control music and
'Volume up',  'Volume down'.

Select the app you are running 'Start' - 'Wear Music' in Wear. (Or Wear music start voice command)

To wear and send an alarm, you can control the music coming through the current song information, and Action. (To be updated)

https://play.google.com/store/apps/details?id=com.shakej.wear.music