簡體   English   中英

使用Fabric在Twitter上共享SD卡視頻嗎?

[英]Sd card Video Sharing on Twitter using the Fabric?

我正在使用Twitter的Fabric共享視頻。我無法在Twitter上共享視頻,但是現在我僅在Fabric的幫助下共享圖像
以下是我的結構集成代碼行

public class MainActivity extends AppCompatActivity {

    // Note: Your consumer key and secret should be obfuscated in your source code before shipping.
    private static final String TWITTER_KEY = "xxxxxxx";
    private static final String TWITTER_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxx";
    private TwitterAuthClient authclient;
    private TwitterLoginButton loginButton;
    private String selectedImagePath;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
        Fabric.with(this, new Twitter(authConfig));
        setContentView(R.layout.activity_main);



        authclient = new TwitterAuthClient();


        loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
        loginButton.setCallback(new Callback<TwitterSession>() {
            @Override
            public void success(Result<TwitterSession> result) {
                // The TwitterSession is also available through:
                // Twitter.getInstance().core.getSessionManager().getActiveSession()
                TwitterSession session = result.data;
                // TODO: Remove toast and use the TwitterSession's userID
                // with your app's user model
                String msg = "@" + session.getUserName() + " logged in! (#" + session.getUserId() + ")";
                Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
            }

            @Override
            public void failure(TwitterException exception) {
                Log.d("TwitterKit", "Login with Twitter failure", exception);
            }
        });


        Button share_btn = (Button)findViewById(R.id.share_btn);
        share_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
                intent.setType("video/*");
                startActivityForResult(intent, 3);



            }
        });


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            try {

                 if (requestCode == 3) {
                    Uri selectedImageUri = data.getData();

                    // OI FILE Manager


                    selectedImagePath = selectedImageUri.getPath();

                    // MEDIA GALLERY
                    selectedImagePath = getPath(selectedImageUri);

                    System.out.println("Here is the data ==>> " + selectedImagePath+"  ");


                     TweetComposer.Builder builder = new TweetComposer.Builder(MainActivity.this)
                             .text("")
                             .image(Uri.parse(selectedImagePath));
                     builder.show();


                 }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public String getPath(Uri uri) {
        String[] projection = {MediaStore.Images.Media.DATA};
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        if (cursor != null) {
            // HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
            // THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
            int column_index = cursor
                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        } else
            return null;
    }

}

我有使用Twitter的 Fabrics上傳視頻的解決方案
以下是使用Fabric將視頻上傳到Twitter的以下代碼行

             File myVideoFile = new File("HERE_IS_YOURS_SD_CARD_VIDEO_PATH");
             Uri myVideoUri = Uri.fromFile(myVideoFile);

             TweetComposer.Builder builder = new TweetComposer.Builder(MainActivity.this)
                     .text("YOUR_TEXT_MESSAGE")  //Here is yours  message which you want to send..If u does not require than remove this method
                    .image(myVideoUri );
             builder.show();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM