android外部链接打开相机,Android实现外部链接唤醒App,并且在App内部打开详情页面...

最近项目中遇到了这个需求,下面详情描述下,在此做个笔记。

需求:app分享出去的链接(只有报名和投票,在详情页里面点击报名或者投票才唤起app),如果本地安装了这个应用则可以直接唤醒app并在app内部打开这个链接的详情页面,如果本地没有安装这个app,则跳转到下载页面提示去下载。

下面是具体的实现过程:

1.Mainfest中的配置

intent-filter>

activity>

注:OutsideActivity是通过Manifest中的配置来启动的。

需要h5传过来的信息scheme://com.newnet.hlxc.palmNews?newType=7&contentId=12345scheme是协议,

com.newnet.hlxc.palmNews是host值,后面的全是所需要的参数。

2.OutsideActivity关键代码

String data = getIntent().getDataString();//接收到网页传过来的数据:sharetest://data/http://www.huxiu.com/if(data != null) {

String[] split = data.split(getPackageName() + "?");//以data/切割data字符串String UrlData = split[1]; //就得到:http://www.huxiu.com/(这就是我们需要网页传给我们的数据)String[] param = UrlData.split("&");

contentId= Integer.parseInt((param[0].split("="))[1]);

newType= Integer.parseInt((param[1].split("="))[1]);

} else{

text.setText("参数错误,无法启动");

return;

}

注:

String data = getIntent().getDataString();//接收到网页传过来的数据:scheme://com.newnet.hlxc.palmNews?newType=7&contentId=12345

3.OutsideActivity类的具体实现代码:

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.hlxc.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;

/**

* 外部启动Activity

* 描述:该类实现的需求是报名和投票类

* 点击外部分享链接启动本地App并跳转详细页面

*/

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();//接收到网页传过来的数据:sharetest://data/http://www.huxiu.com/

if (data != null) {

String[] split = data.split(getPackageName() + "?");//以data/切割data字符串

String UrlData = split[1]; //就得到:http://www.huxiu.com/(这就是我们需要网页传给我们的数据)

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("TAG", "登陆的状态下=========================");

} else {

if (isBindMobile) {

Log.e("TAG", "已绑定状态下=========================");

openActivity();

} else {

Log.e("TAG", "未绑定状态下=========================");

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("TAG", "未登陆的状态下=========================");

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() {

}

@Override

protected void onResume() {

super.onResume();

Log.e("TAG", "只走了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) {

}

}

参考博文:点击打开链接 http://blog.csdn.net/starry_eve/article/details/52873485

点击打开链接 http://blog.csdn.net/daijin888888/article/details/50009387

点击打开链接 https://www.cnblogs.com/alex-mh/p/7040736.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值