//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参数加更新内容就好了。