### Initialize Supported Social Platforms Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt This code initializes a list of supported social media platforms for sharing. It includes platforms like WeChat, Weibo, QQ, and international options. Ensure all necessary platform SDKs are integrated before using these. ```java public class SharePlatformActivity extends BaseActivity { public ArrayList platforms = new ArrayList(); private void initPlatforms() { platforms.clear(); // 微信系列 platforms.add(SHARE_MEDIA.WEIXIN.toSnsPlatform()); // 微信好友 platforms.add(SHARE_MEDIA.WEIXIN_CIRCLE.toSnsPlatform()); // 微信朋友圈 platforms.add(SHARE_MEDIA.WEIXIN_FAVORITE.toSnsPlatform()); // 微信收藏 platforms.add(SHARE_MEDIA.WXWORK.toSnsPlatform()); // 企业微信 // 微博 platforms.add(SHARE_MEDIA.SINA.toSnsPlatform()); // 新浪微博 // QQ系列 platforms.add(SHARE_MEDIA.QQ.toSnsPlatform()); // QQ好友 platforms.add(SHARE_MEDIA.QZONE.toSnsPlatform()); // QQ空间 // 支付宝和钉钉 platforms.add(SHARE_MEDIA.ALIPAY.toSnsPlatform()); // 支付宝 platforms.add(SHARE_MEDIA.DINGTALK.toSnsPlatform()); // 钉钉 // 字节跳动 platforms.add(SHARE_MEDIA.BYTEDANCE.toSnsPlatform()); // 抖音 platforms.add(SHARE_MEDIA.BYTEDANCE_PUBLISH.toSnsPlatform()); // 抖音发布 platforms.add(SHARE_MEDIA.BYTEDANCE_FRIENDS.toSnsPlatform()); // 抖音好友 // 国际平台 platforms.add(SHARE_MEDIA.FACEBOOK.toSnsPlatform()); platforms.add(SHARE_MEDIA.FACEBOOK_MESSAGER.toSnsPlatform()); platforms.add(SHARE_MEDIA.TWITTER.toSnsPlatform()); platforms.add(SHARE_MEDIA.WHATSAPP.toSnsPlatform()); platforms.add(SHARE_MEDIA.LINE.toSnsPlatform()); platforms.add(SHARE_MEDIA.INSTAGRAM.toSnsPlatform()); platforms.add(SHARE_MEDIA.LINKEDIN.toSnsPlatform()); platforms.add(SHARE_MEDIA.PINTEREST.toSnsPlatform()); // 更多平台 platforms.add(SHARE_MEDIA.SMS.toSnsPlatform()); // 短信 platforms.add(SHARE_MEDIA.EMAIL.toSnsPlatform()); // 邮件 platforms.add(SHARE_MEDIA.DOUBAN.toSnsPlatform()); // 豆瓣 platforms.add(SHARE_MEDIA.YIXIN.toSnsPlatform()); // 易信 platforms.add(SHARE_MEDIA.KAKAO.toSnsPlatform()); // Kakao platforms.add(SHARE_MEDIA.VKONTAKTE.toSnsPlatform()); // VK platforms.add(SHARE_MEDIA.DROPBOX.toSnsPlatform()); // Dropbox platforms.add(SHARE_MEDIA.MORE.toSnsPlatform()); // 系统分享 } } ``` -------------------------------- ### Share Mini-Programs with U-Share Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Use UMMin for WeChat mini-programs and UMQQMini for QQ mini-programs. Ensure the correct path and ID are provided for the target mini-program. ```java // 微信小程序分享 public void shareMINApp() { UMMin umMin = new UMMin("http://mobile.umeng.com/social"); umMin.setThumb(new UMImage(this, R.drawable.thumb)); umMin.setTitle("【友盟+】社会化组件U-Share"); umMin.setDescription("欢迎使用友盟社会化分享"); umMin.setPath("pages/page10007/page10007"); // 小程序页面路径 umMin.setUserName("gh_3ac2059ac66f"); // 小程序原始ID new ShareAction(ShareDetailActivity.this) .withMedia(umMin) .setPlatform(share_media) .setCallback(shareListener) .share(); } // QQ小程序分享 public void shareQQMiniApp() { UMQQMini qqMini = new UMQQMini("http://mobile.umeng.com/social"); qqMini.setThumb(new UMImage(this, "https://img.alicdn.com/example.jpg")); qqMini.setTitle("【友盟+】社会化组件U-Share"); qqMini.setDescription("欢迎使用友盟社会化分享"); qqMini.setMiniAppId("1110429485"); // QQ小程序AppID qqMini.setPath("pages/index/index"); // 小程序页面路径 new ShareAction(ShareDetailActivity.this) .withMedia(qqMini) .setPlatform(share_media) .setCallback(shareListener) .share(); } ``` -------------------------------- ### Share Music Link with Umeng SDK Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Share a music link including title, thumbnail, description, and target URL. Ensure the music object is properly initialized. ```java public void shareMusic() { UMusic music = new UMusic("https://y.qq.com/n/yqq/song/108782194_num.html"); music.setTitle("This is music title"); music.setThumb(new UMImage(this, R.drawable.thumb)); music.setDescription("my description"); music.setmTargetUrl("https://y.qq.com/n/yqq/song/108782194_num.html"); new ShareAction(ShareDetailActivity.this) .withMedia(music) .setPlatform(share_media) .setCallback(shareListener) .share(); } ``` -------------------------------- ### Share Web Link with Umeng SDK Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Share a web link with title, description, and thumbnail. Ensure the Umeng SDK and necessary permissions are configured. ```java public void shareUrl() { UMWeb web = new UMWeb("http://mobile.umeng.com/social"); web.setTitle("This is web title"); web.setThumb(new UMImage(this, R.drawable.thumb)); web.setDescription("my description"); new ShareAction(ShareDetailActivity.this) .withMedia(web) .setPlatform(share_media) .setCallback(shareListener) .share(); } ``` -------------------------------- ### Complete Umeng SDK Initialization Configuration Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Initializes all Umeng SDK components including the base library, social platform configurations, and push services. This class should be called after the user agrees to the privacy policy. ```java public class UmInitConfig { public void UMinit(Context context) { // 初始化组件化基础库, 统计SDK/推送SDK/分享SDK都必须调用此初始化接口 // 参数:context, AppKey, Channel, 设备类型, Push消息密钥 UMConfigure.init(context, "59892f08310c9307b60023d0", "Umeng", UMConfigure.DEVICE_TYPE_PHONE, "669c30a9584623e70e8cd01b0381dcb4"); // 配置FileProvider (分享图片、文件需要) String fileProvider = "com.umeng.soexample.fileprovider"; PlatformConfig.setFileProvider(fileProvider); // 微信配置 PlatformConfig.setWeixin("wxdc1e388c3822c80b", "3baf1193c85774b3fd9d18447d76cab0"); // 企业微信配置 PlatformConfig.setWXWork("wwac6ffb259ff6f66a", "EU1LRsWC5uWn6KUuYOiWUpkoH45eOA0yH-ngL8579zs", "1000002", "wwauthac6ffb259ff6f66a000002"); // 字节跳动配置 PlatformConfig.setBytedance("awd1cemo6d0l69zp", "awd1cemo6d0l69zp", "a2dce41fff214270dd4a7f60ac885491", fileProvider); // 新浪微博配置 PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad", "http://sns.whalecloud.com"); // QQ和QQ空间配置 PlatformConfig.setQQZone("101830139", "5d63ae8858f1caab67715ccd6c18d7a5"); // Twitter配置 PlatformConfig.setTwitter("3aIN7fuF685MuZ7jtXkQxalyi", "MK6FEYG63eWcpDFgRYw4w9puJhzDl0tyuqWjZ3M7XJuuG7mMbO"); // 支付宝配置 PlatformConfig.setAlipay("2015111700822536"); // 钉钉配置 PlatformConfig.setDing("dingoalmlnohc0wggfedpk"); // 更多平台... PlatformConfig.setPinterest("1439206"); PlatformConfig.setKakao("e4f60e065048eb031e235c806b31c70f"); PlatformConfig.setVKontakte("5764965", "5My6SNliAaLxEm3Lyd9J"); PlatformConfig.setDropbox("oz8v5apet3arcdy", "h7p2pjbzkkxt02a"); PlatformConfig.setHonor("104408749", "fb1d1d0320a0f661cb1c22892622501f3affceeafb625a5646f299a04c1602ec"); // 集成umeng-crash时,关闭原有统计SDK异常捕获功能 MobclickAgent.setCatchUncaughtExceptions(false); // 推送SDK初始化 initUpush(context); // 统计SDK支持多进程打点 UMConfigure.setProcessEvent(true); // 页面数据采集模式 (AUTO模式自动采集Activity页面访问) MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO); } } ``` -------------------------------- ### 初始化友盟推送SDK Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt 在应用启动时调用此方法以配置推送功能,包括消息处理、通知样式自定义及设备注册。 ```java private void initUpush(Context context) { PushAgent pushAgent = PushAgent.getInstance(context); handler = new Handler(getMainLooper()); // SDK开启通知声音 pushAgent.setNotificationPlaySound(MsgConstant.NOTIFICATION_PLAY_SDK_ENABLE); // 可选: 关闭通知声音 // pushAgent.setNotificationPlaySound(MsgConstant.NOTIFICATION_PLAY_SDK_DISABLE); // 可选: 通知声音由服务端控制 // pushAgent.setNotificationPlaySound(MsgConstant.NOTIFICATION_PLAY_SERVER); // 设置消息处理器 UmengMessageHandler messageHandler = new UmengMessageHandler() { // 通知的回调方法(通知送达时会回调) @Override public void dealWithNotificationMessage(Context context, UMessage msg) { // 调用super,会展示通知,不调用super,则不展示通知 super.dealWithNotificationMessage(context, msg); } // 自定义消息的回调方法 @Override public void dealWithCustomMessage(final Context context, final UMessage msg) { handler.post(new Runnable() { @Override public void run() { boolean isClickOrDismissed = true; if (isClickOrDismissed) { // 自定义消息的点击统计 UTrack.getInstance().trackMsgClick(msg); } else { // 自定义消息的忽略统计 UTrack.getInstance().trackMsgDismissed(msg); } Toast.makeText(context, msg.custom, Toast.LENGTH_LONG).show(); } }); } // 自定义通知栏样式 @Override public Notification getNotification(Context context, UMessage msg) { switch (msg.builder_id) { case 1: Notification.Builder builder; if (Build.VERSION.SDK_INT >= 26) { NotificationChannel channel = UPushNotificationChannel.getDefaultMode(context); builder = new Notification.Builder(context, channel.getId()); } else { builder = new Notification.Builder(context); } RemoteViews myNotificationView = new RemoteViews( context.getPackageName(), R.layout.notification_view); myNotificationView.setTextViewText(R.id.notification_title, msg.title); myNotificationView.setTextViewText(R.id.notification_text, msg.text); myNotificationView.setImageViewBitmap(R.id.notification_large_icon, getLargeIcon(context, msg)); myNotificationView.setImageViewResource(R.id.notification_small_icon, getSmallIconId(context, msg)); builder.setContent(myNotificationView) .setSmallIcon(getSmallIconId(context, msg)) .setTicker(msg.ticker) .setAutoCancel(true); return builder.getNotification(); default: return super.getNotification(context, msg); } } }; pushAgent.setMessageHandler(messageHandler); // 自定义通知点击行为 UmengNotificationClickHandler notificationClickHandler = new UmengNotificationClickHandler() { @Override public void launchApp(Context context, UMessage msg) { super.launchApp(context, msg); } @Override public void openUrl(Context context, UMessage msg) { super.openUrl(context, msg); } @Override public void openActivity(Context context, UMessage msg) { super.openActivity(context, msg); } @Override public void dealWithCustomAction(Context context, UMessage msg) { Toast.makeText(context, msg.custom, Toast.LENGTH_LONG).show(); } }; pushAgent.setNotificationClickHandler(notificationClickHandler); // 注册推送服务 pushAgent.register(new UPushRegisterCallback() { @Override public void onSuccess(String deviceToken) { Log.i(TAG, "device token: " + deviceToken); context.sendBroadcast(new Intent(UPDATE_STATUS_ACTION)); } @Override public void onFailure(String s, String s1) { Log.i(TAG, "register failed: " + s + " " + s1); context.sendBroadcast(new Intent(UPDATE_STATUS_ACTION)); } }); } ``` -------------------------------- ### Share Online Video with Umeng SDK Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Share an online video link with thumbnail, title, and description. The video URL should point to a playable video resource. ```java // 分享网络视频 public void shareVideo() { UMVideo video = new UMVideo("http://video.sina.com.cn/example.html"); video.setThumb(new UMImage(this, R.drawable.thumb)); video.setTitle("This is video title"); video.setDescription("my description"); new ShareAction(ShareDetailActivity.this) .withMedia(video) .setPlatform(share_media) .setCallback(shareListener) .share(); } ``` -------------------------------- ### Share Local Video with Umeng SDK Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Share a local video file. This involves copying the video from assets to external storage and then creating a UMVideo object from the file path. Ensure file writing permissions are handled. ```java // 分享本地视频 public void shareLocalVideo() { String umengCacheDir = this.getExternalFilesDir(null) + File.separator + "umeng_cache"; File dir = new File(umengCacheDir); if (!dir.exists()) { dir.mkdir(); } // 从assets复制视频到外部存储 String localVideoFileName = "localvideo.mp4"; AssetManager am = this.getAssets(); try { InputStream is = am.open(localVideoFileName); writeFile(umengCacheDir + File.separator + localVideoFileName, is); File videoFile = new File(umengCacheDir + File.separator + localVideoFileName); UMVideo localVideo = new UMVideo(videoFile); new ShareAction(ShareDetailActivity.this) .withMedia(localVideo) .withText("本地视频分享") .setPlatform(share_media) .setCallback(shareListener) .share(); } catch (Exception e) { e.printStackTrace(); } } ``` -------------------------------- ### Umeng SDK Pre-initialization in Application Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Pre-initializes the Umeng SDK in the Application's onCreate method before user privacy agreement. It sets the log level and checks for prior agreement to perform formal initialization. ```java public class App extends Application { SharedPreferencesHelper sharedPreferencesHelper; @Override public void onCreate() { super.onCreate(); sharedPreferencesHelper = new SharedPreferencesHelper(this, "umeng"); // 设置LOG开关,默认为false UMConfigure.setLogEnabled(true); // 友盟预初始化 (在隐私协议同意前调用) UMConfigure.preInit(getApplicationContext(), "59892f08310c9307b60023d0", "Umeng"); // 判断是否同意隐私协议,uminit为1时为已经同意,直接初始化 if (sharedPreferencesHelper.getSharedPreference("uminit", "").equals("1")) { // 友盟正式初始化 UmInitConfig umInitConfig = new UmInitConfig(); umInitConfig.UMinit(getApplicationContext()); // QQ官方sdk授权 Tencent.setIsPermissionGranted(true); } } } ``` -------------------------------- ### Retrieve All User Tags - Umeng Push SDK Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Fetches all tags currently associated with users. The result is a list of strings, which should be handled appropriately, especially if the list is null or empty. ```java mPushAgent.getTagManager().getTags(new UPushTagCallback>() { @Override public void onMessage(final boolean isSuccess, final List result) { handler.post(new Runnable() { @Override public void run() { if (isSuccess && result != null) { StringBuilder info = new StringBuilder(); for (int i = 0; i < result.size(); i++) { info.append(result.get(i)); if (i != result.size() - 1) { info.append("、"); } } // 显示标签列表 showTagsDialog(info.toString()); } } }); } }); ``` -------------------------------- ### Track User Account Events Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Use these methods to record user sign-in and sign-off events for behavior tracking. ```java // 用户登录统计 findViewById(R.id.analytics_g2_b1).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MobclickAgent.onProfileSignIn("example_id"); Toast.makeText(mContext, "已完成用户登录", Toast.LENGTH_SHORT).show(); } }); // 用户登出统计 findViewById(R.id.analytics_g2_b2).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MobclickAgent.onProfileSignOff(); Toast.makeText(mContext, "已完成用户登出", Toast.LENGTH_SHORT).show(); } }); ``` -------------------------------- ### 管理推送别名 (Alias) Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt 包含添加、设置(覆盖)和删除别名的操作方法。所有操作均需通过UPushAliasCallback回调处理结果。 ```java // 添加别名 private void addAlias() { String alias = inputAlias.getText().toString(); String aliasType = inputAliasType.getText().toString(); if (TextUtils.isEmpty(alias)) { Toast.makeText(this, "请先输入alias", Toast.LENGTH_SHORT).show(); return; } if (TextUtils.isEmpty(aliasType)) { Toast.makeText(this, "请先输入alias type", Toast.LENGTH_SHORT).show(); return; } mPushAgent.addAlias(alias, aliasType, new UPushAliasCallback() { @Override public void onMessage(boolean isSuccess, String message) { handler.post(new Runnable() { @Override public void run() { inputAlias.setText(""); inputAliasType.setText(""); if (isSuccess) { Toast.makeText(context, "添加别名成功", Toast.LENGTH_SHORT).show(); } } }); } }); } // 设置别名 (会覆盖之前的别名) private void setAlias() { String alias = inputAlias.getText().toString(); String aliasType = inputAliasType.getText().toString(); if (TextUtils.isEmpty(alias) || TextUtils.isEmpty(aliasType)) { Toast.makeText(this, "请输入alias和alias type", Toast.LENGTH_SHORT).show(); return; } mPushAgent.setAlias(alias, aliasType, new UPushAliasCallback() { @Override public void onMessage(boolean isSuccess, String message) { handler.post(new Runnable() { @Override public void run() { inputAlias.setText(""); inputAliasType.setText(""); } }); } }); } // 删除别名 private void deleteAlias() { String alias = inputAlias.getText().toString(); String aliasType = inputAliasType.getText().toString(); if (TextUtils.isEmpty(alias) || TextUtils.isEmpty(aliasType)) { Toast.makeText(this, "请输入alias和alias type", Toast.LENGTH_SHORT).show(); return; } mPushAgent.deleteAlias(alias, aliasType, new UPushAliasCallback() { @Override public void onMessage(boolean isSuccess, String message) { handler.post(new Runnable() { @Override public void run() { inputAlias.setText(""); inputAliasType.setText(""); if (isSuccess) { Toast.makeText(context, "删除别名成功", Toast.LENGTH_SHORT).show(); } } }); } }); } ``` -------------------------------- ### Share Network Image Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt This method demonstrates sharing an image from a network URL. Similar to local image sharing, a thumbnail can be set. The ShareAction is used, and a UMShareListener handles the sharing callbacks. ```java // 分享网络图片 public void shareImageNet() { UMImage imageurl = new UMImage(this, "https://img.alicdn.com/example.jpg"); imageurl.setThumb(new UMImage(this, R.drawable.thumb)); new ShareAction(ShareDetailActivity.this) .withMedia(imageurl) .setPlatform(share_media) .setCallback(shareListener) .share(); } ``` -------------------------------- ### Manage Preset Event Properties Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Methods for registering, unregistering, retrieving, and clearing global properties that are automatically attached to subsequent events. ```java // 注册预置属性 findViewById(R.id.analytics_g5_b1).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { JSONObject pre = new JSONObject(); try { pre.put("PreProperties-key1", "PreProperties-value1"); pre.put("PreProperties-key2", "PreProperties-value2"); pre.put("PreProperties-key3", "PreProperties-value3"); } catch (JSONException e) { e.printStackTrace(); } MobclickAgent.registerPreProperties(mContext, pre); Toast.makeText(mContext, "预置属性已注册", Toast.LENGTH_SHORT).show(); } }); // 注销部分预置属性 findViewById(R.id.analytics_g5_b2).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MobclickAgent.unregisterPreProperty(mContext, "PreProperties-key1"); MobclickAgent.unregisterPreProperty(mContext, "PreProperties-key3"); Toast.makeText(mContext, "预置属性已部分注销", Toast.LENGTH_SHORT).show(); } }); // 获取当前预置属性 findViewById(R.id.analytics_g5_b3).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { JSONObject preProperties = MobclickAgent.getPreProperties(mContext); if (preProperties != null && preProperties.length() > 0) { Toast.makeText(mContext, "当前预置属性: " + preProperties.toString(), Toast.LENGTH_SHORT).show(); } } }); // 清空所有预置属性 findViewById(R.id.analytics_g5_b4).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MobclickAgent.clearPreProperties(mContext); Toast.makeText(mContext, "预置属性已清空", Toast.LENGTH_SHORT).show(); } }); ``` -------------------------------- ### Handle Privacy Policy Authorization in Android Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Implement a splash activity that checks for privacy consent before initializing Umeng SDK components. Use SharedPreferences to persist the user's decision and trigger SDK initialization accordingly. ```java public class SplashTestActivity extends UmengSplashMessageActivity { SharedPreferencesHelper sharedPreferencesHelper; @Override public boolean onCustomPretreatment() { sharedPreferencesHelper = new SharedPreferencesHelper(this, "umeng"); if (sharedPreferencesHelper.getSharedPreference("uminit", "").equals("1")) { // 已同意隐私协议,配置推送全屏消息 InAppMessageManager mInAppMessageManager = InAppMessageManager.getInstance(this); mInAppMessageManager.setInAppMsgDebugMode(true); mInAppMessageManager.setMainActivityPath("com.umeng.soexample.HomeActivity"); // 推送平台多维度推送决策必须调用方法 PushAgent.getInstance(this).onAppStart(); return super.onCustomPretreatment(); } else { // 显示隐私协议授权弹窗 showPrivacyDialog(); return true; } } private void showPrivacyDialog() { Dialog dialog = new Dialog(this, R.style.dialog); View inflate = LayoutInflater.from(this).inflate(R.layout.diaologlayout, null); // 同意按钮 TextView successBtn = (TextView) inflate.findViewById(R.id.succsebtn); successBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 记录授权状态 sharedPreferencesHelper.put("uminit", "1"); UMConfigure.submitPolicyGrantResult(getApplicationContext(), true); // 友盟SDK正式初始化 UmInitConfig umInitConfig = new UmInitConfig(); umInitConfig.UMinit(getApplicationContext()); // QQ官方SDK授权 Tencent.setIsPermissionGranted(true); // 推送决策调用 PushAgent.getInstance(SplashTestActivity.this).onAppStart(); dialog.dismiss(); startActivity(new Intent(SplashTestActivity.this, HomeActivity.class)); finish(); } }); // 拒绝按钮 TextView cancelBtn = (TextView) inflate.findViewById(R.id.caclebtn); cancelBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); UMConfigure.submitPolicyGrantResult(getApplicationContext(), false); android.os.Process.killProcess(android.os.Process.myPid()); } }); dialog.setContentView(inflate); dialog.setCancelable(false); dialog.show(); } } ``` -------------------------------- ### Add Tag to User - Umeng Push SDK Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Use this method to add a tag to a user. Ensure a tag is provided and handle the success or failure of the operation. ```java mPushAgent.getTagManager().addTags(new UPushTagCallback() { @Override public void onMessage(final boolean isSuccess, final ITagManager.Result result) { handler.post(new Runnable() { @Override public void run() { inputTag.setText(""); if (isSuccess) { tagRemain.setText(String.valueOf(result.remain)); Toast.makeText(context, "添加成功", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(context, "添加失败", Toast.LENGTH_SHORT).show(); } } }); } }, tag); ``` -------------------------------- ### Share Emojis and Local Files Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Use UMEmoji for GIF sharing and ShareAction.withFile for local file sharing. Ensure the file exists before attempting to share it. ```java // 分享表情 public void shareEmoji() { UMEmoji emoji = new UMEmoji(this, R.drawable.tutu); emoji.setThumb(new UMImage(this, R.drawable.thumb)); new ShareAction(ShareDetailActivity.this) .withMedia(emoji) .setPlatform(share_media) .setCallback(shareListener) .share(); } // 分享本地文件 public void shareLocalFile() { String umengCacheDir = this.getExternalFilesDir(null) + File.separator + "umeng_cache"; File dir = new File(umengCacheDir); if (!dir.exists()) { dir.mkdir(); } String localFilePath = umengCacheDir + File.separator + "localFile.txt"; File localfile = new File(localFilePath); if (!localfile.exists()) { try { localfile.createNewFile(); String content = "U-share分享"; FileOutputStream fop = new FileOutputStream(localfile); fop.write(content.getBytes()); fop.flush(); fop.close(); } catch (IOException e) { e.printStackTrace(); } } new ShareAction(ShareDetailActivity.this) .withFile(localfile) .withText("文件分享测试") .withSubject("【友盟+】社会化组件U-Share") .setPlatform(share_media) .setCallback(shareListener) .share(); } ``` -------------------------------- ### Share Local Image Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt This method shows how to share a local image to a social platform. A thumbnail can also be set for the shared image. The sharing process uses ShareAction and requires a UMShareListener for callbacks. ```java // 分享本地图片 public void shareImageLocal() { UMImage imagelocal = new UMImage(this, R.drawable.logo); imagelocal.setThumb(new UMImage(this, R.drawable.thumb)); new ShareAction(ShareDetailActivity.this) .withMedia(imagelocal) .setPlatform(share_media) .setCallback(shareListener) .share(); } ``` -------------------------------- ### Share Text Content Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt This method demonstrates how to share plain text content to a specified social platform using the ShareAction. A UMShareListener is required to handle the callback events for the sharing operation. ```java public void shareText() { new ShareAction(ShareDetailActivity.this) .withText("欢迎使用【友盟+】社会化组件U-Share,SDK包最小,集成成本最低") .setPlatform(share_media) .setCallback(shareListener) .share(); } ``` ```java // 分享回调监听 private UMShareListener shareListener = new UMShareListener() { @Override public void onStart(SHARE_MEDIA platform) { // 分享开始 SocializeUtils.safeShowDialog(dialog); } @Override public void onResult(SHARE_MEDIA platform) { // 分享成功 Toast.makeText(context, "成功了", Toast.LENGTH_LONG).show(); SocializeUtils.safeCloseDialog(dialog); } @Override public void onError(SHARE_MEDIA platform, Throwable t) { // 分享失败 SocializeUtils.safeCloseDialog(dialog); Toast.makeText(context, "失败: " + t.getMessage(), Toast.LENGTH_LONG).show(); } @Override public void onCancel(SHARE_MEDIA platform) { // 分享取消 SocializeUtils.safeCloseDialog(dialog); Toast.makeText(context, "取消了", Toast.LENGTH_LONG).show(); } }; ``` -------------------------------- ### OAuth Authorization with Umeng Share SDK Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Handles OAuth authorization, checking authorization status, and deleting authorization for third-party platforms using Umeng's Share SDK. Requires implementing UMAuthListener for callbacks. ```java public class AuthAdapter extends BaseAdapter { private UMShareAPI umShareAPI; // 检查是否已授权 public boolean isAuthorized(Activity activity, SHARE_MEDIA platform) { return UMShareAPI.get(mContext).isAuthorize(activity, platform); } // 执行授权 public void doAuthorize(Activity activity, SHARE_MEDIA platform) { UMShareAPI.get(mContext).doOauthVerify(activity, platform, authListener); } // 删除授权 public void deleteAuthorize(Activity activity, SHARE_MEDIA platform) { UMShareAPI.get(mContext).deleteOauth(activity, platform, authListener); } // 授权回调监听 UMAuthListener authListener = new UMAuthListener() { @Override public void onStart(SHARE_MEDIA platform) { SocializeUtils.safeShowDialog(dialog); } @Override public void onComplete(SHARE_MEDIA platform, int action, Map data) { SocializeUtils.safeCloseDialog(dialog); // data包含用户信息: uid, name, iconurl等 mActivity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(mContext, "授权成功", Toast.LENGTH_LONG).show(); notifyDataSetChanged(); } }); } @Override public void onError(SHARE_MEDIA platform, int action, Throwable t) { SocializeUtils.safeCloseDialog(dialog); mActivity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(mContext, "失败:" + t.getMessage(), Toast.LENGTH_LONG).show(); } }); } @Override public void onCancel(SHARE_MEDIA platform, int action) { SocializeUtils.safeCloseDialog(dialog); mActivity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(mContext, "取消了", Toast.LENGTH_LONG).show(); } }); } }; } ``` ```java // 在Activity中处理授权回调 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data); } @Override protected void onDestroy() { super.onDestroy(); UMShareAPI.get(this).release(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); UMShareAPI.get(this).onSaveInstanceState(outState); } ``` -------------------------------- ### Share Web Link with Tracking Code Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Share a web link with custom tracking parameters for analytics. This requires obtaining a UMID and generating a root track code before sharing. ```java public void shareUrlWithRootTrackCode(final Context context) { final String webUrl = "http://mobile.umeng.com/social"; HashMap customParam = new HashMap(); customParam.put("userId", "123566"); customParam.put("website", "baidu.com"); String umid = TrackerManager.getUMID(context); if (TextUtils.isEmpty(umid)) { Toast.makeText(context, "UMID获取失败,请稍后重试!", Toast.LENGTH_LONG).show(); return; } TrackerManager.requestTrackerCode(context, "59892f08310c9307b60023d0", umid, webUrl, null, customParam, new TrackerResultHandler() { @Override public void codeGenerateSuccess(final String rootTrackCode) { String newWebUrl = webUrl + "?um_rtc=" + rootTrackCode; UMWeb rootTrackWeb = new UMWeb(newWebUrl); rootTrackWeb.setTitle("Web title with root track code."); rootTrackWeb.setThumb(new UMImage(context, R.drawable.thumb)); rootTrackWeb.setDescription("root track code sample."); new ShareAction((Activity) context) .withMedia(rootTrackWeb) .setPlatform(share_media) .setCallback(shareListener) .share(); } @Override public void codeGenerateFailed(Throwable t) { Toast.makeText(context, "获取rootTrackCode失败: " + t.getMessage(), Toast.LENGTH_LONG).show(); } }); } ``` -------------------------------- ### Umeng SDK Gradle Dependencies Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Configures project-level Gradle dependencies for Umeng SDKs, including support libraries, Twitter, Sina Weibo, WeChat, DingTalk, and ByteDance SDKs. ```groovy // app/build.gradle apply plugin: 'com.android.application' android { compileSdkVersion 34 defaultConfig { applicationId "com.umeng.soexample" minSdkVersion 21 targetSdkVersion 30 versionCode 1 versionName "1.0" ndk { // PushSDK目前只支持4种架构 abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86' } } } dependencies { // 友盟SDK离线包 implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs') implementation project(':UMLibrary') // U-Share 依赖 implementation 'com.android.support:support-v4:25.0.0' // Twitter SDK implementation 'com.twitter.sdk.android:twitter-core:3.1.1' implementation 'com.twitter.sdk.android:tweet-composer:3.1.1' // 新浪官方依赖库 implementation('io.github.sinaweibosdk:core:13.10.1') { exclude module: 'unspecified' } // 微信官方依赖库 implementation 'com.tencent.mm.opensdk:wechat-sdk-android:6.8.24' // 钉钉官方sdk implementation "com.alibaba.android:ddsharesdk:1.2.2" // 字节跳动sdk implementation 'com.bytedance.ies.ugc.aweme:opensdk-china-external:0.1.9.0' implementation 'com.bytedance.ies.ugc.aweme:opensdk-common:0.1.9.0' } ``` -------------------------------- ### Implement Custom Event Tracking with MobclickAgent Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt Utilize MobclickAgent to track simple events, multi-attribute K-V events, and numerical statistics. Ensure page tracking is handled within onResume and onPause lifecycle methods. ```java public class UappActivity extends BaseActivity { private Context mContext; private final String mPageName = "UappActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; // 普通事件统计 findViewById(R.id.analytics_g1_b1).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // 简单事件 MobclickAgent.onEvent(mContext, "click"); // 带标签的事件 MobclickAgent.onEvent(mContext, "click", "button"); Toast.makeText(mContext, "已完成普通事件", Toast.LENGTH_SHORT).show(); } }); // 多属性(K-V)事件统计 findViewById(R.id.analytics_g1_b2).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Map map_ekv = new HashMap(); map_ekv.put("type", "popular"); map_ekv.put("artist", "JJLin"); MobclickAgent.onEvent(mContext, "music", map_ekv); Toast.makeText(mContext, "已完成多属性(K-V)事件", Toast.LENGTH_SHORT).show(); } }); // 数值型统计 findViewById(R.id.analytics_g1_b3).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Map map_value = new HashMap(); map_value.put("type", "popular"); map_value.put("artist", "JJLin"); MobclickAgent.onEventValue(mContext, "music", map_value, 12000); Toast.makeText(mContext, "已完成数值型统计", Toast.LENGTH_SHORT).show(); } }); } // 页面统计 - 在onResume/onPause中调用 @Override public void onResume() { super.onResume(); MobclickAgent.onPageStart(mPageName); } @Override public void onPause() { super.onPause(); MobclickAgent.onPageEnd(mPageName); } } ``` -------------------------------- ### Share Multiple Images Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt This method allows sharing multiple images simultaneously, which is supported by platforms like Weibo. Both images and their thumbnails are defined using UMImage. The ShareAction is configured with text and multiple media objects, and a UMShareListener manages the callbacks. ```java // 分享多图 (支持微博等平台) public void shareMulImage() { UMImage imagelocal1 = new UMImage(this, R.drawable.logo); imagelocal1.setThumb(new UMImage(this, R.drawable.thumb)); UMImage imagelocal2 = new UMImage(this, R.drawable.datu); imagelocal2.setThumb(new UMImage(this, R.drawable.datu)); new ShareAction(ShareDetailActivity.this) .withText("多图分享") .withMedias(imagelocal1, imagelocal2) .setPlatform(share_media) .setCallback(shareListener) .share(); } ``` -------------------------------- ### Delete Tag from User - Umeng Push SDK Source: https://context7.com/umeng/multifunctionandroiddemo/llms.txt This method allows for the removal of a specific tag from a user. It requires a tag to be specified and provides feedback on the operation's outcome. ```java mPushAgent.getTagManager().deleteTags(new UPushTagCallback() { @Override public void onMessage(final boolean isSuccess, final ITagManager.Result result) { handler.post(new Runnable() { @Override public void run() { inputTag.setText(""); if (isSuccess) { tagRemain.setText(String.valueOf(result.remain)); Toast.makeText(context, "删除成功", Toast.LENGTH_SHORT).show(); } } }); } }, tag); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.