每一具身体。
与此链接cwac-wakeful相同
我有AppListener类:
public class AppListener implements WakefulIntentService.AlarmListener {
public void scheduleAlarms(AlarmManager amr, PendingIntent pi, Context ctx){
amr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+60000, AlarmManager.INTERVAL_FIFTEEN_MINUTES, pi);
}
public void sendWakefulWork(Context ctx){
WakefulIntentService.sendWakefulWork(ctx, AlarmServiceWakeful.class);
}
public long getMaxAge(){
return (AlarmManager.INTERVAL_FIFTEEN_MINUTES*2);
}
}然后,我创建了一个XML元数据文件,其中标识了实现WakefulIntentService.AlarmListener的类,因此wakeful.xml:
<WakefulIntentService
listener="com.example.wakefulintentservicetest.AppListener"
/>接下来,在清单中将我的AlarmReceiver注册为,设置为响应ACTION_BOOT_COMPLETED广播,并使用指向上一步中的XML资源的com.commonsware.cwac.wakeful元素,类似于:
<receiver android:name="com.commonsware.cwac.wakeful.AlarmReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<meta-data
android:name="com.commonsware.cwac.wakeful"
android:resource="@xml/wakeful"/>
</receiver>同样,在project.propertise中未注释下面的代码行:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt并将以下代码添加到proguard-project.txt中:
-keep class com.example.wakefulintentservicetest.** {公有保护私有*;}
但是当我在mainactivity中调用下面的代码时,oncreate方法:
WakefulIntentService.scheduleAlarms(new AppListener(), this, false);给了我以下错误:
java.lang.NoClassDefFoundError:com/example/wakefulintentservicetest/AppListener每个人都能帮助我吗?
提前感谢
发布于 2015-02-15 01:58:19
看起来您在清单中定义了错误的alarmReceiver包。
com.commonsware.cwac.wakeful.AlarmReceiver
它应该是您的包名:
com.example.wakefulintentservicetest...
https://stackoverflow.com/questions/28518089
复制相似问题