核心代码部分标注了红色!!!!!!!!!!!!!!!!
AndroidMianifest:
OutsideActivity类:
package com.palmnewsclient.test;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.newnet.ydc.palmNews.R;
import com.palmnewsclient.MainActivity;
import com.palmnewsclient.base.BaseActivity;
import com.palmnewsclient.bean.NewsListBean;
import com.palmnewsclient.data.AppConfig;
import com.palmnewsclient.http.rx.RxBus;
import com.palmnewsclient.http.subscriber.SimpleSubscriber;
import com.palmnewsclient.newcenter.OtherNewsTypeActivity;
import com.palmnewsclient.newcenter.VoteActivity;
import com.palmnewsclient.newcenter.helper.NewHelpUtils;
import com.palmnewsclient.usercenter.LoginActivity;
import com.palmnewsclient.utils.AppManager;
import com.palmnewsclient.utils.Constants;
import com.palmnewsclient.utils.SPUtils;
import static com.palmnewsclient.utils.SPUtils.getBooleanType;
public class OutsideActivity extends BaseActivity {
private int newType;
private int contentId;
private String tooken;
private TextView text;
private String url;
private NewsListBean.BodyEntity.DataEntity bean;
@Override
protected int initRootView() {
return R.layout.activity_outside;
}
@Override
protected void initTitle() {
RxBus.getDefault().toObservable(OutSideBindSucceed.class).subscribe(new SimpleSubscriber() {
@Override
public void onNext(OutSideBindSucceed imageController) {
if(imageController.isSuccess()) {
openActivity();
}
}
});
RxBus.getDefault().toObservable(OutSideEvent.class).subscribe(new SimpleSubscriber() {
@Override
public void onNext(OutSideEvent event) {
if(event.getOutside()) {
openActivity();
}
}
});
}
@Override
protected void initViews() {
text = (TextView) findViewById(R.id.text);
}
@Override
protected void initData() {
String data = getIntent().getDataString();//接收到网页传过来的数据:scheme://com.newnet.ydc.palmNews?newType=7&contentId=12345
if(data!=null) {
String[] split = data.split(getPackageName()+"?");//以包名加问号为切割符来切割字符串
String UrlData = split[1]; //就得到:newType=7&contentId=12345(这就是我们需要网页传给我们的数据)
//以下是截取字符串处理拿到我们需要的参数值
String[] param=UrlData.split("&");
contentId=Integer.parseInt((param[0].split("="))[1]);
newType=Integer.parseInt((param[1].split("="))[1]);
Log.e("WEIWEI", "newType="+newType+" contentId="+contentId);
Log.e("WEIWEI", data);
}else {
text.setText("参数错误,无法启动");
return;
}
boolean islogin = getBooleanType(this, Constants.USER_LOGIN_STATUS);
boolean isBindMobile = getBooleanType(this, Constants.USER_LOGIN_THIRD_WAY_BIND_MOBILE_STATUS);
boolean isthirdLogin=SPUtils.getBooleanType(this,Constants.USER_LOGIN_THIRD_WAY_STATUS);
Log.e("WEI", "isLogin=="+islogin+"");
if(islogin) {
if(!isthirdLogin) {
openActivity();
Log.e("WEI", "登陆的状态下=========================");
}else {
if(isBindMobile) {
Log.e("WEI", "已绑定状态下=========================");
openActivity();
}else {
Log.e("WEI", "未绑定状态下=========================");
Bundle b=new Bundle();
b.putCharSequence(AppConfig.SHOW_BIND_DIALOG,"bind");
AppManager.getInstance().jumpActivity(this, MainActivity.class, b);
AppManager.getInstance().finishActivity(this);
}
}
}else{
Log.e("WEI", "未登陆的状态下=========================");
Bundle bundle=new Bundle();
bundle.putString("OUT_SIDE","out_side");
AppManager.getInstance().jumpActivity(this, LoginActivity.class, bundle);
AppManager.getInstance().finishActivity(this);
}
}
@Override
protected void initListener() {
////如果是第三方登录并且还未绑定
// boolean thirdLoginStatus = SPUtils.getBooleanType(context, Constants.USER_LOGIN_THIRD_WAY_STATUS);
// boolean loginStatus = SPUtils.getBooleanType(context, Constants.USER_LOGIN_STATUS);
// boolean isBindMobile = SPUtils.getBooleanType(context, Constants.USER_LOGIN_THIRD_WAY_BIND_MOBILE_STATUS);
// //7.8.12类型的文章必须有这步操作
// boolean needLoginFunc = dataEntity.getNewType() == 7 || dataEntity.getNewType() == 8 || dataEntity.getNewType() == 12;
// if(loginStatus&&thirdLoginStatus&&!isBindMobile&&needLoginFunc) {//第三方登录并且没有绑定手机,并且不是普通文章
// //提示去绑定手机
// Toast.makeText(context, "请先去绑定您的手机", Toast.LENGTH_SHORT).show();
// Intent intent = new Intent(context, Main2Activity.class);
// intent.putExtras(bundle);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// startActivity(intent);
// }else {
// Intent intent = new Intent(context, webviewByNewsType);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intent.putExtras(bundle);
// startActivity(intent);
// }
}
@Override
protected void onResume() {
super.onResume();
Log.e("WEI", "只走了onResume=========================");
}
private void openActivity() {
getBundle();
AppManager.getInstance().jumpActivity(this, MainActivity.class, null);
if(newType==8) {
AppManager.getInstance().jumpActivity(this, VoteActivity.class, bundle);
}else {
AppManager.getInstance().jumpActivity(this, OtherNewsTypeActivity.class, bundle);
}
AppManager.getInstance().finishActivity(this);
}
private Bundle bundle;
@NonNull
private void getBundle() {
tooken= SPUtils.getStringType(this, Constants.USER_LOGIN_TOKEN);
url= NewHelpUtils.getNewsUrlByNewsType(this,newType,contentId,tooken);
Log.e("WEIWEI", url);
bean=new NewsListBean.BodyEntity.DataEntity();
bean.setTitle(NewHelpUtils.getNewsTitleByNewsType(newType));
bean.setNewType(newType);
bean.setContentId(contentId);
bean.setId(contentId);
Intent intent=new Intent();
intent.putExtra(Constants.NEW_DETAIL_TITLE,NewHelpUtils.getNewsTitleByNewsType(newType));
intent.putExtra(Constants.NEW_DETAIL_SHARE_BEAN,bean);
intent.putExtra(Constants.NEW_DETAIL_URL,url);
bundle=new Bundle();
bundle.putString(Constants.NEW_DETAIL_URL, url);//路径
bundle.putString(Constants.NEW_DETAIL_TITLE, NewHelpUtils.getNewsTitleByNewsType(newType));//文章详情标题
bundle.putString(Constants.NEW_LINK_TITLE, NewHelpUtils.getNewsTitleByNewsType(newType));//文章链接标题
bundle.putSerializable(Constants.NEW_DETAIL_SHARE_BEAN, bean);
}
@Override
public void onClick(View v) {
}
}