网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

android调用系统分享图片及文字-创新互联

调用系统分享文字:
public static void shareText(Context context, String extraText) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "连接分享");
intent.putExtra(Intent.EXTRA_TEXT, extraText);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(
Intent.createChooser(intent, "连接分享"));
}

创新互联公司是一家专业从事成都网站建设、做网站、网页设计的品牌网络公司。如今是成都地区具影响力的网站设计公司,作为专业的成都网站建设公司,创新互联公司依托强大的技术实力、以及多年的网站运营经验,为您提供专业的成都网站建设、营销型网站建设及网站设计开发服务!

调用系统分享图片,方法是:
1、 把图片放到文件assets里面
2、先读取Assets里面的图片转化成Bitmap;
3、再以文件File形式保存在本地;
4、最后Uri连接本地该图片进行分享。

调用系统原生分享图片代码:

public static void shareImage(Context context, Uri uri, String title) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("image/jpeg");
context.startActivity(Intent.createChooser(shareIntent, title));
}

最后Uri连接本地该图片进行分享:

方法一:
// 读取Assets里面的图片转化成Bitmap
private static Bitmap getImageFromAssetsFile(Context context,String fileName){
Bitmap image = null;
AssetManager am = context.getResources().getAssets();
try {
InputStream is=am.open(fileName);
image= BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace(); }
return image;
}

// Bitmap以文件File形式保存在本地
private static Uri saveBitmap(Bitmap bm, String picName) {
try {
String dir= Environment.getExternalStorageDirectory().getAbsolutePath()+"/zqhd/"+picName+".jpg";
File f = new File(dir);
if (!f.exists()) {
f.getParentFile().mkdirs();
f.createNewFile();
}
FileOutputStream out = new FileOutputStream(f);
bm.compress(Bitmap.CompressFormat.JPEG, 80, out);
out.flush();
out.close();
Uri uri = Uri.fromFile(f);
return uri;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace(); }
return null;
}

public static void localshare(Context context,String pic) {
/* 分享图片 /
Bitmap bgimg0 = getImageFromAssetsFile(context,pic+".png");
Intent share_intent = new Intent();
share_intent.setAction(Intent.ACTION_SEND);//设置分享行为
share_intent.setType("image/
"); //设置分享内容的类型
share_intent.putExtra(Intent.EXTRA_STREAM, saveBitmap(bgimg0,pic));
//创建分享的Dialog
share_intent = Intent.createChooser(share_intent, "分享图片");
context.startActivity(share_intent);
}

方法二:

public static String dir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/zuhd/";

// Bitmap以文件File形式保存在本地
public static File saveFile(Bitmap bm,String path, String fileName) throws IOException {
File dirFile = new File(path);
if(!dirFile.exists()){
dirFile.mkdir();
}
File myCaptureFile = new File(path , fileName);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);
bos.flush();
bos.close();
return myCaptureFile;
}

public static void sharePic(){
 Bitmap  bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ewcode);
               File file=null;
            try {
                file = saveFile(bitmap, dir, "ewcode.jpg");

            } catch (IOException e) {
                e.printStackTrace();
            }
                                 Uri uri = Uri.fromFile(file);
                                 Shares.shareImage(EWcodeActivity.this,uri,"二维码分享");

    }

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站标题:android调用系统分享图片及文字-创新互联
URL地址:http://bjjierui.cn/article/ehijh.html

其他资讯