189 8069 5689

android调用系统分享-创新互联

package com.example.sharedemo;

import com.google.zxing.WriterException;

网站的建设成都创新互联公司专注网站定制,经验丰富,不做模板,主营网站定制开发.小程序定制开发,H5页面制作!给你焕然一新的设计体验!已为服务器租用等企业提供专业服务。

import android.net.Uri;

import android.os.Bundle;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.Context;

import android.content.DialogInterface;

import android.content.Intent;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class ShareActivity extends Activity {

private Button btnshare;

private Context context;

private String msg;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_share);

context = ShareActivity.this;

msg = "Test share";

btnshare = (Button) findViewById(R.id.button1);

btnshare.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

shareMemo(context, msg);

}

});

}

public static void shareMemo(final Context context, final String uid) {

new AlertDialog.Builder(context)

.setTitle(context.getString(R.string.selectsharemode))

.setItems(

context.getResources()

.getStringArray(R.array.sharemode),

new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog,

int which) {

// TODO Auto-generated method stub

if (which == 0) {

Intent it = new Intent(Intent.ACTION_SEND);

it.putExtra(Intent.EXTRA_TEXT, uid);

// it.setType("audio

    public Bitmap Create2DCode(String str) throws WriterException {

        //生成二维矩阵,编码时指定大小,不要生成了图片以后再进行缩放,这样会模糊导致识别失败

    qrcode =  str;

        BitMatrix matrix = new MultiFormatWriter().encode(str,BarcodeFormat.QR_CODE, 300, 300);

        int width = matrix.getWidth();

        int height = matrix.getHeight();

        //二维矩阵转为一维像素数组,也就是一直横着排了

        int[] pixels = new int[width * height];

        for (int y = 0; y < height; y++) {

            for (int x = 0; x < width; x++) {

                if(matrix.get(x, y)){

                    pixels[y * width + x] = 0xff000000;

                }

            }

        }

        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

        //通过像素数组生成bitmap,具体参考api

        bitmap.setPixels(pixels, 0, width, 0, 0, width, height);

        return bitmap;

    }

    public Uri  WriteBitmap(Bitmap bm)

    {

    String filepath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + qrcode + ".png";

    File file = new File(filepath);

    try {

      if(!file.createNewFile()) {

          System.out.println("File already exists");

      }

    } catch (IOException ex) {

      System.out.println(ex);

    }

    try {

      FileOutputStream out = new FileOutputStream(file);

      bm.compress(Bitmap.CompressFormat.PNG, 90, out);

      out.flush();

      out.close();

     } catch (FileNotFoundException e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

     } catch (IOException e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

     }

    return Uri.fromFile(file);

    }

}

//少不了权限

//strings.xml

   请选择分享模式

        文字分享UID

        图片分享UID

另外需要导入core.jar库文件

这个可从网上下载

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


网页标题:android调用系统分享-创新互联
浏览路径:http://jkwzsj.com/article/ejgdh.html

其他资讯