2017-08-10 14 views
0

ロック画面が表示されているときに通知を受け取ると、画面が点灯するはずです。通知が表示されたら起床画面が表示される

private void unlockScreen() { 
    Window window = this.getWindow(); 
    window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 
    window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); 
    window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); 
} 

私は画面のロックを解除する必要があります。その後、私は完全に罰金shapeRoundButton.setImageResource(R.drawable.toggle_on)作品が、unlockScreen()

private void updateNotification(int notificationCode) 
{ 
    switch(notificationCode) 
    { 
     case NotificationService.InterceptedNotificationCode.FACEBOOK_CODE: 
      shapeRoundButton.setImageResource(R.drawable.toggle_on); 
      unlockScreen(); 
      break; 
     case NotificationService.InterceptedNotificationCode.OTHER_NOTIFICATIONS_CODE: 
      shapeRectangleButton.setImageResource(R.drawable.toggle_on); 
      break; 
    } 
} 

それを呼び出すために、これを使用しています。しません。通知が受信されています。

画面がロックされていない理由、または画面のロックを解除する方法を知っている人は誰ですか?乾杯!

答えて

0

この

PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); 
boolean isScreenOn = pm.isScreenOn(); 
Log.e("screen on.................................", ""+isScreenOn); 
if(isScreenOn==false) 
{ 
    WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,"MyLock"); 
    wl.acquire(10000); 
    WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyCpuLock"); 

    wl_cpu.acquire(10000); 
} 
0

がIntentServiceを使用してみてください参照してください。あなたの目的のサービスで、あなたの意思ターゲットを置き換えます

Intent yepIntent = new Intent(context, MyIntentService.class); 
yepIntent.putExtra("foo", true); 
yepIntent.putExtra("bar", "more info"); 
PendingIntent yepPendingIntent = PendingIntent.getService(context, notificationId, yepIntent, PendingIntent.FLAG_CANCEL_CURRENT); 
notificationBuilder.addAction(R.drawable.icon_of_choice, "My Action", yepPendingIntent); 

がマニフェストにあなたのサービスを登録します。

<service 
    android:name="app.great.mypackage.MyIntentService" 
    android:exported="false"/> 

あなたのサービスは、次のようになります。名前

からのフィードバックと

public class MyIntentSerice extends IntentService { 
@Override 
protected void onHandleIntent(Intent intent) { 
    Log.d("myapp", "I got this awesome intent and will now do stuff in the background!"); 
    // .... do what you like 
} 
} 

UPDATE

このトリックは

  1. サービスを使用する
  2. アクションまたはcontentIntentではなくRemoteViewsメソッドを使用してインテントを追加します。組み合わせ

それは次のようになります。

NotificationCompat.Builder builder = new NotificationCompat.Builder(this) 
    .setVisibility(Notification.VISIBILITY_PUBLIC) 
    .setOngoing(true) 
    .setSmallIcon(R.drawable.abc_ic_menu_share_mtrl_alpha) 
    .setContentTitle("My notification") 
    .setContentText("Hello World!"); 

int notificationId = 1; 
Intent yepIntent = new Intent(this, MyIntentService.class); 
yepIntent.setAction("test"); 
yepIntent.putExtra("foo", true); 
yepIntent.putExtra("bar", "more info"); 
PendingIntent yepPendingIntent = PendingIntent.getService(this, 
notificationId, yepIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

// doesn't show up on my lock-screen 
//builder.addAction(R.drawable.abc_ic_menu_share_mtrl_alpha, "My Action", 
yepPendingIntent); 

// asks for unlock code for some reason 
//builder.setContentIntent(yepPendingIntent); 

// Bingo 
RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification); 
view.setOnClickPendingIntent(R.id.notification_closebtn_ib, yepPendingIntent); 
builder.setContent(view); 
+0

は、おそらくそれが明確になされているはずですが、私は、通知を行うが、そのようなFacebookやInstagramのと同類などのアプリケーションからそれらを受けていませんよ。しかし、私はとにかくこれを行って、何が起こるか見るでしょう。 –

関連する問題