0
点赞
收藏
分享

微信扫一扫

自己设置包的信息方便更新以及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);

举报

相关推荐

0 条评论