• 安卓高级9 用原生intent分享


    大家都用过安卓app时发现有个分享按钮如下:
    百度
    所以今天特此分享用用原生完成:

    package qianfeng.com.simplesharedemo;
    
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.Environment;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    
    import java.io.File;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
        }
    
        public void onClick(View view) {
            shareImage();
    
        }
    
        public void shareText() {
            //点击分享
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, "这是一条测试信息");
            String title = "   分享到:  ";
            startActivity(Intent.createChooser(intent, title));
        }
    
        public void shareImage() {
            String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "aaa.jpg";
    
            Uri uri = Uri.fromFile(new File(filePath));
            //点击分享
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_STREAM, uri);
            String title = "   分享到:  ";
            startActivity(Intent.createChooser(intent, title));
        }
    
    
    
    
    }
    

    另外还有分享多个图片等案例

    public void shareImage() {
            String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "aaa.jpg";
            String filePath2 = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "aaa.jpg";
    
            Uri uri = Uri.fromFile(new File(filePath));
            Uri uri2 = Uri.fromFile(new File(filePath2));
            ArrayList<Uri> uris = new ArrayList<>();
            uris.add(uri);
            uris.add(uri2);
    
            //点击分享
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("image/*");
            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
            String title = "   分享到:  ";
            startActivity(Intent.createChooser(intent, title));
        }
  • 相关阅读:
    .NET经销商实战(七)——获取商品类型接口开发
    .gitignore规则不生效
    .NET经销商实战(五)——linq分页查询
    .NET经销商实战(十)——根据物品小类筛选数据
    .NET经销商实战(十二)——优化用户体验,完善产品列表查询
    .NET经销商实战(八)——前端界面代码改造
    .NET经销商实战(三)——md5加密,反射注入仓储与服务,及生成token
    Ubuntu 22.04 MacOS Monterey 主题
    Dart 语言之旅
    Docker storage drivers
  • 原文地址:https://www.cnblogs.com/muyuge/p/6152126.html
Copyright © 2020-2023  润新知