Java Code Examples for com.tencent.tauth.Tencent#createInstance()

The following examples show how to use com.tencent.tauth.Tencent#createInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseDialog.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
    View view = inflater.inflate(R.layout.base_dialog, container, false);
    AnimationUtils.slideToUp(view);
    view.findViewById(R.id.share_sinaweibo_box).setOnClickListener(this);
    view.findViewById(R.id.share_wechat_friend_box).setOnClickListener(this);
    view.findViewById(R.id.share_weichat_timeline_box).setOnClickListener(this);
    view.findViewById(R.id.share_qq_box).setOnClickListener(this);
    registerToWx();
    mTencent = Tencent.createInstance(Constants.TENCENT_APPID, mContext);
    shareText = mContext.getResources().getString(R.string.shareText);
    shareLink = wechatShareLink;
    return view;
}
 
Example 2
Source File: QQShareApi.java    From browser with GNU General Public License v2.0 6 votes vote down vote up
public static void shareWebPageQQFriend(final Activity activity,final String url,final String title,final String desc,final String img,IUiListener listener ){
    if (api == null) {
        api = Tencent.createInstance(APP_ID, MainApp.getContext());
    }

    if(api==null){
        return;
    }
    final 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, title);
    params.putString(QQShare.SHARE_TO_QQ_SUMMARY,  desc);
    params.putString(QQShare.SHARE_TO_QQ_TARGET_URL,  url);

    String postimg=img;
    if(StringUtils.isEmpty(img)) {
        postimg="http://youkes.oss.aliyuncs.com/icon/icon_96.png";
    }

    params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL,postimg);
    params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "优分享");

    api.shareToQQ(activity, params,listener);

}
 
Example 3
Source File: MainActivity.java    From BookReader with Apache License 2.0 6 votes vote down vote up
@Override
public void initDatas() {
    startService(new Intent(this, DownloadBookService.class));

    mTencent = Tencent.createInstance("1105670298", MainActivity.this);

    mDatas = Arrays.asList(getResources().getStringArray(R.array.home_tabs));
    mTabContents = new ArrayList<>();
    mTabContents.add(new RecommendFragment());
    mTabContents.add(new CommunityFragment());
    mTabContents.add(new FindFragment());

    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mTabContents.size();
        }

        @Override
        public Fragment getItem(int position) {
            return mTabContents.get(position);
        }
    };
}
 
Example 4
Source File: QQLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
public QQLoginInstance(Activity activity, final LoginListener listener,
                       final boolean fetchUserInfo) {
    super(activity, listener, fetchUserInfo);
    mTencent = Tencent.createInstance(ShareManager.CONFIG.getQqId(), activity);
    mIUiListener = new IUiListener() {
        @Override
        public void onComplete(Object o) {
            ShareLogger.i(ShareLogger.INFO.QQ_AUTH_SUCCESS);
            try {
                QQToken token = new QQToken((JSONObject) o);
                if (fetchUserInfo) {
                    listener.beforeFetchUserInfo(token);
                    fetchUserInfo(token);
                } else {
                    listener.loginSuccess(new LoginResultData(LoginPlatform.QQ, token));
                    LoginUtil.recycle();
                }
            } catch (JSONException e) {
                ShareLogger.i(ShareLogger.INFO.ILLEGAL_TOKEN);
                mLoginListener.loginFailure(e, ShareLogger.INFO.ERR_GET_TOKEN_CODE);
                LoginUtil.recycle();
            }
        }

        @Override
        public void onError(UiError uiError) {
            ShareLogger.i(ShareLogger.INFO.LOGIN_ERROR);
            listener.loginFailure(new Exception(uiError.errorDetail), uiError.errorCode);
            LoginUtil.recycle();
        }

        @Override
        public void onCancel() {
            ShareLogger.i(ShareLogger.INFO.AUTH_CANCEL);
            listener.loginCancel();
            LoginUtil.recycle();
        }
    };
}
 
Example 5
Source File: LoginFragment.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    loginFragmentCallback = (LoginFragmentCallback)activity;
    mTencent = Tencent.createInstance("1105431865", MyApplication.mContext);

    loginListener = new QQIUiListener(){
        @Override
        public void onComplete(Object response) {
            //super.onComplete(response);
            Log.d("QQLogin","QQ登录成功");
        }
    };

}
 
Example 6
Source File: QQHelper.java    From SocialHelper with Apache License 2.0 5 votes vote down vote up
QQHelper(Activity activity, String appId) {
    this.activity = activity;
    this.appId = appId;
    if (TextUtils.isEmpty(appId)) {
        Log.w("QQHelper", "QQ's appId is empty!");
        return;
    }
    tencent = Tencent.createInstance(appId, activity.getApplicationContext());
}
 
Example 7
Source File: QQShareManager.java    From sharesdk with Apache License 2.0 5 votes vote down vote up
QQShareManager(Context context) {
    mAppId = ShareSDK.getInstance().getQQAppId();
    mContext = context;
    if (!TextUtils.isEmpty(mAppId)) {
        mTencent = Tencent.createInstance(mAppId, context);
        mQQShare = new QQShare(context, mTencent.getQQToken());
        mQZoneShare = new QzoneShare(context, mTencent.getQQToken());
    }
}
 
Example 8
Source File: QQShareApi.java    From browser with GNU General Public License v2.0 5 votes vote down vote up
public static void login(Activity activity,String scope,IUiListener listener) {
    if (api == null) {
        api = Tencent.createInstance(APP_ID, MainApp.getContext());
    }

    if(api==null){
        return;
    }

    if (!api.isSessionValid()) {

        api.login(activity, scope, listener);
    }

}
 
Example 9
Source File: QQAuthManager.java    From sharesdk with Apache License 2.0 5 votes vote down vote up
QQAuthManager(Context context) {
    mContext = context;
    mAppId = ShareSDK.getInstance().getQQAppId();
    if (!TextUtils.isEmpty(mAppId)) {
        mTencent = Tencent.createInstance(mAppId, context);
    }
}
 
Example 10
Source File: SharePanelView.java    From nono-android with GNU General Public License v3.0 4 votes vote down vote up
public static Tencent getTencentQQApi(){
    if(tencentQQApi == null){
        tencentQQApi = Tencent.createInstance(QQ_API_ID,MyApp.getInstance().getApplicationContext());
    }
    return tencentQQApi;
}
 
Example 11
Source File: BaseQQShareHandler.java    From BiliShare with Apache License 2.0 4 votes vote down vote up
@Override
public void init() throws Exception {
    if (mTencent == null) {
        mTencent = Tencent.createInstance(mAppId, getContext().getApplicationContext());
    }
}
 
Example 12
Source File: QQShareImpl.java    From ChinaShare with MIT License 4 votes vote down vote up
public QQShareImpl(Activity activity, int resIcon, String title,int qqShareWay) {
    super(activity, resIcon, title);
    this.mShareWay = qqShareWay;
    mTencent = Tencent.createInstance(ShareManager.getQQAppId(), activity);
}
 
Example 13
Source File: ShareByQQ.java    From ShareSDK with MIT License 4 votes vote down vote up
public ShareByQQ(Context context) {
    super(context);
    mTencent = Tencent.createInstance(ManifestUtil.getTencentQQAppId(context.getApplicationContext()), context.getApplicationContext());
}
 
Example 14
Source File: AppbarActivity.java    From letv with Apache License 2.0 4 votes vote down vote up
private Tencent getTencent() {
    if (this.tencent == null) {
        this.tencent = Tencent.createInstance(this.appid, this);
    }
    return this.tencent;
}
 
Example 15
Source File: TencentInstance.java    From letv with Apache License 2.0 4 votes vote down vote up
public static Tencent getInstance(Context context) {
    if (mTencent == null) {
        mTencent = Tencent.createInstance(AppConstants.APP_ID, context);
    }
    return mTencent;
}
 
Example 16
Source File: QQShareInstance.java    From smart-farmer-android with Apache License 2.0 4 votes vote down vote up
public QQShareInstance(Context context, String app_id) {
    mTencent = Tencent.createInstance(app_id, context.getApplicationContext());
}
 
