2016-09-12 16 views
0

「コール」アプリを使用しています。Wake LockがAndroidロリポップ(API 21)で動作しない5.0.2

API 21で 'wake lock'をリリースする際に問題が発生しています。(Kitkat APIではなくAPI 21で問題なく動作します)コール活動を開始する

私のコードは次のようになります。これは、デバイスのロックを解除するために

Intent callIntent = new Intent(context, CallActivity.class); 
        callIntent.putExtra(QBServiceConsts.EXTRA_OPPONENTS, (Serializable) qbUsersList); 
        callIntent.putExtra(QBServiceConsts.EXTRA_START_CONVERSATION_REASON_TYPE, 
          StartConversationReason.INCOME_CALL_FOR_ACCEPTION); 
        callIntent.putExtra(QBServiceConsts.EXTRA_CONFERENCE_TYPE, qbConferenceType); 
        callIntent.putExtra(QBServiceConsts.EXTRA_SESSION_DESCRIPTION, qbRtcSessionDescription); 
        callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        context.getApplicationContext().startActivity(callIntent); 

です。

km = (KeyguardManager) context .getSystemService(Context.KEYGUARD_SERVICE); 
       kl = km .newKeyguardLock("MyKeyguardLock"); 
       kl.disableKeyguard(); 
       PowerManager pm = (PowerManager) context .getSystemService(Context.POWER_SERVICE); 
       wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyWakeLock"); 
       wakeLock.acquire(); 

私はCallアクティビティの中でこのコードを試しました。

Window window = getWindow(); 
     window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD 
       | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED 
       | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON 
       | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 

そして、私のマニフェストは次のとおりです。

<activity 
      android:name=".ui.activities.call.CallActivity" 
      android:configChanges="keyboardHidden|orientation|screenSize" 
      android:launchMode="singleTask" 
      android:screenOrientation="portrait" /> 
+0

良い質問!!! –

答えて

1

私が使用したソリューションは、一つの活性を作成し、その中にフラグkeyguard_dismissを設定することがわかっています。

public class KeyGuardDismissActivity extends Activity { 

    private ScreenOnReceiver receiver; 
    public static final String TAG = KeyGuardDismissActivity.class.getSimpleName(); 
    private static List<QBUser> qbUsersList; 
    private static QBRTCTypes.QBConferenceType qbConferenceType; 
    private static QBRTCSessionDescription qbRtcSessionDescription; 

    public static KeyGuardDismissActivity instance; 

    @Override 
    public void onAttachedToWindow() { 
     super.onAttachedToWindow(); 
     Window window = getWindow(); 
     window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD 
       | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED 
       | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON 
       | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     Log.e(TAG,"Start keyguard dismisser!"); 
     if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { 
      startActivity(new Intent(getApplicationContext(),CallActivity.class)); 
      finish(); 
      return; 
     } 

     qbUsersList = (ArrayList<QBUser>)getIntent().getSerializableExtra(QBServiceConsts.EXTRA_OPPONENTS); 
     qbConferenceType = (QBRTCTypes.QBConferenceType) getIntent().getExtras().getSerializable(QBServiceConsts.EXTRA_CONFERENCE_TYPE); 
     qbRtcSessionDescription = (QBRTCSessionDescription) getIntent().getExtras().getSerializable(QBServiceConsts.EXTRA_SESSION_DESCRIPTION); 

     instance = this; 
     receiver = new ScreenOnReceiver(); 
//  registerReceiver(receiver, receiver.getFilter()); 

     Intent broadcast = new Intent(KeyGuardDismissActivity.this, ScreenOnReceiver.class); 
     sendBroadcast(broadcast); 

    } 

    @Override 
    protected void onStart() { 
     super.onStart(); 
     instance = this; 
    } 

    public void dismissingKeyguard() { 
     Log.e(TAG, "Dismissing keyguard!"); 

     Handler handler = new Handler(); 
     handler.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       Intent yourRealActivity = new Intent(getApplicationContext(), CallActivity.class); 
       yourRealActivity.putExtra(QBServiceConsts.EXTRA_OPPONENTS, (Serializable) qbUsersList); 
       yourRealActivity.putExtra(QBServiceConsts.EXTRA_START_CONVERSATION_REASON_TYPE, 
         StartConversationReason.INCOME_CALL_FOR_ACCEPTION); 
       yourRealActivity.putExtra(QBServiceConsts.EXTRA_CONFERENCE_TYPE, qbConferenceType); 
       yourRealActivity.putExtra(QBServiceConsts.EXTRA_SESSION_DESCRIPTION, qbRtcSessionDescription); 
       yourRealActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       startActivity(yourRealActivity); 
//    if (receiver != null) { 
//     unregisterReceiver(receiver); 
//    } 
      } 
     }, 1000); 

     finish(); 

    } 

    @Override 
    protected void onDestroy() { 
     super.onDestroy(); 
     getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD 
       | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED 
       | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON 
       | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 

    } 

    public static class ScreenOnReceiver extends BroadcastReceiver { 

     @Override 
     public void onReceive(Context context, Intent intent) { 
      Log.e(TAG,"Screen on, yay!"); 
      KeyGuardDismissActivity.instance.dismissingKeyguard(); 
     } 

     public IntentFilter getFilter() { 
      IntentFilter filter = new IntentFilter(); 
      filter.addAction(Intent.ACTION_SCREEN_ON); 
      return filter; 
     } 
    } 
} 

また、コールアクティビティでもフラグを設定します。

+0

良い!!!!!!!!!!!!!!!! –

関連する問題