2014-10-19 2 views
0

내 의견으로는이 일을하는 방법을 하루 종일 검색하고 있습니다 ... 간단한 앱 ... 알람이 울리며 앱이 울리면 내 그는 알람을 끌 수 있도록 사용자 화면 앞에 응용 프로그램은 ... 내 활동에 은 내가 ... 리시버를 호출사용자가 집 버튼을 클릭했을 때도 알람 브로드 캐스트 수신기에서 활동 시작

registerReceiver(mReceiver, new IntentFilter("sample")); 
PendingIntent pendingIntent = PendingIntent.getBroadcast(MapActivity.this, 0, new Intent("sample"),0); 
AlarmManager alarmManager = (AlarmManager)(MapActivity.this.getSystemService(Context.ALARM_SERVICE)); 

을 의도를 설정하고이 내 onRecieve 방법

입니다
@Override 
    public void onReceive(Context context, Intent intent) { 

    Toast.makeText(context, "Alarm time has been reached", Toast.LENGTH_LONG).show(); 
    Uri notifikacijaAlarma = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); 
    final Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notifikacijaAlarma); 
    r.play(); 

    PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); 
    WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK, "TRAININGCOUNDOWN"); 
    wl.acquire(); 

    Intent i = new Intent(getBaseContext(), GlavniIzbornik.class); 
    i.setAction(Intent.ACTION_MAIN); 
    i.addCategory(Intent.CATEGORY_LAUNCHER); 
    i.setFlags(Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); 

    startActivity(i); 
    wl.release(); 

}    

다른 응용 프로그램으로 이동하거나 다른 작업을 수행 할 때도 내 경보가 울립니다. 전화로 ... 그것은 토스트를 보여 주며 벨소리를 재생하지만 그것은 내 앱을 앞에 가져 오지 않습니다. 수동으로 내 앱으로 이동하면 액티비티가 시작되지만 앱을 가져올 수 없으므로 내 앱이 앞에 표시됩니다. .

아무에게도 제안 사항이 있습니까? 나는 내 알람 활동에서 벨소리를 재생해야 알

PS는 ... 난 그냥 모든 코드가 실행됩니다 경우 명시 적 Intent하여 Activity을 시작 ...

+1

와우, 고마워 ... 마침내 작동합니다 ...이 문제에 얼마나 많은 돈을 지출했는지 말할 수는 없습니다 ... – user3632055

+1

고마워요. 대답했지만 지금은 그랬어 ... :) – user3632055

+0

Stackoverflow에 오신 것을 환영합니다. 숙박을 즐기십시오. 많은 것을 배우기를 바랍니다. –

답변

0

을보고 싶었다. 줄을 i.setAction(...)i.setCategory(...)으로 삭제하십시오. 이것들은 발동기에 Activity을 표시하는 매니페스트에 사용됩니다.

다음으로 documentation에 따르면 Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY을 직접 설정하지 마십시오.

new Intent(context, GlavniIzbornik.class); 또는 context.startActivity(i) 같이 BroadcastReceiver.onReceive(...) 사용 context에,하지 EVER 사용 getBaseContext()를 수행합니다. Activity 또는 Servicethis을 사용하십시오.

관련 문제