Android Open Source - ShareSDK-for-Android Laiwang






From Project

Back to project page ShareSDK-for-Android.

License

The source code is released under:

MIT License

If you think the Android project ShareSDK-for-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package cn.sharesdk.demo;
//w  ww.  j  a  va 2  s. c  o m
import java.io.File;
import java.util.HashMap;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.text.TextUtils;
import cn.sharesdk.framework.CustomPlatform;
import cn.sharesdk.framework.Platform;

public class Laiwang extends CustomPlatform {
  public static final String NAME = Laiwang.class.getSimpleName();

  public Laiwang(Context context) {
    super(context);
  }

  public String getName() {
    return NAME;
  }

  protected boolean checkAuthorize(int action, Object extra) {
    return isValid();
  }

  public boolean isValid() {
    return isClientInstalled();
  }

  private boolean isClientInstalled() {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setPackage("com.alibaba.android.babylon");
    i.setType("image/*");
    PackageManager pm = getContext().getPackageManager();
    List<?> ris = pm.queryIntentActivities(
        i, PackageManager.GET_ACTIVITIES);
    return ris != null && ris.size() > 0;
  }

  protected void doShare(Platform.ShareParams params) {
    ShareParams sp = new ShareParams(params.toMap());
    Intent i = new Intent(Intent.ACTION_SEND);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setPackage("com.alibaba.android.babylon");
    String imagePath = sp.getImagePath();
    String text = sp.getText();
    if (!TextUtils.isEmpty(imagePath)
        && (new File(imagePath).exists())) {
      Uri uri = Uri.fromFile(new File(imagePath));
      i.putExtra(Intent.EXTRA_STREAM, uri);
      i.setType("image/*");
      try {
        getContext().startActivity(i);
        if (listener != null) {
          HashMap<String, Object> res = new HashMap<String, Object>();
          res.put("ShareParams", params);
          listener.onComplete(this, ACTION_SHARE, res);
        }
      } catch (Throwable t) {
        listener.onError(this, ACTION_SHARE, t);
      }
    } else if (!TextUtils.isEmpty(text)) {
      i.putExtra(Intent.EXTRA_TEXT, text);
      i.setType("text/plain");
      try {
        getContext().startActivity(i);
        if (listener != null) {
          HashMap<String, Object> res = new HashMap<String, Object>();
          res.put("ShareParams", params);
          listener.onComplete(this, ACTION_SHARE, res);
        }
      } catch (Throwable t) {
        listener.onError(this, ACTION_SHARE, t);
      }
    } else if (listener != null) {
      listener.onError(this, ACTION_SHARE, new Throwable("Share content is empty!"));
    }
  }

  public static class ShareParams extends Platform.ShareParams {

    public ShareParams() {
      super();
    }

    public ShareParams(HashMap<String, Object> params) {
      super(params);
    }

    public ShareParams(String jsonParams) {
      super(jsonParams);
    }

    public void setText(String text) {
      set(ShareParams.TEXT, text);
    }

    public String getText() {
      return get(ShareParams.TEXT, String.class);
    }

    public void setImagePath(String imagePath) {
      set(ShareParams.IMAGE_PATH, imagePath);
    }

    public String getImagePath() {
      return get(ShareParams.IMAGE_PATH, String.class);
    }

  }

}




Java Source Code List

cn.sharesdk.demo.AuthPage.java
cn.sharesdk.demo.CustomShareFieldsPage.java
cn.sharesdk.demo.CustomerPage.java
cn.sharesdk.demo.DemoPage.java
cn.sharesdk.demo.GetInforPage.java
cn.sharesdk.demo.GetTokenPage.java
cn.sharesdk.demo.JsonPage.java
cn.sharesdk.demo.Laiwang.java
cn.sharesdk.demo.MainActivity.java
cn.sharesdk.demo.MainAdapter.java
cn.sharesdk.demo.MyAdapter.java
cn.sharesdk.demo.MyQZoneWebShareAdapter.java
cn.sharesdk.demo.OneKeyShareCallback.java
cn.sharesdk.demo.ShareContentCustomizeDemo.java
cn.sharesdk.demo.SlidingMenuPage.java
cn.sharesdk.demo.WechatPage.java
cn.sharesdk.demo.YixinPage.java
cn.sharesdk.demo.wxapi.WXEntryActivity.java
cn.sharesdk.demo.yxapi.YXEntryActivity.java
cn.sharesdk.onekeyshare.CustomerLogo.java
cn.sharesdk.onekeyshare.CustomerLogo.java
cn.sharesdk.onekeyshare.EditPageFakeActivity.java
cn.sharesdk.onekeyshare.EditPageFakeActivity.java
cn.sharesdk.onekeyshare.FollowerListFakeActivity.java
cn.sharesdk.onekeyshare.FollowerListFakeActivity.java
cn.sharesdk.onekeyshare.OnekeyShareTheme.java
cn.sharesdk.onekeyshare.OnekeyShareTheme.java
cn.sharesdk.onekeyshare.OnekeyShare.java
cn.sharesdk.onekeyshare.OnekeyShare.java
cn.sharesdk.onekeyshare.PicViewer.java
cn.sharesdk.onekeyshare.PicViewer.java
cn.sharesdk.onekeyshare.PlatformListFakeActivity.java
cn.sharesdk.onekeyshare.PlatformListFakeActivity.java
cn.sharesdk.onekeyshare.Shake2Share.java
cn.sharesdk.onekeyshare.Shake2Share.java
cn.sharesdk.onekeyshare.ShareContentCustomizeCallback.java
cn.sharesdk.onekeyshare.ShareContentCustomizeCallback.java
cn.sharesdk.onekeyshare.ShareCore.java
cn.sharesdk.onekeyshare.ShareCore.java
cn.sharesdk.onekeyshare.ThemeShareCallback.java
cn.sharesdk.onekeyshare.ThemeShareCallback.java
cn.sharesdk.onekeyshare.theme.classic.EditPage.java
cn.sharesdk.onekeyshare.theme.classic.EditPage.java
cn.sharesdk.onekeyshare.theme.classic.FollowListPage.java
cn.sharesdk.onekeyshare.theme.classic.FollowListPage.java
cn.sharesdk.onekeyshare.theme.classic.PlatformGridView.java
cn.sharesdk.onekeyshare.theme.classic.PlatformGridView.java
cn.sharesdk.onekeyshare.theme.classic.PlatformListPage.java
cn.sharesdk.onekeyshare.theme.classic.PlatformListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.EditPage.java
cn.sharesdk.onekeyshare.theme.skyblue.EditPage.java
cn.sharesdk.onekeyshare.theme.skyblue.FollowListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.FollowListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformGridViewAdapter.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformGridViewAdapter.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformListPage.java
cn.sharesdk.socialization.sample.MainActivity.java
cn.sharesdk.socialization.sample.MyPlatform.java
cn.sharesdk.socialization.sample.wxapi.WXEntryActivity.java
cn.sharesdk.socialization.sample.yxapi.YXEntryActivity.java