tabactivity约6.0权限

时间:2016-06-12 05:43:49

标签: java android tabs

mTabHost = getTabHost();
        mTabHost.addTab(mTabHost.newTabSpec(TAB_NEWS).setIndicator(TAB_NEWS).setContent(new Intent(this, NewsActivity1.class)));
        mTabHost.addTab(mTabHost.newTabSpec(TAB_BBS).setIndicator(TAB_BBS).setContent(new Intent(this, BBSActivity.class)));
        mTabHost.addTab(mTabHost.newTabSpec(TAB_CATEGORY).setIndicator(TAB_CATEGORY).setContent(new Intent(this, CategoryActivity.class)));
        mTabHost.addTab(mTabHost.newTabSpec(TAB_DISCOVER).setIndicator(TAB_DISCOVER).setContent(new Intent(this, DiscoverActivity.class)));
        mTabHost.addTab(mTabHost.newTabSpec(TAB_MINE).setIndicator(TAB_MINE).setContent(new Intent(this, MineActivity.class)));

由于某个原因,我使用TabActivity,但系统的权限对话框无法在targetSdk23中显示。

例如:在NewsActivity,BBSActivity,CategoryActivity,DiscoverActivity,MineActivity中,都无法显示。

请帮助我,谢谢〜

例如DiscoverActivity:

