소스 수정
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
Log.i(TAG, "Received message context " + intent.getExtras().getString("message"));
//String message = getString(R.string.gcm_message);
Vibrator vibrator = (Vibrator)getSystemService(context.VIBRATOR_SERVICE);
vibrator.vibrate(1000);
WakeUpScreen.acquire(getApplicationContext(), 10000);
String message = intent.getExtras().getString("message");
// notifies user
generateNotification(context, message);
}
WakeUpScreen CLASS 추가
import android.content.Context;
import android.os.PowerManager;
/**
* 스크린을 ON한다. 젤리빈 4.2부터는 getWindows() 권장
* @author IKCHOI
*
*/
public class WakeUpScreen {
private static PowerManager.WakeLock wakeLock;
/**
* timeout을 설정하면, 자동으로 릴리즈됨
* @param context
* @param timeout
*/
public static void acquire(Context context, long timeout) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(
PowerManager.ACQUIRE_CAUSES_WAKEUP |
PowerManager.FULL_WAKE_LOCK |
PowerManager.ON_AFTER_RELEASE
, context.getClass().getName());
if(timeout > 0)
wakeLock.acquire(timeout);
else
wakeLock.acquire();
}
/**
* 이 메소드를 사용하면, 반드시 release를 해줘야 함
* @param context
*/
public static void acquire(Context context) {
acquire(context, 0);
}
public static void release() {
if (wakeLock.isHeld())
wakeLock.release();
}
}
Manifest 추가
<uses-permission android:name="android.permission.VIBRATE"/>
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
참고 http://nonstop.pe.kr/android/1612
참고 2 http://www.androidside.com/bbs/board.php?bo_table=b49&wr_id=107992
댓글 없음:
댓글 쓰기