安卓系統(tǒng)分享到微信qq微博

public class ShareActivityextends AppCompatActivityimplements View.OnClickListener {

private static Uriuri;

// private String path;

? ? private ArrayListpathList =new ArrayList<>();

@Override

? ? protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_share);

findViewById(R.id.bt_share).setOnClickListener(this);

findViewById(R.id.bt_shares).setOnClickListener(this);

findViewById(R.id.bt_share_wechat).setOnClickListener(this);

findViewById(R.id.bt_share_pyq).setOnClickListener(this);

findViewById(R.id.bt_share_qq).setOnClickListener(this);

findViewById(R.id.bt_share_wb).setOnClickListener(this);

findViewById(R.id.bt_share_wechats).setOnClickListener(this);

findViewById(R.id.bt_share_pyqs).setOnClickListener(this);

findViewById(R.id.bt_share_qqs).setOnClickListener(this);

findViewById(R.id.bt_share_wbs).setOnClickListener(this);

}

public void shareText() {

Intent shareIntent =new Intent();

shareIntent.setAction(Intent.ACTION_SEND);

shareIntent.putExtra(Intent.EXTRA_SUBJECT,"<a href=\"http://www.w3school.com.cn\">這是一個鏈接</a>");

shareIntent.putExtra(Intent.EXTRA_TEXT,"<a href=\"http://www.w3school.com.cn\">This is a link</a>");

shareIntent.setType("text/plain");

//shareIntent.setType("text/html");

? ? ? ? //設置分享列表的標題,并且每次都顯示分享列表

? ? ? ? startActivity(Intent.createChooser(shareIntent,"分享到"));

}

//https://blog.csdn.net/weixin_42165508/article/details/117348499

? ? ? ? public static void sharePhotoToWX(Context context, String text, String photoPath) {

/*if (!uninstallSoftware(context, "com.tencent.mm")) {

? ? ? ? ? ? ? ? Toast.makeText(context, "微信沒有安裝!", Toast.LENGTH_SHORT).show();

return;

}*/

/*? File file = new File(photoPath);

if (!file.exists()) {

? ? ? ? ? ? ? ? String tip = "文件不存在";

Toast.makeText(context, tip + " path = " + photoPath, Toast.LENGTH_LONG).show();

return;

}*/

? ? ? ? ? ? Intent intent =new Intent();

ComponentName componentName =new ComponentName("com.tencent.mm",

"com.tencent.mm.ui.tools.ShareToTimeLineUI");

intent.setComponent(componentName);

intent.setAction("android.intent.action.SEND");

intent.setType("image/*");

intent.putExtra("Kdescription", text);

intent.putExtra(Intent.EXTRA_STREAM,uri);

context.startActivity(intent);

}

// http://www.itdecent.cn/p/15eafb9e40f7

// https://www.bbsmax.com/A/gGdXAOg1z4/

? ? // 分享到微信 qq 微博 單圖,多圖等

? ? @Override

? ? public void onClick(View view) {

switch (view.getId()){

case R.id.bt_share:

shareText();

break;

case R.id.bt_shares:

// shareText();

? ? ? ? ? ? ? ? Intent intent =new Intent(Intent.ACTION_PICK,null);

intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,"image/*");

startActivityForResult(intent,2);

break;

case R.id.bt_share_wechat:

ShareFileUtilss.shareImageToWeChat(this,uri);

break;

case R.id.bt_share_pyq:

//sharePhotoToWX(this,"坎坎坷坷擴This is a link",null);

? ? ? ? ? ? ? ? ShareFileUtilss.shareImageToWeChatFriend(this,uri);

break;

case R.id.bt_share_qq:

ShareFileUtilss.shareImageToQQ(this,uri);

break;

case R.id.bt_share_wb:

ShareFileUtilss.shareImageToWeibo(this,uri);

break;

case R.id.bt_share_wechats:

ShareFileUtilss.shareImageToWeChat(this,pathList);

break;

case R.id.bt_share_pyqs:

//sharePhotoToWX(this,"坎坎坷坷擴This is a link",null);

? ? ? ? ? ? ? ? ShareFileUtilss.shareImageToWeChatFriend(this,pathList);

break;

case R.id.bt_share_qqs:

ShareFileUtilss.shareImageToQQ(this,pathList);

break;

case R.id.bt_share_wbs:

ShareFileUtilss.shareImageToWeibo(this,pathList);

break;

}

}

@Override

? ? protected void onActivityResult(int requestCode,int resultCode,? Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if(requestCode ==2){

if(data !=null){

uri = data.getData();

//path=uri.getPath();

? ? ? ? ? ? ? ? pathList.add(uri);

}

}

}

}

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容