と思われるでしょうが
6年物のCore2DuoのPCでがんばってる身としては、なるべく軽くて、枯れた環境でやっていたかったのです・・・
ADT 22.6.0(March 2014) Dependencies:
- Java 1.6 or higher is required.
- Eclipse Indigo (Version 3.7.2) or higher is required.
今日からEclipse Keplerでがんばりたいと思います
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対応 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);
}
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")
}
}
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);
}
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.暗黙的Intent | ○ | ○ | Twitter関連アプリ以外もでる |
| 2.Package指定 | × | ○ | 公式Twitterクライアントのみでる |
| 3.URIスキーム指定 | △ | × | 互換クライアントはスキーム対応アプリのみ |
| 4.URL(HTTP)指定 | × | × | 公式クライアントがなくてもブラウザで投稿できる |