前几年项目中也是写过微信分享的,但是中间换了几台电脑笔记无法一下找到,这次接收前任android的代码,微信分享成功后回调问题、造成页面混乱问题!它用的是友盟第三方,万变不离其宗必须依赖各平台官网,依据经验: 仔细看log+搜索关键字+快速多尝试,很多问题不是问题!
最终我找到的原因是WXEntryActivity在AndroidManifest.xml文件中声明有问题
<!-- 这样写会出现页面混乱问题 -->
<!--<activity-->
<!--android:name=".wxapi.WXEntryActivity"-->
<!--android:configChanges="keyboardHidden|orientation|screenSize"-->
<!--android:exported="true"-->
<!--android:launchMode="singleTask"-->
<!--android:screenOrientation="portrait"-->
<!--android:theme="@android:style/Theme.Translucent.NoTitleBar" />-->
<activity
android:name=".wxapi.WXEntryActivity"
android:launchMode="singleTop"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="sdksample"/>
</intent-filter>
</activity>
下面列出2个核心点:
1. 在你的包名相应目录下新建一个wxapi目录,并在该wxapi目录下新增一个WXEntryActivity类,该类继承自Activity,并在manifest文件里面加上exported属性,设置为true,允许该Activity被其他应用调用,这句话很重要。
<activity
android:name="你的APP包名.wxapi.WXEntryActivity"
android:launchMode="singleTop"
android:exported="true"
android:theme="@style/comment_activity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="sdksample"/>
</intent-filter>
</activity>
2. 实现IWXAPIEventHandler接口,微信发送的请求将回调到onReq方法,发送到微信请求的响应结果将回调到onResp方法。
public class WXEntryActivity extends WXCallbackActivity implements IWXAPIEventHandler {
private static String TAG = "WXEntryActivity@@@";
@Override
public void onResp(BaseResp resp) {
super.onResp(resp);
Log.v(TAG,"onResp");
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.v(TAG,"onNewIntent");
}
}
参考链接: