Java Code Examples for com.tencent.mm.sdk.openapi.WXAPIFactory#createWXAPI()

The following examples show how to use com.tencent.mm.sdk.openapi.WXAPIFactory#createWXAPI() . 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: OnekeyShare.java    From Huochexing12306 with Apache License 2.0 5 votes vote down vote up
private void shareToWechat(boolean isWechatMoments,boolean isWechat, boolean isWechatFavorite, String imagePath, String comment) {
	IWXAPI api = WXAPIFactory.createWXAPI(MyApp.getInstance(), MyApp.WEIXIN_KEY);
	// 将该app注册到微信
       api.registerApp( MyApp.WEIXIN_KEY);
	WXImageObject imgObj = new WXImageObject();
	imgObj.setImagePath(imagePath);
	
	WXMediaMessage msg = new WXMediaMessage();
	msg.description = comment;
	msg.mediaObject = imgObj;
	
	Bitmap bmp = BitmapFactory.decodeFile(imagePath);
	Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 100, 100, true);
	bmp.recycle();
	msg.thumbData = bmpToByteArray(thumbBmp, true);
	int imageSize = msg.thumbData.length / 1024;
       if (imageSize > 32) {
               Toast.makeText(MyApp.getInstance(), "您分享的图片过大", Toast.LENGTH_SHORT)
                               .show();
               return;
       }
	SendMessageToWX.Req req = new SendMessageToWX.Req();
	req.transaction = buildTransaction("img");
	req.message = msg;
	req.scene = isWechat? SendMessageToWX.Req.WXSceneSession:SendMessageToWX.Req.WXSceneTimeline;
	api.sendReq(req);
	finish();
}
 
Example 2
Source File: Activity_Result_Combination.java    From MortgageCalculator with Apache License 2.0 5 votes vote down vote up
public void init(){
    //微信分享初始化
    wxApi = WXAPIFactory.createWXAPI(this, WXAppID);
    wxApi.registerApp(WXAppID);

    /*//有米
    //获取要嵌入广告条的布局
    LinearLayout bannerLayout = (LinearLayout)findViewById(R.id.ll_banner2);

    //获取广告条
    View bannerView = BannerManager.getInstance(Activity_Result.this).getBannerView(new net.youmi.android.normal.banner.BannerViewListener() {
        @Override
        public void onRequestSuccess() {
            System.out.println("请求广告成功");
        }

        @Override
        public void onSwitchBanner() {
            System.out.println("切换广告条");
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            lp.addRule(RelativeLayout.ABOVE,  R.id.ll_banner1);
            lp.addRule(RelativeLayout.BELOW, R.id.ResultCursorImageView);
            viewPager.setLayoutParams(lp);
        }

        @Override
        public void onRequestFailed() {
            System.out.println("请求广告失败");
        }
    });

    //将广告条加入到布局中
    bannerLayout.addView(bannerView);*/
}
 
Example 3
Source File: Activity_Result.java    From MortgageCalculator with Apache License 2.0 5 votes vote down vote up
public void init(){
    //微信分享初始化
    wxApi = WXAPIFactory.createWXAPI(this, WXAppID);
    wxApi.registerApp(WXAppID);

    /*//有米
    //获取要嵌入广告条的布局
    LinearLayout bannerLayout = (LinearLayout)findViewById(R.id.ll_banner1);

    //获取广告条
    View bannerView = BannerManager.getInstance(Activity_Result.this).getBannerView(new net.youmi.android.normal.banner.BannerViewListener() {
        @Override
        public void onRequestSuccess() {
            System.out.println("请求广告成功");
        }

        @Override
        public void onSwitchBanner() {
            System.out.println("切换广告条");
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            lp.addRule(RelativeLayout.ABOVE,  R.id.ll_banner1);
            lp.addRule(RelativeLayout.BELOW, R.id.ResultCursorImageView);
            viewPager.setLayoutParams(lp);
        }

        @Override
        public void onRequestFailed() {
            System.out.println("请求广告失败");
        }
    });

    //将广告条加入到布局中
    bannerLayout.addView(bannerView);*/
}
 
Example 4
Source File: WXEntryActivity.java    From GOpenSource_AppKit_Android_AS with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	IWXAPI api = WXAPIFactory.createWXAPI(this, GosDeploy.setWechatAppID(),
			true);
	api.handleIntent(getIntent(), this);
}
 
Example 5
Source File: WeChat.java    From ESSocialSDK with Apache License 2.0 5 votes vote down vote up
public static IWXAPI getIWXAPIInstance(Context context, String appId) {
    if (null == api) {
        api = WXAPIFactory.createWXAPI(context, appId, true);
        api.registerApp(appId);
    }

    return api;
}
 
