Androidアプリ 「twicca shutter plug-in」 リリースしましか
Androidアプリ 「twicca shutter plug-in」とは?
Android専用Twitterクライアント「twicca」に写真・動画アップロードサービス「shutter」の機能を拡張するプラグインです。
shutterって?
http://shtt.jp/ は国産のTwitter連携した写真・動画アップロードサービスです。写真や動画をアップロードすると短縮URLに変換され、そのままツイートすることができます。まだリリースされたばかりでこれから流行りそうな感じなので、可愛がってあげてください。yfrogとかtwitpicと同じだと思ってもらっていいです。
Android Market
DLはこちらから。
https://market.android.com/details?id=jp.shikajiro.twiccaplugin
ソースコード
githubで公開中。
https://github.com/shikajiro/twicca-shutter-plug-in
twicca plug-in の参考にして頂けると幸いです。
twicca plug-inのつくりかた
しかだよ。
twicca shutter plug-in作ったので技術公開します。主にメディアアップロードプラグインの作り方になります。
サンプルソースコード
twicca shutter plug-inのソースコードはgithubで公開中なう。
https://github.com/shikajiro/twicca-shutter-plug-in
公式ドキュメント
http://twicca.r246.jp/plugins/documents/
androidやってる方は読めば分かるかも知れないけど、しかは未熟なのでわからないことが多かった。
おおまかな作り方
twiccaからのメディアの受け取り方
getIntent()でもらえます。
InputStream openInputStream = null; try{ Intent receivedIntent = getIntent(); Uri uri = receivedIntent.getData(); openInputStream = getContentResolver().openInputStream(uri); }...
アップロードするメディアの種類を決める
mimeTypeをどこに書くのかわかんなかった。Manifestファイルのactivityのintent-filterに書くみたいです。画像や動画の様に複数種類ある場合は、複数行に分けて書いてください。
<activity android:name=".MainActivity" android:label="@string/acitivity_name" android:theme="@android:style/Theme.Translucent"> <intent-filter> <action android:name="jp.r246.twicca.ACTION_UPLOAD" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> <data android:mimeType="video/*" /> </intent-filter> </activity>
変換画面は透明にしたい
twiccaの画面を隠さず処理したい場合、activityを透明にします。activityタグのthemeにTranslucentの設定してください。applicationタグに書くと、他のactivityも透明になるので注意。
<activity android:name=".MainActivity" android:label="@string/acitivity_name" android:theme="@android:style/Theme.Translucent">
メディアと文字列を同時にPostできない
MultipartEntityを使ってください。
http://hc.apache.org/downloads.cgi
HttpClient 4.1の中に入っている httpmime-4.1.jar をAndroidプロジェクトの中に突っ込んで、Pathを通してください。(僕はlibディレクトリを作ってpathを通しました。)
HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(UPLOAD_URL); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart("key", new StringBody(key, Charset.forName("UTF-8"))); // TODO メッセージに何を送る? entity.addPart("message", new StringBody("shutter plugin sample message", Charset.forName("UTF-8"))); String type = getIntent().getType(); // TODO ファイル名をどうする? InputStreamBody streamBody = new InputStreamBody(inputStream, type,"shutter_plugin_sample.jpg"); entity.addPart("media", streamBody); httppost.setEntity(entity); HttpResponse response = httpclient.execute(httppost);
これで写真や動画のメディアとファイル名などの文字列を同時にサーバーにPostできます。
plug-inで使うのはActivity
どうやらtwiccaから呼ばれるのはActivityじゃないとだめっぽいです。レシーバやサービスでやってみましたがだめでした。