Android 推特文本和图像

Android 推特文本和图像,android,android-intent,twitter,Android,Android Intent,Twitter,遵循以下简单代码: String tweetUrl = "https://twitter.com/intent/tweet?text=PUT TEXT HERE &url="+"https://www.google.com"; Uri uri = Uri.parse(tweetUrl); startActivity(new Intent(Intent.ACTION_VIEW, uri)); 是否可以与这些文本和图像共享?不使用twitter4j库 谢谢大家! 此代码的作用是查询与Int

遵循以下简单代码:

String tweetUrl = "https://twitter.com/intent/tweet?text=PUT TEXT HERE &url="+"https://www.google.com";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
是否可以与这些文本和图像共享?不使用twitter4j库


谢谢大家!

此代码的作用是查询与
Intent.ACTION\u SEND
匹配的所有活动,然后搜索
“com.twitter.android.PostActivity”
Intent

try{
intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.setType("text/plain");
final PackageManager pm = context.getPackageManager();
final List activityList = pm.queryIntentActivities(intent, 0);
    int len =  activityList.size();
for (int i = 0; i < len; i++) {
    final ResolveInfo app = activityList.get(i);
    if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) {
        final ActivityInfo activity=app.activityInfo;
        final ComponentName name=new ComponentName(activity.applicationInfo.packageName, activity.name);
        intent=new Intent(Intent.ACTION_SEND);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        intent.setComponent(name);
        intent.putExtra(Intent.EXTRA_TEXT, message);
        context.startActivity(intent);
        break;
    }
}
 }   catch(final ActivityNotFoundException e) {
     Log.i("mufumbo", "no twitter native",e );
      }
试试看{
意向=新意向(意向.行动\发送);
intent.putExtra(intent.EXTRA_文本、消息);
intent.setType(“文本/普通”);
final-PackageManager pm=context.getPackageManager();
最终列表activityList=pm.querytentActivities(intent,0);
int len=activityList.size();
对于(int i=0;i
试试这个,它对我有用。我将使用它来分享我的产品详细信息。我将从服务器上获取产品的详细信息,如名称、图像、描述,并在应用程序中显示,然后将其分享给twitter

从服务器获取图像url

URL url = ConvertToUrl(imgURL);
        Bitmap imagebitmap = null;
        try {
            imagebitmap = BitmapFactory.decodeStream(url.openConnection()
                    .getInputStream());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
在twitter上发布图片和文本

// post on twitter
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.putExtra(
                    Intent.EXTRA_TEXT,
                    "Check this out, what do you think?"
                            + System.getProperty("line.separator")
                            + sharedescription);
            intent.putExtra(Intent.EXTRA_SUBJECT, sharename);
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_STREAM,
                    getImageUri(HomeActivity.this, imagebitmap));
            intent.setPackage("com.twitter.android");
            startActivity(intent);
将Uri字符串转换为URL

private URL ConvertToUrl(String urlStr) {
    try {
        URL url = new URL(urlStr);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(),
                url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        url = uri.toURL();
        return url;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
将位图转换为Uri

public Uri getImageUri(Context inContext, Bitmap inImage) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(
            inContext.getContentResolver(), inImage, "Title", null);
    return Uri.parse(path);
}

你的意思是说你想在twitter上使用intent共享链接?谢谢,我修改了设置类型并加载了一个带有图片的外部流,我得到了我想要的!谢谢!