Example 17
Source File: SetAccountActivity.java    From Social with Apache License 2.0 4 votes vote down vote up
private void handleCheckUsername(Message msg){
    String result = msg.obj.toString();
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
    CheckUsernameRoot root = gson.fromJson(result, CheckUsernameRoot.class);

    if (root == null){
        //new Dialog(this,"错误","链接服务器失败").show();
        Toast.makeText(this, "服务器繁忙,请重试", Toast.LENGTH_LONG).show();
        return;
    }

    if (!root.success){
        new Dialog(this,"错误",root.message).show();
        return ;
    }

    if (root.isExist==0){
        //无记录 可注册
        //获取QQ用户信息
        mTencent = Tencent.createInstance(MyConstants.QQ_APP_ID, MyApplication.mContext);
        mTencent.setOpenId(openid);
        mTencent.setAccessToken(access_token, expires);
        qqToken = mTencent.getQQToken();
        userInfo = new UserInfo(MyApplication.mContext,qqToken);
        userInfo.getUserInfo(new IUiListener() {
            @Override
            public void onComplete(Object object) {
                Log.d("QQinfo", "获取成功");
                JSONObject jsonObject = (JSONObject) object;
                System.out.println(jsonObject);
                try {
                    nickname = jsonObject.getString("nickname");
                    Log.d("QQinfo", "nickname = " + nickname);
                    sex = jsonObject.getString("gender");
                    Log.d("QQinfo", "sex = " + sex);
                    city = jsonObject.getString("province") + jsonObject.getString("city");
                    Log.d("QQinfo", "city = " + city);
                    head_url = jsonObject.getString("figureurl_qq_2");
                    Log.d("QQinfo", "head_url = " + head_url);
                    //下载头像到sd卡

                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            downloadQQhead();
                        }
                    }).start();
                    //OkhttpUtil.downloadQQhead(handler, head_url);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(UiError uiError) {

            }

            @Override
            public void onCancel() {

            }
        });

    }else{
        //有记录 账号不可用 重写
    }

}
 
Example 18
Source File: TXShare.java    From sdk3rd with Apache License 2.0 4 votes vote down vote up
TXShare(Activity activity, Platform platform) {
    mActivity = activity;
    mPlatform = platform;
    mApi = Tencent.createInstance(platform.getAppId(), mActivity);
}
 
Example 19
Source File: Share.java    From UPMiss with GNU General Public License v3.0 4 votes vote down vote up
private synchronized static Tencent getTencent(Context context) {
    if (TENCENT == null) {
        TENCENT = Tencent.createInstance(Constants.QQ_APP_ID, context.getApplicationContext());
    }
    return TENCENT;
}
 
Example 20
Source File: GosUserLoginActivity.java    From Gizwits-SmartBuld_Android with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setTheme(R.style.AppTheme);
	if (!this.isTaskRoot()) {// 判断此activity是不是任务控件的源Activity,“非”也就是说是被系统重新实例化出来的
		Intent mainIntent = getIntent();
		String action = mainIntent.getAction();
		if (mainIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)) {
			finish();
			return;
		}
	}

	setContentView(R.layout.activity_gos_user_login);
	// 设置actionBar
	setActionBar(false, false, R.string.app_company);
	initView();
	initEvent();

	String tencentAPPID = GosDeploy.setTencentAppID();
	if (TextUtils.isEmpty(tencentAPPID) || tencentAPPID.contains("your_tencent_app_id")) {
		Toast.makeText(this, R.string.TencentAPPID_Toast, 2000).show();
		llQQ.setClickable(false);
	} else {
		// 启动QQ登录SDK
		mTencent = Tencent.createInstance(GosDeploy.setTencentAppID(), this.getApplicationContext());
		llQQ.setClickable(true);
	}

	String wechatAppID = GosDeploy.setWechatAppID();
	String wechatAppSecret = GosDeploy.setWechatAppSecret();
	if (TextUtils.isEmpty(wechatAppID) || TextUtils.isEmpty(wechatAppSecret)) {
		Toast.makeText(this, R.string.WechatAppID_Toast, 2000).show();
		llWechat.setClickable(false);

	} else {
		// 启动微信登录SDK
		mIwxapi = WXAPIFactory.createWXAPI(this, wechatAppID, true);

		// 将应用的AppID注册到微信
		mIwxapi.registerApp(wechatAppID);
		llWechat.setClickable(true);
		// 设置与WXEntryActivity共用Handler
		setBaseHandler(baseHandler);
	}

}