1.得到Realtime
SystemClock.elapsedRealtime(); 从boot获取经历时间,与修改手机时间是无关的。
2.跳转Rate
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
String referrer = "market://details?id=" + mainActivity.getPackageName();
intent.setData(Uri.parse(referrer));
mainActivity.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
} catch (OutOfMemoryError e) {
e.printStackTrace();
throw e;
}
3.判断手机是不是有网
判断有wifi或者是数据流量。
public boolean isNetworkConnected() {
try {
Context context = mainActivity;
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
return true;
}
}
return false;
} catch (Exception e) {
return false;
}
}
网上找到另一个方法,这种不是很正确,因为有卡的手机,它是有volite网络的,判断的结果也是有网。代码如下:
public boolean checkNet(){
ConnectivityManager connectivityManager = (ConnectivityManager) getContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager == null) {
return false;
} else {
NetworkInfo[] net_info = connectivityManager.getAllNetworkInfo();
if (net_info != null) {
for (int i = 0; i < net_info.length; i++) {
if (net_info[i].getState() == NetworkInfo.State.CONNECTED) {
BrickLog.INFO("net connect");
return true;
}
}
}
}
BrickLog.INFO("net disconnect");
return false;
}
}
网友评论