public class DiscoverActivity extends BaseActivity implements View.OnClickListener{
    private RelativeLayout near, plate, search, rate, oil, two_dimension_code, rl_activity, coupon;
    private TextView tvActivityTitle;
    private String url;
    private LoadDialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_discover);
        GoogleAnalyticsUtil.doGoogleAnalytics();
        initView();
        initEvent();
    }

    private void initView() {
        // TODO Auto-generated method stub
        near = (RelativeLayout) findViewById(R.id.discover_near);
        plate = (RelativeLayout) findViewById(R.id.discover_plate);
        search = (RelativeLayout) findViewById(R.id.discover_search);
        rate = (RelativeLayout) findViewById(R.id.discover_rate);
        oil = (RelativeLayout) findViewById(R.id.discover_oil);
        two_dimension_code = (RelativeLayout) findViewById(R.id.rl_twodimension_code);
        rl_activity = (RelativeLayout) findViewById(R.id.rl_activity);
        coupon = (RelativeLayout) findViewById(R.id.rl_coupon);
        tvActivityTitle = (TextView) findViewById(R.id.tv_activity_title);
    }

    private void initEvent() {
        near.setOnClickListener(this);
        plate.setOnClickListener(this);
        search.setOnClickListener(this);
        rate.setOnClickListener(this);
        oil.setOnClickListener(this);
        two_dimension_code.setOnClickListener(this);
        rl_activity.setOnClickListener(this);
        coupon.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        final Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.discover_near:
                GoogleAnalyticsUtil.doGoogleActionAnalytics(GoogleAnalyticsConstant.ActionEvent.NEARPEOPLE_ACTION);
                if (TextUtils.isEmpty(ShareProUtils.getUid(this))) {
                    intent.setClass(this, LoginActivity.class);
                    startActivity(intent);
                } else {
                    intent.setClass(this, NearbyActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.discover_plate:
                intent.setClass(this, ForumActivity.class);
                startActivity(intent);
                break;
            case R.id.discover_search:
                intent.setClass(this, TopicSearchActivity.class);
                startActivity(intent);
                break;
            case R.id.discover_rate:
                intent.setClass(this, RateActivity.class);
                startActivity(intent);
                break;
            case R.id.discover_oil:
                intent.setClass(this, OilActivity.class);
                startActivity(intent);
                break;
            case R.id.rl_twodimension_code:
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                        DialogUtil.getInstance().showPermissionDialog(this, "permission");
                    } else {
                        intent.setClass(DiscoverActivity.this, CaptureActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivityForResult(intent, 1);
                    }
                } else {
                    intent.setClass(DiscoverActivity.this, CaptureActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivityForResult(intent, 1);
                }
                break;
            case R.id.rl_activity:
                intent.setClass(this, WebViewActivity.class);
                intent.putExtra("url", url);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                break;
            case R.id.rl_coupon:
                intent.setClass(this, GroupBuyListActivity.class);
                startActivity(intent);
                break;
        }
    }

    private void loadActivity() {
        Map<String, String> mp = new HashMap<String, String>();
        Okhttp.getIntance().post(Api.REAL_URL, Api.YORKBBS_CMS_TXTSETTING, mp, new StringCallback() {
            @Override
            public void onError(Call call, Exception e) {
            }

            @Override
            public void onResponse(String response) {
                if (!TextUtils.isEmpty(response)) {
                    String result = ParamUtils.ConvertData(response);
                    JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                    if (jsonObject.has("list")) {
                        rl_activity.setVisibility(View.VISIBLE);
                        String list = jsonObject.get("list").toString();
                        List<Discoverac> listObj = new Gson().fromJson(list, new TypeToken<List<Discoverac>>() {
                        }.getType());
                        if (listObj != null && listObj.size() > 0) {
                            tvActivityTitle.setText(listObj.get(0).getTxt());
                            url = listObj.get(0).getUrl();
                        }
                    }
                }
                rl_activity.setVisibility(View.GONE);

            }
        });
    }

    private void check(String ticket) {
        Map<String, String> mp = new HashMap<String, String>();
        mp.put("sessionkey", ShareProUtils.getLoginSession(this));
        mp.put("code", ticket);
        mp.put("merchantid", ShareProUtils.getUid(this));
        Okhttp.getIntance().post(Api.GROUPBUY_URL, Api.GROUPON_CHECK, mp, new StringCallback() {
            @Override
            public void onBefore(Request request) {
                super.onBefore(request);
                dialog = DialogUtil.getInstance().showLoadDialog(DiscoverActivity.this, "正在验证...");
            }

            @Override
            public void onError(Call call, Exception e) {
            }

            @Override
            public void onResponse(String response) {
                if (!TextUtils.isEmpty(response)) {
                    String result = ParamUtils.ConvertData(response);
                    GrouponDetailResponse response1 = new Gson().fromJson(result,GrouponDetailResponse.class);
                    if (response1.getFlag().equals("0")){
                        Intent intent = new Intent(DiscoverActivity.this, TicketCheckSuccessActivity.class);
                        startActivity(intent);
                    }else {
                        Intent intent = new Intent(DiscoverActivity.this, TicketCheckFailActivity.class);
                        startActivity(intent);
                    }
                } else {
                    TipsToast.show(DiscoverActivity.this, "error");
                }
            }

            @Override
            public void onAfter() {
                DialogUtil.getInstance().dissMissDialog(dialog);
                super.onAfter();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (isNet()) {
            loadActivity();
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == 1) {
                Bundle bundle = data.getExtras();
                String result = bundle.getString("result");
                if (!TextUtils.isEmpty(result)) {
                    if (result.contains("code")) {
                        if (TextUtils.isEmpty(ShareProUtils.getUid(this))) {
                            Intent login = new Intent(this, LoginActivity.class);
                            startActivity(login);
                            return;
                        }
                        result = result.replaceAll("http://www.yorkbbs.ca\\?yorkbbscode=","");
                        check(result);
                    } else {
                        Intent intent = new Intent(this, WebViewActivity.class);
                        intent.putExtra("url", result);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(intent);
                    }

                } else {
                    TipsToast.show(this, "scan error");
                }
            }
        }
    }
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        // NOTE: delegate the permission handling to generated method
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        return false;
    }
}

1 个答案:

答案 0 :(得分:0)

TabActivity现已已弃用。要创建Tab,您必须使用FragmentViewPager创建它。

以下是使用TabFragment创建ViewPager的示例。

请参阅此处的例子:http://www.truiton.com/2015/06/android-tabs-example-fragments-viewpager/