Android 安卓:当我通过本机推特应用程序推特时,我可以附加图片吗

Android 安卓:当我通过本机推特应用程序推特时,我可以附加图片吗,android,twitter,Android,Twitter,这是我的密码 Intent intent = new Intent(Intent.ACTION_SEND); intent.setClassName("com.twitter.android", "com.twitter.android.PostActivity"); intent.putExtra(Intent.EXTRA_TEXT, message); startActivity(intent); var postrTwitter = Ti.Android.crea

这是我的密码

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName("com.twitter.android", "com.twitter.android.PostActivity");
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(intent);
            var postrTwitter = Ti.Android.createIntent({
            action : Ti.Android.ACTION_SEND,
            packageName : "com.twitter.android",
            className : "com.twitter.android.PostActivity",
            flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK,
            type : "text/plain"
            });
            postrTwitter.setType("*/*");
            postrTwitter.putExtra(Ti.Android.EXTRA_TEXT, "Text message ");
            postrTwitter.putExtraUri(Ti.Android.EXTRA_STREAM, image_file.nativePath);

            Ti.Android.currentActivity.startActivity(postrTwitter);
我可以通过编程方式附加图片吗

            var postrTwitter = Ti.Android.createIntent({
            action : Ti.Android.ACTION_SEND,
            packageName : "com.twitter.android",
            className : "com.twitter.android.PostActivity",
            flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK,
            type : "text/plain"
            });
            postrTwitter.setType("*/*");
            postrTwitter.putExtra(Ti.Android.EXTRA_TEXT, "Text message ");
            postrTwitter.putExtraUri(Ti.Android.EXTRA_STREAM, image_file.nativePath);

            Ti.Android.currentActivity.startActivity(postrTwitter);

            var postrTwitter = Ti.Android.createIntent({
            action : Ti.Android.ACTION_SEND,
            packageName : "com.twitter.android",
            className : "com.twitter.android.PostActivity",
            flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK,
            type : "text/plain"
            });
            postrTwitter.setType("*/*");
            postrTwitter.putExtra(Ti.Android.EXTRA_TEXT, "Text message ");
            postrTwitter.putExtraUri(Ti.Android.EXTRA_STREAM, image_file.nativePath);

            Ti.Android.currentActivity.startActivity(postrTwitter);
编辑

            var postrTwitter = Ti.Android.createIntent({
            action : Ti.Android.ACTION_SEND,
            packageName : "com.twitter.android",
            className : "com.twitter.android.PostActivity",
            flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK,
            type : "text/plain"
            });
            postrTwitter.setType("*/*");
            postrTwitter.putExtra(Ti.Android.EXTRA_TEXT, "Text message ");
            postrTwitter.putExtraUri(Ti.Android.EXTRA_STREAM, image_file.nativePath);

            Ti.Android.currentActivity.startActivity(postrTwitter);
解决方案

            var postrTwitter = Ti.Android.createIntent({
            action : Ti.Android.ACTION_SEND,
            packageName : "com.twitter.android",
            className : "com.twitter.android.PostActivity",
            flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK,
            type : "text/plain"
            });
            postrTwitter.setType("*/*");
            postrTwitter.putExtra(Ti.Android.EXTRA_TEXT, "Text message ");
            postrTwitter.putExtraUri(Ti.Android.EXTRA_STREAM, image_file.nativePath);

            Ti.Android.currentActivity.startActivity(postrTwitter);
额外增加1行

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName("com.twitter.android", "com.twitter.android.PostActivity");
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.putExtra(Intent.EXTRA_STREAM, Uri);      
startActivity(intent);
            var postrTwitter = Ti.Android.createIntent({
            action : Ti.Android.ACTION_SEND,
            packageName : "com.twitter.android",
            className : "com.twitter.android.PostActivity",
            flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK,
            type : "text/plain"
            });
            postrTwitter.setType("*/*");
            postrTwitter.putExtra(Ti.Android.EXTRA_TEXT, "Text message ");
            postrTwitter.putExtraUri(Ti.Android.EXTRA_STREAM, image_file.nativePath);

            Ti.Android.currentActivity.startActivity(postrTwitter);
试试这个

Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
Uri screenshotUri = Uri.parse("file:///sdcard/image.jpg");
sharingIntent.setType("*/*");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Body text of the new status");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
            var postrTwitter = Ti.Android.createIntent({
            action : Ti.Android.ACTION_SEND,
            packageName : "com.twitter.android",
            className : "com.twitter.android.PostActivity",
            flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK,
            type : "text/plain"
            });
            postrTwitter.setType("*/*");
            postrTwitter.putExtra(Ti.Android.EXTRA_TEXT, "Text message ");
            postrTwitter.putExtraUri(Ti.Android.EXTRA_STREAM, image_file.nativePath);

            Ti.Android.currentActivity.startActivity(postrTwitter);

试试这段代码,它工作得很好。如果你的手机上安装了twitter应用程序。否则使用try..catch

            var postrTwitter = Ti.Android.createIntent({
            action : Ti.Android.ACTION_SEND,
            packageName : "com.twitter.android",
            className : "com.twitter.android.PostActivity",
            flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK,
            type : "text/plain"
            });
            postrTwitter.setType("*/*");
            postrTwitter.putExtra(Ti.Android.EXTRA_TEXT, "Text message ");
            postrTwitter.putExtraUri(Ti.Android.EXTRA_STREAM, image_file.nativePath);

            Ti.Android.currentActivity.startActivity(postrTwitter);