編輯:關於Android編程
private void sendSMS(String message) { Uri smsToUri = Uri.parse("smsto:"); Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri); intent.putExtra("sms_body", message); mContext.startActivity(intent); mHandler.sendEmptyMessage(0); }
private void sendEmail(String title, String content) { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_SUBJECT, title); intent.putExtra(Intent.EXTRA_TEXT, content); intent.setType("message/rfc822"); mContext.startActivity(Intent.createChooser(intent, "請選擇郵件客戶端")); mHandler.sendEmptyMessage(0); }
ClipboardManager cm = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(mUrl);方法二,可復制文本、圖片、URI等等,代碼如下:
ClipboardManager cm = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE); ClipData data = ClipData.newPlainText("mUrl", mUrl); cm.setPrimaryClip(data);
import java.io.File; import java.util.ArrayList; import net.sourceforge.simcpux.R; import com.example.exmshare.util.Utils; import android.annotation.TargetApi; import android.content.ClipData; import android.content.ClipboardManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Handler; import android.util.Patterns; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; public class ItemSystemAdapter extends BaseAdapter implements OnItemClickListener { private LayoutInflater mInflater; private Context mContext; private Handler mHandler; private String mUrl; private String mTitle; private String mContent; private String mImageUrl; private ArrayListmChannelList; private int[] mShareIcons = {R.drawable.share_weixin, R.drawable.share_pengyou, R.drawable.share_qq, R.drawable.share_qzone, R.drawable.share_weibo, R.drawable.share_tweibo, R.drawable.share_sms, R.drawable.share_mail, R.drawable.share_copy}; public ItemSystemAdapter(final Context context, Handler handler, String url, String title, String content, final String imageUrl, ArrayList channelList) { mInflater = LayoutInflater.from(context); mContext = context; mHandler = handler; mUrl = url; mTitle = title; mContent = content; if (imageUrl!=null && Patterns.WEB_URL.matcher(imageUrl).matches()) { new Thread(new Runnable() { public void run() { try { mImageUrl = Utils.getImagePath(imageUrl, Utils.getFileCache(context)); } catch (Exception e) { e.printStackTrace(); } } }).start(); } else { mImageUrl = imageUrl; } if(channelList == null){ mChannelList = new ArrayList (); mChannelList.add(new ShareChanels("微信好友", 0, "com.tencent.mm.ui.tools.ShareImgUI", "com.tencent.mm")); mChannelList.add(new ShareChanels("微信朋友圈", 1, "com.tencent.mm.ui.tools.ShareToTimeLineUI", "com.tencent.mm")); mChannelList.add(new ShareChanels("QQ好友", 2, "com.tencent.mobileqq.activity.JumpActivity","com.tencent.mobileqq")); mChannelList.add(new ShareChanels("QQ空間", 3, "com.qzone.ui.operation.QZonePublishMoodActivity","com.qzone")); mChannelList.add(new ShareChanels("新浪微博", 4, "com.sina.weibo.EditActivity", "com.sina.weibo")); mChannelList.add(new ShareChanels("騰訊微博", 5, "com.tencent.WBlog.intentproxy.TencentWeiboIntent","com.tencent.WBlog")); mChannelList.add(new ShareChanels("發送短信", 6, "", "")); mChannelList.add(new ShareChanels("發送郵件", 7, "", "")); mChannelList.add(new ShareChanels("復制鏈接", 8, "", "")); }else{ mChannelList = channelList; } } @Override public int getCount() { return mChannelList.size(); } @Override public Object getItem(int position) { return mChannelList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.item_share_system, null); holder.tv_share_name = (TextView) convertView.findViewById(R.id.tv_share_name); holder.iv_share_icon = (ImageView) convertView.findViewById(R.id.iv_share_icon); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } ShareChanels item = mChannelList.get(position); holder.tv_share_name.setText(item.channelName); holder.iv_share_icon.setImageResource(mShareIcons[item.channelType]); return convertView; } public final class ViewHolder { public TextView tv_share_name; public ImageView iv_share_icon; } public static class ShareChanels { public String channelName; public int channelType; public String activityName; public String packageName; public ShareChanels(String name, int type, String activityName, String packageName) { this.channelName = name; this.channelType = type; this.activityName = activityName; this.packageName = packageName; } } @Override public void onItemClick(AdapterView parent, View view, int position, long id) { ShareChanels item = mChannelList.get(position); mHandler.sendEmptyMessageDelayed(0, 1500); if (item.channelType <= 5) { //朋友圈僅支持分享圖片 shareMsg(mContext, mTitle, mContent + mUrl, mImageUrl, item); } else if (item.channelType == 6) { sendSMS(mContent + mUrl); } else if (item.channelType == 7) { sendEmail(mTitle, mContent + mUrl); } else if (item.channelType == 8) { Toast.makeText(mContext, "成功復制鏈接", Toast.LENGTH_LONG).show(); ClipboardManager cm = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(mUrl); // ClipData data = ClipData.newPlainText("mUrl", mUrl); // cm.setPrimaryClip(data); } } private void sendSMS(String message) { Uri smsToUri = Uri.parse("smsto:"); Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri); intent.putExtra("sms_body", message); mContext.startActivity(intent); mHandler.sendEmptyMessage(0); } private void sendEmail(String title, String content) { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_SUBJECT, title); intent.putExtra(Intent.EXTRA_TEXT, content); intent.setType("message/rfc822"); mContext.startActivity(Intent.createChooser(intent, "請選擇郵件客戶端")); mHandler.sendEmptyMessage(0); } @TargetApi(Build.VERSION_CODES.GINGERBREAD) private void shareMsg(Context context, String msgTitle, String msgText, String imgPath, ShareChanels share) { if (!share.packageName.isEmpty() && !Utils.isAvailable(mContext, share.packageName)) { Toast.makeText(mContext, "請先安裝" + share.channelName.replace("好友", ""), Toast.LENGTH_SHORT).show(); return; } Intent intent = new Intent("android.intent.action.SEND"); if ((imgPath == null) || (imgPath.equals(""))) { intent.setType("text/plain"); } else { File f = new File(imgPath); if ((f != null) && (f.exists()) && (f.isFile())) { intent.setType("image/png"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); } } intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle); intent.putExtra(Intent.EXTRA_TEXT, msgText); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if(!share.packageName.isEmpty()) { intent.setComponent(new ComponentName(share.packageName, share.activityName)); context.startActivity(intent); } else { context.startActivity(Intent.createChooser(intent, msgTitle)); } } }
import java.io.File; import java.util.ArrayList; import net.sourceforge.simcpux.R; import com.example.exmshare.util.Utils; import android.annotation.TargetApi; import android.content.ClipData; import android.content.ClipboardManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Handler; import android.util.Patterns; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; public class ItemSystemAdapter extends BaseAdapter implements OnItemClickListener { private LayoutInflater mInflater; private Context mContext; private Handler mHandler; private String mUrl; private String mTitle; private String mContent; private String mImageUrl; private ArrayListmChannelList; private int[] mShareIcons = {R.drawable.share_weixin, R.drawable.share_pengyou, R.drawable.share_qq, R.drawable.share_qzone, R.drawable.share_weibo, R.drawable.share_tweibo, R.drawable.share_sms, R.drawable.share_mail, R.drawable.share_copy}; public ItemSystemAdapter(final Context context, Handler handler, String url, String title, String content, final String imageUrl, ArrayList channelList) { mInflater = LayoutInflater.from(context); mContext = context; mHandler = handler; mUrl = url; mTitle = title; mContent = content; if (imageUrl!=null && Patterns.WEB_URL.matcher(imageUrl).matches()) { new Thread(new Runnable() { public void run() { try { mImageUrl = Utils.getImagePath(imageUrl, Utils.getFileCache(context)); } catch (Exception e) { e.printStackTrace(); } } }).start(); } else { mImageUrl = imageUrl; } if(channelList == null){ mChannelList = new ArrayList (); mChannelList.add(new ShareChanels("微信好友", 0, "com.tencent.mm.ui.tools.ShareImgUI", "com.tencent.mm")); mChannelList.add(new ShareChanels("微信朋友圈", 1, "com.tencent.mm.ui.tools.ShareToTimeLineUI", "com.tencent.mm")); mChannelList.add(new ShareChanels("QQ好友", 2, "com.tencent.mobileqq.activity.JumpActivity","com.tencent.mobileqq")); mChannelList.add(new ShareChanels("QQ空間", 3, "com.qzone.ui.operation.QZonePublishMoodActivity","com.qzone")); mChannelList.add(new ShareChanels("新浪微博", 4, "com.sina.weibo.EditActivity", "com.sina.weibo")); mChannelList.add(new ShareChanels("騰訊微博", 5, "com.tencent.WBlog.intentproxy.TencentWeiboIntent","com.tencent.WBlog")); mChannelList.add(new ShareChanels("發送短信", 6, "", "")); mChannelList.add(new ShareChanels("發送郵件", 7, "", "")); mChannelList.add(new ShareChanels("復制鏈接", 8, "", "")); }else{ mChannelList = channelList; } } @Override public int getCount() { return mChannelList.size(); } @Override public Object getItem(int position) { return mChannelList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.item_share_system, null); holder.tv_share_name = (TextView) convertView.findViewById(R.id.tv_share_name); holder.iv_share_icon = (ImageView) convertView.findViewById(R.id.iv_share_icon); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } ShareChanels item = mChannelList.get(position); holder.tv_share_name.setText(item.channelName); holder.iv_share_icon.setImageResource(mShareIcons[item.channelType]); return convertView; } public final class ViewHolder { public TextView tv_share_name; public ImageView iv_share_icon; } public static class ShareChanels { public String channelName; public int channelType; public String activityName; public String packageName; public ShareChanels(String name, int type, String activityName, String packageName) { this.channelName = name; this.channelType = type; this.activityName = activityName; this.packageName = packageName; } } @Override public void onItemClick(AdapterView parent, View view, int position, long id) { ShareChanels item = mChannelList.get(position); mHandler.sendEmptyMessageDelayed(0, 1500); if (item.channelType <= 5) { //朋友圈僅支持分享圖片 shareMsg(mContext, mTitle, mContent + mUrl, mImageUrl, item); } else if (item.channelType == 6) { sendSMS(mContent + mUrl); } else if (item.channelType == 7) { sendEmail(mTitle, mContent + mUrl); } else if (item.channelType == 8) { Toast.makeText(mContext, "成功復制鏈接", Toast.LENGTH_LONG).show(); ClipboardManager cm = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(mUrl); // ClipData data = ClipData.newPlainText("mUrl", mUrl); // cm.setPrimaryClip(data); } } private void sendSMS(String message) { Uri smsToUri = Uri.parse("smsto:"); Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri); intent.putExtra("sms_body", message); mContext.startActivity(intent); mHandler.sendEmptyMessage(0); } private void sendEmail(String title, String content) { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_SUBJECT, title); intent.putExtra(Intent.EXTRA_TEXT, content); intent.setType("message/rfc822"); mContext.startActivity(Intent.createChooser(intent, "請選擇郵件客戶端")); mHandler.sendEmptyMessage(0); } @TargetApi(Build.VERSION_CODES.GINGERBREAD) private void shareMsg(Context context, String msgTitle, String msgText, String imgPath, ShareChanels share) { if (!share.packageName.isEmpty() && !Utils.isAvailable(mContext, share.packageName)) { Toast.makeText(mContext, "請先安裝" + share.channelName.replace("好友", ""), Toast.LENGTH_SHORT).show(); return; } Intent intent = new Intent("android.intent.action.SEND"); if ((imgPath == null) || (imgPath.equals(""))) { intent.setType("text/plain"); } else { File f = new File(imgPath); if ((f != null) && (f.exists()) && (f.isFile())) { intent.setType("image/png"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); } } intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle); intent.putExtra(Intent.EXTRA_TEXT, msgText); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if(!share.packageName.isEmpty()) { intent.setComponent(new ComponentName(share.packageName, share.activityName)); context.startActivity(intent); } else { context.startActivity(Intent.createChooser(intent, msgTitle)); } } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d(TAG, "-->onActivityResult " + requestCode + " resultCode=" + resultCode); if (requestCode==Constants.REQUEST_LOGIN || requestCode==Constants.REQUEST_APPBAR) { Tencent.onActivityResultData(requestCode,resultCode,data,ItemTencentAdapter.mLoginListener); } else if (requestCode==Constants.REQUEST_QQ_SHARE || requestCode==Constants.REQUEST_QZONE_SHARE) { Tencent.onActivityResultData(requestCode,resultCode,data,ItemTencentAdapter.mShareListener); } super.onActivityResult(requestCode, resultCode, data); }
import java.util.ArrayList; import org.json.JSONObject; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.os.Handler; import android.text.TextUtils; import android.util.Patterns; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Toast; import net.sourceforge.simcpux.R; import com.example.exmshare.util.Utils; import com.tencent.connect.common.Constants; import com.tencent.connect.share.QQShare; import com.tencent.connect.share.QzoneShare; import com.tencent.mm.sdk.modelmsg.SendMessageToWX; import com.tencent.mm.sdk.modelmsg.WXImageObject; import com.tencent.mm.sdk.modelmsg.WXMediaMessage; import com.tencent.mm.sdk.modelmsg.WXTextObject; import com.tencent.mm.sdk.modelmsg.WXWebpageObject; import com.tencent.mm.sdk.openapi.IWXAPI; import com.tencent.mm.sdk.openapi.WXAPIFactory; import com.tencent.open.t.Weibo; import com.tencent.tauth.IUiListener; import com.tencent.tauth.Tencent; import com.tencent.tauth.UiError; import com.umeng.socialize.utils.Log; public class ItemTencentAdapter extends BaseAdapter implements OnItemClickListener { private final static String TAG = "ItemTentcentAdapter"; private LayoutInflater mInflater; private static Context mContext; private Handler mHandler; private String mUrl; private String mTitle; private static String mContent; private static String mImageUrl; private ArrayListmChannelList; private final String QQ_APPID = "100330589"; //這裡替換為開發者在QQ互聯平台申請的應用id private static Tencent mTencent; private static Weibo mWeibo = null; private final String WX_APPID = "wxd930ea5d5a258f4f"; //這裡替換為開發者在微信開放平台申請的應用id private IWXAPI mWeixinApi; private int[] mShareIcons = {R.drawable.logo_wechat, R.drawable.logo_wechatcircle, R.drawable.logo_qq, R.drawable.logo_qzone, R.drawable.logo_tencentweibo}; public ItemTencentAdapter(final Context context, Handler handler, String url, String title, String content, final String imageUrl, ArrayList channelList) { mInflater = LayoutInflater.from(context); mContext = context; mHandler = handler; mUrl = url; mTitle = title; mContent = content; if (imageUrl!=null && Patterns.WEB_URL.matcher(imageUrl).matches()) { new Thread(new Runnable() { public void run() { try { mImageUrl = Utils.getImagePath(imageUrl, Utils.getFileCache(context)); } catch (Exception e) { e.printStackTrace(); } } }).start(); } else { mImageUrl = imageUrl; } if (channelList == null) { mChannelList = new ArrayList (); mChannelList.add(new ShareChanels("微信好友", 0)); mChannelList.add(new ShareChanels("微信朋友圈", 1)); mChannelList.add(new ShareChanels("QQ好友", 2)); mChannelList.add(new ShareChanels("QQ空間", 3)); mChannelList.add(new ShareChanels("騰訊微博", 4)); } else { mChannelList = channelList; } // 創建一個QQ實例,用於QQ分享、QQ空間分享、騰訊微博分享 mTencent = Tencent.createInstance(QQ_APPID, mContext); // 將該app注冊到微信,用於微信分享、微信朋友圈分享 mWeixinApi = WXAPIFactory.createWXAPI(mContext, null); mWeixinApi.registerApp(WX_APPID); mWeixinApi = WXAPIFactory.createWXAPI(mContext, WX_APPID); } @Override public int getCount() { return mChannelList.size(); } @Override public Object getItem(int position) { return mChannelList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.item_share_system, null); holder.tv_share_name = (TextView) convertView.findViewById(R.id.tv_share_name); holder.iv_share_icon = (ImageView) convertView.findViewById(R.id.iv_share_icon); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } ShareChanels item = mChannelList.get(position); holder.tv_share_name.setText(item.channelName); holder.tv_share_name.setPadding(0, 0, 0, 0); holder.iv_share_icon.setImageResource(mShareIcons[item.channelType]); return convertView; } public final class ViewHolder { public TextView tv_share_name; public ImageView iv_share_icon; } public static class ShareChanels { public String channelName; public int channelType; public ShareChanels(String name, int type) { this.channelName = name; this.channelType = type; } } public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { ShareChanels item = mChannelList.get(arg2); mHandler.sendEmptyMessageDelayed(0, 1500); if (item.channelType == 0) { SendMessageToWX.Req req = new SendMessageToWX.Req(); // transaction字段用於唯一標識一個請求 req.transaction = "wx_share" + System.currentTimeMillis(); req.message = getWXMessage(); req.scene = SendMessageToWX.Req.WXSceneSession; mWeixinApi.sendReq(req); } else if (item.channelType == 1) { SendMessageToWX.Req req = new SendMessageToWX.Req(); req.transaction = "wx_share" + System.currentTimeMillis(); req.message = getWXMessage(); req.scene = SendMessageToWX.Req.WXSceneTimeline; mWeixinApi.sendReq(req); } else if (item.channelType == 2) { mShareListener = new ShareQQListener(mContext, item.channelName); Bundle params = new Bundle(); params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT); params.putString(QQShare.SHARE_TO_QQ_TITLE, mTitle); params.putString(QQShare.SHARE_TO_QQ_SUMMARY, mContent); params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, mUrl); params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, mImageUrl); params.putString(QQShare.SHARE_TO_QQ_APP_NAME, mContext.getPackageName()); mTencent.shareToQQ((Activity) mContext, params, mShareListener); } else if (item.channelType == 3) { mShareListener = new ShareQQListener(mContext, item.channelName); ArrayList urlList = new ArrayList (); urlList.add(mImageUrl); Bundle params = new Bundle(); params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE,QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT ); params.putString(QzoneShare.SHARE_TO_QQ_TITLE, mTitle); params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, mContent); params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL, mUrl); params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL, urlList); mTencent.shareToQzone((Activity) mContext, params, mShareListener); } else if (item.channelType == 4) { // 騰訊微博分享需要QQ登錄授權 mTencent.login((Activity) mContext, "all", mLoginListener); } } private int THUMB_SIZE = 150; private WXMediaMessage getWXMessage() { WXMediaMessage msg = new WXMediaMessage(); if (!TextUtils.isEmpty(mTitle) && TextUtils.isEmpty(mImageUrl)) { // 分享文本消息 WXTextObject textObj = new WXTextObject(); textObj.text = mContent; msg.mediaObject = textObj; msg.title = mTitle; msg.description = mContent; } else if (TextUtils.isEmpty(mTitle) && !TextUtils.isEmpty(mImageUrl)) { // 分享圖片消息 // WXImageObject imgObj = new WXImageObject(); // imgObj.setImagePath(mImageUrl); Bitmap bmp = BitmapFactory.decodeFile(mImageUrl); WXImageObject imgObj = new WXImageObject(bmp); msg.mediaObject = imgObj; Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true); msg.thumbData = Utils.bmpToByteArray(thumbBmp, true); // 設置縮略圖 } else if (!TextUtils.isEmpty(mTitle) && !TextUtils.isEmpty(mImageUrl)) { // 分享圖文消息 WXWebpageObject webpage = new WXWebpageObject(); webpage.webpageUrl = mUrl; msg.title = mTitle; msg.description = mContent; msg.mediaObject = webpage; Bitmap bmp = BitmapFactory.decodeFile(mImageUrl); Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true); msg.thumbData = Utils.bmpToByteArray(thumbBmp, true); // 設置縮略圖 } return msg; } public static final int REQUEST_ADD_PIC_T = 1001; public static IUiListener mLoginListener = new IUiListener() { @Override public void onComplete(Object object) { Log.d(TAG, "登錄完成:"+object.toString()); try { JSONObject jsonObject = (JSONObject)object; String token = jsonObject.getString(Constants.PARAM_ACCESS_TOKEN); String expires = jsonObject.getString(Constants.PARAM_EXPIRES_IN); String openId = jsonObject.getString(Constants.PARAM_OPEN_ID); if (!TextUtils.isEmpty(token) && !TextUtils.isEmpty(expires) && !TextUtils.isEmpty(openId)) { mTencent.setAccessToken(token, expires); mTencent.setOpenId(openId); mWeibo = new Weibo(mContext, mTencent.getQQToken()); if (mImageUrl==null || mImageUrl.length()<=0) { mWeibo.sendText(mContent, new ShareQQListener(mContext, "微博文字")); } else { mWeibo.sendPicText(mContent, mImageUrl, new ShareQQListener(mContext, "微博圖文")); } } } catch (Exception e) { Log.d(TAG, "登錄異常:"+e.getMessage()); } } @Override public void onError(UiError error) { Log.d(TAG, "登錄失敗:"+error.errorMessage); } @Override public void onCancel() { Log.d(TAG, "登錄取消"); } }; public static ShareQQListener mShareListener; private static class ShareQQListener implements IUiListener { private Context context; private String channelName; public ShareQQListener(final Context context, final String channelName) { this.context = context; this.channelName = channelName; } @Override public void onComplete(Object object) { Toast.makeText(context, channelName+"分享完成:"+object.toString(), Toast.LENGTH_LONG).show(); } @Override public void onError(UiError error) { Toast.makeText(context, channelName+"分享失敗:"+error.errorMessage, Toast.LENGTH_LONG).show(); } @Override public void onCancel() { Toast.makeText(context, channelName+"分享取消", Toast.LENGTH_LONG).show(); } } }
一.功能描述銀聯支付流程如下所示:拷貝upmp_android/sdkPro/jar/data.bin到工程的assets文件夾中;拷貝upmp_android/sdkP
自定義View學習的最後一期了,先上效果圖。 相信大家心中都有自己的實現方法,這裡就貼上我的方法以供參考。/** * 刻度畫筆 */ private P
之前幫別人寫了一個不是那麼優美的圓形進度條,效果圖大家也看過了。但是後某人不滿意,說原應用是倒計時時間最後5s,才開始顯示數字的,同時轉完一圈需要的時間只能是30s左右。
本文將向大家展示如何拍照截圖。先看看效果圖:拍照截圖有點兒特殊,要知道,現在的Android智能手機的攝像頭都是幾百萬的像素,拍出來的圖片都是非常大的。因此,我們不能像對