BroadcastReceiver实现Intent的Activity跳转

//2016/10/29///

/by   xbw/


之前写过更新推送,发现又丑又长,巨恶心。

现在感觉腾讯信鸽的消息透传越用越爽,虽然延迟有点高,不过对于非即使通讯已经足够了。


利用腾讯信鸽的消息透传作版本更新提示。

首先是更新弹窗

private void updateshow(String a,final Context context){
        builder.setTitle("更新提示");
        builder.setMessage(a);
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                //MainActivity.webView.loadUrl("http://a.app.qq.com/o/simple.jsp?pkgname=com.xbw.mvp");
                //Intent intent =new Intent(Intent.ACTION_VIEW);
                //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                //在广播里实现intent跳转就需要这行代码。
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                Uri content_url = Uri.parse("http://a.app.qq.com/o/simple.jsp?pkgname=com.xbw.mvp");
                intent.setData(content_url);
                context.startActivity(intent);
                //context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://sj.qq.com/myapp/detail.htm?apkName=com.xbw.mvp")));
            }
        });
        builder.setNegativeButton("忽略", new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
            }
        });
        builder.show();
    }
再是广播中调用。

public void onTextMessage(Context context, XGPushTextMessage message) {
        if(message.getTitle().toString().equals("token")){
            builder=MainActivity.builder;
            updateshow(message.getContent().toString(),context);

        }
    }

private AlertDialog.Builder builder;

以上代码都在信鸽广播透传中,这样就实现了。

更新提示只需要一个token参数加更新内容就好了。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值