首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

自各儿设置包的信息方便更新以及alarm的使用启动服务

2012-08-30 
自己设置包的信息方便更新以及alarm的使用启动服务manifest xmlns:androidhttp://schemas.android.com/

自己设置包的信息方便更新以及alarm的使用启动服务

<manifest xmlns:android="http://schemas.android.com/apk/res/android"?
? package="org.moo.android.myApp"?
? android:versionCode="12"?
? android:versionName="1.2.37">?
try?
{?
? ? PackageManager manager = context.getPackageManager();?
? ? PackageInfo info = manager.getPackageInfo("org.moo.android.myApp", 0);?
? ? int code = info.versionCode;?
? ? String name = info.versionName;?
?
? ? // Compare with values on the server to see if there is a new version?
}?
catch(NameNotFoundException nnf)?
{?
? ? nnf.printStackTrace();?
}?

2.

final Intent intent = new Intent(context, YourService.class);?
final PendingIntent pending = PendingIntent.getService(context, 0, intent, 0);?
final AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);?
alarm.cancel(pending);?
long interval = 30000;//milliseconds?
alarm.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(),interval, pending);?

热点排行