Example 6
Source File: WeixinPayHelper.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
public WeixinPayHelper initWXPayApi(Context context) {
    //支付。对应的activity 需要配置scheme  SdkConfig.WEIXIN_PAY_APP_ID
    mWxApi = WXAPIFactory.createWXAPI(context.getApplicationContext(),
            SdkFactory.PayConfig.sWeixin_app_Id, false);
    mWxApi.registerApp(SdkFactory.PayConfig.sWeixin_app_Id);
    return this;
}
 
Example 7
Source File: LetvAlipayManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private boolean initWxpayApi(String appId) {
    if (TextUtils.isEmpty(appId)) {
        ToastUtils.showToast(this.activity, this.activity.getString(2131100995));
        return false;
    }
    this.api = WXAPIFactory.createWXAPI(this.activity, appId);
    this.api.registerApp(appId);
    this.isRegisterWx = true;
    return true;
}
 
Example 8
Source File: MainActivity.java    From Example-of-Cocos2DX with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	Log.d("sss","Main create");
	
	api = WXAPIFactory.createWXAPI(this, APP_ID,true);
	api.registerApp(APP_ID);
	s_Instance = this;
}
 
Example 9
Source File: AppRegister.java    From wechatsdk-xamarin with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
	final IWXAPI api = WXAPIFactory.createWXAPI(context, null);

	// ����appע�ᵽ΢��
	api.registerApp(Constants.APP_ID);
}
 
Example 10
Source File: SharePanelView.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
public static IWXAPI getIWXAPI(){
    if(iwxapi == null){
        iwxapi = WXAPIFactory.createWXAPI(MyApp.getInstance().getApplicationContext(),WECHAT_APP_ID,true);
        iwxapi.registerApp(WECHAT_APP_ID);
    }
    return iwxapi;
}
 
Example 11
Source File: WXEntryActivity.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@Override
  public void onCreate(Bundle savedInstanceState) {
  	Log.i(TAG, "onCreate");
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_wechat_login_dialog);
  	api = WXAPIFactory.createWXAPI(this, Constants.WECHAT_APPID, false);
  	api.registerApp(Constants.WECHAT_APPID);    	
      api.handleIntent(getIntent(), this);
      it=getIntent();
      int type=0;
      if(it!=null){
      	type=it.getIntExtra(TYPE, 0);
      }
      if(type==LOGIN){
      	SendAuth.Req req = new SendAuth.Req();
      	req.scope = "snsapi_userinfo";
      	req.state = state=Long.toString(System.currentTimeMillis());
      	api.sendReq(req);
      }
      findViewById(R.id.wechat_close).setOnClickListener(new View.OnClickListener() {
	
	@Override
	public void onClick(View v) {
		finish();
	}
});
  }
 
Example 12
Source File: WXEntryActivity.java    From Android-Plugin-Framework with MIT License 4 votes vote down vote up
@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
api = WXAPIFactory.createWXAPI(this, APP_ID, false);
      api.handleIntent(getIntent(), this);
  }
 
Example 13
Source File: WXEntryActivity.java    From FoodOrdering with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    api = WXAPIFactory.createWXAPI(this, ManifestUtil.getWeixinKey(this), false);
    api.handleIntent(getIntent(), this);
}
 
Example 14
Source File: WXPay.java    From letv with Apache License 2.0 4 votes vote down vote up
private WXPay(Context context) {
    this.mContext = context;
    this.api = WXAPIFactory.createWXAPI(context.getApplicationContext(), null);
}
 
Example 15
Source File: WChatManager.java    From Android-Application-ZJB with Apache License 2.0 4 votes vote down vote up
/**
 * 构造方法当中初始化IWXAPI
 */
private WChatManager() {
    WXAPI = WXAPIFactory.createWXAPI(ZjbApplication.gContext, ShareConstant.WEIXIN_APPID, false);
    WXAPI.registerApp(ShareConstant.WEIXIN_APPID);
}
 
Example 16
Source File: WxShareInstance.java    From ShareUtil with Apache License 2.0 4 votes vote down vote up
public WxShareInstance(Context context, String appId) {
    mIWXAPI = WXAPIFactory.createWXAPI(context, appId, true);
    mIWXAPI.registerApp(appId);
}
 
Example 17
Source File: ShareByWeixin.java    From ShareSDK with MIT License 4 votes vote down vote up
public ShareByWeixin(Context context, int channel) {
    super(context);
    this.context = context.getApplicationContext();
    this.channel = channel;
    api = WXAPIFactory.createWXAPI(context.getApplicationContext(), ManifestUtil.getWeixinKey(this.context));
}
 
Example 18
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);
	}

}
 
Example 19
Source File: WXEntryActivity.java    From gokit-android with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	IWXAPI api = WXAPIFactory.createWXAPI(this, GosDeploy.setWechatAppID(), true);
	api.handleIntent(getIntent(), this);
}
 
Example 20
Source File: BaseDialog.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
private void registerToWx() {
    wAPI = WXAPIFactory.createWXAPI(mContext, Constants.WECHAT_APPID, true);
    wAPI.registerApp(Constants.WECHAT_APPID);
}