android app 限制app使用时间

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 20:21   3657   0

/**
* 时间判断
*/
private void limited() {
Time t = new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料。
t.setToNow(); // 取得系统时间。

String time = t.year + "年 " + (t.month + 1) + "月 " + t.monthDay + "日 "
+ t.hour + "h " + t.minute + "m " + t.second;
Log.e("msg", time);
//if (t.year == 2014 && t.month + 1 == 9 && t.monthDay == 23) 测试
// if(t.year!=2020 || (t.month+1)!=5)//这个月
// if(t.year!=2020 || (t.month+1)!=6||t.monthDay!=10) //今天
int mYear=2020,myMonth=6,myMonthDay=30;
if(t.year==mYear && (t.month+1)==myMonth && t.monthDay>=myMonthDay)
{
closeApp();
}else if (t.year>mYear){
closeApp();
}else if (t.year==mYear && (t.month+1)>myMonth){
closeApp();
}
}

/**
* 退出APP
*/
private void closeApp(){
Toast.makeText(IndexMainActivity.this,"试用版时间到自动退出,请联系软件作者微信:18977092827" ,
Toast.LENGTH_LONG).show();

new Handler().postDelayed(new Runnable(){ //延迟执行
@Override
public void run(){
android.os.Process
.killProcess(android.os.Process
.myPid()); // 终止线程
}
}, 3000);
}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP