在我的Android应用程序上,我想在twitter上分享视频,因为我有以下代码:
btnShareTwitter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
videoMoreLayout.setVisibility(View.GONE);
videoActions = new VideoActions();
final String id = videoIDs[position];
if (!isOnline()) {
Toast.makeText(activity,
activity.getString(R.string.noInternetConnection),
Toast.LENGTH_SHORT).show();
} else {
String finalVideoName = null;
String arr[] = videoPathURL[position].split("/upload/videos/");
finalVideoName = (arr[arr.length-1]);
File DoutFile = new File(
Environment.getExternalStorageDirectory() +
File.separator + "vidytape_shared" + File.separator + finalVideoName);
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.setType("video/*");
tweetIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(DoutFile));
tweetIntent.putExtra(Intent.EXTRA_TEXT,
"" + activity.getResources().getString(R.string.app_name));
/*Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.putExtra(Intent.EXTRA_TEXT,
videoPathURL[position]);
tweetIntent.setType("video/*");*/
PackageManager packManager = activity.getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager
.queryIntentActivities(tweetIntent, 0);
boolean resolved = false;
for (ResolveInfo resolveInfo : resolvedInfoList) {
if (resolveInfo.activityInfo.name.equals("com.twitter.android.PostActivity")) {
ActivityInfo actInfo = resolveInfo.activityInfo;
ComponentName cName = new ComponentName(actInfo.applicationInfo.packageName, actInfo.name);
tweetIntent.addCategory(Intent.CATEGORY_LAUNCHER);
tweetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
tweetIntent.setComponent(cName);
resolved = true;
break;
}
}
if (resolved) {
if(!DoutFile.exists()){
Toast.makeText(activity, "Preparing video. Please wait", Toast.LENGTH_LONG).show();
String downloadResult = videoActions.downloadToShare(token, activity, id, videoPathURL[position], finalVideoName);
if (downloadResult.equalsIgnoreCase("POST_FAILURE") || downloadResult.equalsIgnoreCase("FAILURE_102")) {
Toast.makeText(
activity,
activity.getString(R.string.someErrorOccurred),
Toast.LENGTH_SHORT).show();
}
}
activity.startActivity(tweetIntent);
} else {
Toast.makeText(
activity,
activity.getString(R.string.twitterNotInstalled),
Toast.LENGTH_LONG).show();
}
}
}
});
但是我收到了没有安装twitter的Toast消息......我用android 4.4.2,我不知道它是否可以做些什么。
提前致谢