【问题标题】:Adding Social Media Share Logic From Firebase in Android在 Android 中从 Firebase 添加社交媒体共享逻辑
【发布时间】:2017-08-02 05:29:35
【问题描述】:

我正在使用 Firebase 构建一个 android instagram 克隆应用程序。我在我的应用程序中启用了社交媒体分享按钮,以便通过 Facebook、电子邮件、WhatsApp 等分享故事的内容,但不知道如何去做。

看看我的尝试:

公共类 InstacloneApp 扩展 AppCompatActivity { 私有RelativeLayoutrelativeLayout; 私有 ImageView postCoverImg, userPhotoUrl; 私有TextView post_Title,post_Descpn,post_Author,postDate; 私人按钮 cmetsBtn; 私有 FloatingActionButton shareFAB; 私人字符串 post_details = null; 私人 FirebaseAuth mAuth; 私有数据库参考 postRef; 私有上下文 mCtx = this; 私有字符串 uid_post = null; 私有 ScrollView 滚动视图; 私人工具栏工具栏; @覆盖 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_insta_clone_app); relativeLayout = (RelativeLayout) findViewById(R.id.activity_blog_posts_view); scrollView = (ScrollView) findViewById(R.id.scrollView); 工具栏 = (工具栏) findViewById(R.id.toolbar); 工具栏.setTitle(""); setSupportActionBar(工具栏); getSupportActionBar().setDisplayHomeAsUpEnabled(true); post_details = getIntent().getExtras().getString("post+key"); postCoverImg = (ImageView) findViewById(R.id.post_Backdrop); post_Title = (TextView) findViewById(R.id.post_title); post_Descpn = (TextView) findViewById(R.id.post_description_long); post_Author = (TextView) findViewById(R.id.authorTV); userPhotoUrl = (ImageView) findViewById(R.id.author_photo); postDate = (TextView) findViewById(R.id.post_date); shareFAB = (FloatingActionButton) findViewById(R.id.shareFAB); cmetsBtn = (按钮) findViewById(R.id.cmetsBtn); mAuth = FirebaseAuth.getInstance(); postRef = FirebaseDatabase.getInstance().getReference().child("Blog").child("All_Posts"); postRef.keepSynced(true); postRef.child(post_details.toString()).addValueEventListener(new ValueEventListener() { // 这是检索和查看博文数据 @覆盖 公共无效 onDataChange(DataSnapshot 数据快照){ String title_post = (String) dataSnapshot.child("postTitle").getValue(); String desc_post = (String) dataSnapshot.child("full_postDesc").getValue(); String background_post = (String) dataSnapshot.child("postImage").getValue(); String date_post = (String) dataSnapshot.child("postDate").getValue(); uid_post = (String) dataSnapshot.child("uid").getValue(); post_Title.setText(title_post); post_Descpn.setText(desc_post); postDate.setText(date_post); Glide.with(mCtx).load(backdrop_post).into(postCoverImg); } @覆盖 公共无效 onCancelled(DatabaseError databaseError) { } }); shareFAB.setOnClickListener(new View.OnClickListener() { // 我实现的分享动作 @覆盖 public void onClick(查看视图){ 字符串内容 = post_details; 意图 shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("*/*"); shareIntent.putExtra(Intent.EXTRA_TEXT,content); startActivity(Intent.createChooser(shareIntent,"分享给")); } });

【问题讨论】:

    标签: android firebase firebase-realtime-database media


    【解决方案1】:

    你应该试试

    shareIntent.setType("text/plain"); 
    

    而不是

    shareIntent.setType("*/*");
    

    【讨论】:

      【解决方案2】:

      我假设您想共享图像和文本(描述或其他一些细节),您可以查看this question

      如果您想为您的应用添加链接,例如在 Reddit/Instagram 等应用中,请查看 this question

      您可以将两者结合起来,将图像和文本(网址 + 小描述/用户名)分享给任何接受它的应用,例如 WhatsApp

      希望对您有所帮助!

      【讨论】:

        【解决方案3】:

        由于您分享了帖子内容,请尝试更改您的 来自:

        intent.setType("*/*");
        

        收件人:

        intent.setType("text/plain");
        

        【讨论】:

          猜你喜欢
          • 2015-04-13
          • 2012-06-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-09-09
          相关资源
          最近更新 更多