2014年6月6日金曜日

間取りー図をアップデート サイズの編集をロックする機能を追加

間取りー図をアップデートしました
主な変更点は以下
・サイズの編集をロックする機能を追加
 ・オブジェクトの編集ボタンを隠す機能を追加
 
・How toを追加
 
以上です
サイズの編集をロックする機能はよくユーザーからの要望で上がってましたので、ようやくつけれてよかったです
"How to"については今までなかったのがおかしいのですが、間取りー図はかなり有効インスト率が低いなと感じるアプリで、それというのも信じられないことですが、操作の説明が一切ないというのも大きな一因と思ってました
今回のHow toの追加でこの辺に効果があったかどうか、一か月後くらいに報告したいと思います

2014年6月4日水曜日

AndroidでTwitter公式の投稿Activityを取得(新旧バージョン対応)

前回Androidアプリからツイートする4つの方法を紹介しましたが、その中でPackageManagerを利用してピンポイントで公式クライアントアプリを呼び出す方法を紹介しました
しかし、この方法は呼出し時に投稿に使われるActivityまで指定しなければならないため、公式クライアントの更新により変更されてしまった場合使えなくなります
実際過去2回ほどありました
ここではその2回の変更に対応してユーザーの公式クライアントが古いバージョンの場合にも対応できる方法を紹介します

  public static String getTwitterClass(Context context) {
    String twitterClass = null;
    PackageManager pm = context.getPackageManager();
    String packagename = "com.twitter.android";
    String class1 = "com.twitter.android.PostActivity";
    String class2 = "com.twitter.applib.composer.TextFirstComposerActivity";
    String class3 = "com.twitter.android.composer.TextFirstComposerActivity";
    try {
      ActivityInfo[] activities = pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES).activities;
      for(int i = 0; i < activities.length; i++) {
        if (activities[i].name.equals(class1)) {
          twitterClass = class1;
          break;
        } else if (activities[i].name.equals(class2)) {
          twitterClass = class2;
          break;
        } else if (activities[i].name.equals(class3)) {
          twitterClass = class3;
          break;
        }
      }
    } catch (PackageManager.NameNotFoundException e) {
      //Twitter is not install
    }
    return twitterClass ;
  }
※Twitter バージョン5.8.0対応

内容はいたって簡単で、パッケージ名は不変なので"com.twitter.android"でGET_ACTIVITIESによりActivityの一覧を取得して、既知の3つのActivity名と照合します
あとはこれで取得したActivity名を
intent.setClassName("com.twitter.android", 取得Activity名);
とセットして明示的インテントで呼べばオッケーです

2014年6月2日月曜日

AndroidアプリからTwitter公式クライアントでツイートする4つの方法

今回EasyBowlingとBowlingScoreBookにSNS投稿機能をつけましたが、BowlingScoreBookでは特に「Twitterで投稿」ボタンを付けました
その時に調べたTwitterの公式クライアントを呼びだしてツイートする4つの方法です
  1. 暗黙的Intentで投稿
  2. Intent.ACTION_SENDで暗黙的Intent呼び出しによる投稿です
    ACTION_SENDと"text/plain"に反応するアプリがすべて出るので公式以外のクライアントアプリ、Twitterに関係のないアプリも出てきます
      public static void tweetFile1(Context context, String message) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, message);
        ((Activity)context).startActivity(intent);
      }
    
  3. 公式アプリのPackage、Classを指定して投稿
  4. PackageManagerで公式クライアントをピンポイントで呼び出します
    公式以外のクライアントアプリ以外は反応しません
    公式の投稿用Activityが変わった場合には修正が必要となります(過去2回程変更されている)
      public static void tweetFile2(Context context, String message) {
        String twitterClass = "com.twitter.android.composer.TextFirstComposerActivity";
        try {
          Intent intent = new Intent();
          intent.setAction(Intent.ACTION_SEND);
          intent.setType("text/plain");
          intent.putExtra(Intent.EXTRA_TEXT, message);
          intent.setClassName("com.twitter.android", twitterClass);
          ((Activity)context).startActivity(intent);
        } catch (PackageManager.NameNotFoundException e) {
          //Toast("Not found com.twitter.android")
        }
      }
    
  5. URIスキームを指定して投稿
  6. WEBページからアプリを呼び出すのに使用するURIスキームを利用して呼び出します
    公式以外でも"twitter://"のスキームに対応しているアプリが呼び出されます
      public static void tweetFile3(Context context, String message) {
        String url = "twitter://post?message=" + message;
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setType("text/plain");
        intent.setData(Uri.parse(url));
        ((Activity)context).startActivity(intent);
      }
    
  7. URL(http://twitter.com/)を利用して投稿
  8. 公式クライアントかWEBブラウザが呼び出されます ブラウザの場合、"http://twitter.com/"の投稿画面が呼び出されます
      public static void tweetFile4(Context context, String message) {
        String url = "http://twitter.com/share?text=" + message;
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        intent.setType("text/plain");
        intent.setData(Uri.parse(url));
        ((Activity)context).startActivity(intent);
      }
    
このように色々と投稿方法がありますが、どれを採用すべきかは状況によるかと思います
以下に各手法の特徴をまとめてみました
投稿方法互換
クライ
アント
画像
投稿
備 考
1.暗黙的IntentTwitter関連アプリ以外もでる
2.Package指定×公式Twitterクライアントのみでる
3.URIスキーム指定×互換クライアントはスキーム対応アプリのみ
4.URL(HTTP)指定××公式クライアントがなくてもブラウザで投稿できる
※2014/06/02現在