Android Wear 앱에서 내 서비스를 호출하지 내가 몇 번 알림을 만들이 응용 프로그램을 원하는 (내 서비스를 호출 할이 코드에서 알림을 만들기위한 매 15 분)알람 관리기는 내가 Android Wear 앱을 만들
AlramManager에 내 서비스를 등록하면 OS에서 생성 된 작업 (adb shell dumpsys alarm > dump.txt
)을 볼 수는 있지만 서비스가 실행되었음을 알리는 알림 또는 로그를 볼 수 없습니다. startService
으로 서비스를 테스트하고 알림 및 로그가 올바르게 작동하므로 어디에서 문제가 있는지 알 수 없습니다. 여기 내가 사용하는 코드는 다음과 같습니다 알람 관리기에 서비스를 등록
MyAlarmService.java
public class MyAlarmService extends Service {
@Override
public void onCreate() {
super.onCreate();
Log.d("From serivce","Service run once");
// Create notification
Context context = this;
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(context.getString(R.string.NotificationTitle))
.setSmallIcon(R.mipmap.ic_launcher_hafez)
.setContentText("Some text");
Notification secondPage =
new NotificationCompat.Builder(context)
.setContentTitle(context.getString(R.string.NotificationTitle))
.setContentText("Some text")
.build();
NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender();
extender.addPage(secondPage);
builder.extend(extender);
NotificationManagerCompat mgr = NotificationManagerCompat.from(context);
int NotificationId = new Random().nextInt(5200);
mgr.notify(NotificationId, builder.build());
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
의 AndroidManifest.xml
...
<service android:name=".MyAlarmService" />
...
코드 : dump.txt
의
Context context = getActivity().getApplicationContext();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
Intent intent = new Intent(context, MyAlarmService.class);
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_FIFTEEN_MINUTES, alarmIntent);
내용
Current Alarm Manager state:
...
Batch{91609e num=3 start=7228838 end=7233540 flgs=0x8}:
...
RTC_WAKEUP #0: Alarm{18a777f type 0 when 1467992333472 org.rashno.mypackagename}
tag=*walarm*:org.rashno.mypackagename/.MyAlarmService
type=0 whenElapsed=-6s582ms when=2016-07-08 20:08:53
window=+11m15s0ms repeatInterval=900000 count=0 flags=0x0
operation=PendingIntent{397c34c: PendingIntentRecord{de77f95 org.rashno.mypackagename broadcastIntent}}
...
Alarm Stats:
...
u0a57:org.rashno.mypackagename +9ms running, 1 wakeups:
+9ms 1 wakes 1 alarms, last -1m33s417ms:
*walarm*:org.rashno.mypackagename/.MyAlarmService
...
...
제안 사항 (아직 * 해결책이 아닙니다 : ^) : 매니페스트에서 서비스를'exported = "true"'로 설정해보십시오. – String
@String 시도해 보았지만 결과는 이전과 동일합니다 –