-
M9收费应用时间限制实现licen..
软件中心提供的license验证接口LicenseResult .getStartDate方法返回的产品试用开始日期。原来的接口在一些临界的日期如12月时会造成日期出现错乱,故需要升级提供给开发者的jar接口文件。由原来的MStoreLicensing_1.3.jar升级为MStoreLicensing_1.4.jar
请大家下载《Meizu M9软件中心收费开发SDK1.1》该收费SDK已经包含MStoreLicensing_1.4.jar :http:developer.meizu.comm8sdkhelpsdk.jsp
下面提供判断应用是否已经过期以及如果计算剩余的试用时间的参考代码 注意:需要配合新的jar文件MStoreLicensing_1.4.jar
JAVA CODE
---------------------------------------------------------------------------------------------
该方法返回license文件的生成日期(注:该日期的值只精确到天,即时分秒为随机值)
CalendarbeginCal=result.getStartDate;
Log.e,试用开始的日期为:+beginCal.getCalendar.YEAR+年+beginCal.getCalendar.MONTH+1+月+beginCal.getCalendar.DAY_OF_MONTH+日;
**
*以下是可供参考的过期判断
*
你自己定义的过期天数
finalintexpireDays=3;
获取当前日期
CalendarnowCal=Calendar.getInstance;
求剩余的天数
longdif=nowCal.getTimeInMillis-beginCal.getTimeInMillis;
intpassDay=intdif24*60*60*1000;
intleft=expireDays-passDay;
Log.e剩余天数,+left;
ifleft0{
未过期
Log.e,未过期;
}else{
过期
Log.e,过期;
}
-
APN之间的切换
APN切换主要分为以下三个步骤:
1、获取当前系统所有的APN
2、设置当前使用的APN
3、打开APN连接。
final Uri APN_TABLE_URI = Uri.parsecontent:telephonycarriers; 全部使用的apn列表,需要传递查询参数,current=1
final Uri PREFERRED_APN_URI = Uri.parsecontent:telephonycarrierspreferapn; 当前设置的apn
大概的代码步骤:
String projection[] = { _id,apn,type,current,name };
Cursor cr = c.getContentResolver.queryAPN_TABLE_URI, projection,current=1, null, null;
ListAPN list = new ArrayListAPN;
while cr != null cr.moveToNext {
APN a = new APN;
a.id = cr.getStringcr.getColumnIndex_id;
a.apn = cr.getStringcr.getColumnIndexapn;
a.type = cr.getStringcr.getColumnIndextype;
a.name = cr.getStringcr.getColumnIndexname;
if !hasWapAPN
hasWapAPN = a.name.equalsaddAPNName;
list.adda;
}
if cr != null
cr.close;
return list;
现在list里面就是设置项里面出现的APN列表,
设置并打开一个APN连接:
public void openApnAPN apn{
ContentValues values = new ContentValues;
values.putapn_id, apn.id;
c.getContentResolver.updatePREFERRED_APN_URI, values, _id=?,new String[] { apn.id };设置当前使用的APN为需要设置的APN对象
Log.iTAG, 打开APN连接: + apn.name;
ConnectivityManager connManager = ConnectivityManagerc.getSystemServiceContext.CONNECTIVITY_SERVICE;
int i = connManager.startUsingNetworkFeatureConnectivityManager.TYPE_MOBILE, enableMMS;打开新的APN连接
switch i {
case 0:
Log.iTAG, APN已经激活,可以使用网络;
break;
case 1:
Log.iTAG, 请求开始,等待连接通知;
break;
case 2:
Log.iTAG, apn没有设置好;
break;
case 3:
Log.iTAG, 请求失败;
break;
case 4:
Log.iTAG, 系统忙,例如net已经连接;
break;
case 5:
Log.iTAG, 请求使用wap失败,wifi已经打开;
break;
default:
Log.iTAG, 请求错误,错误代码: + i;
break;
}
}
public APN {
String id;
String apn;
String type;
}
设置并使用新的连接就是这样,
需要写一个BroadcastReceiver对当前的网络进行监听,这个代码就不用写了。需要的可以去百度。