2017-01-05 4 views
0

コード:通知のsetOnClickPendingIntentがアンドロイドNで機能しないのですか?詳細:クリックは2回必要ですか?なぜですか?

intent = new Intent(ACTION_STOP); 
intent.setClass(context, SoundRecorderService.class); 
pIntent = PendingIntent.getService(context, 0, intent, 0); 
mNotificationView.setOnClickPendingIntent(R.id.btn_stop, pIntent); 

Notification.Builder builder=new Notification.Builder(context); 
Notification notification = builder.build(); 
notification.contentView = mNotificationView; 
notification.flags |= Notification.FLAG_ONGOING_EVENT; 

notification.icon = R.drawable.notification_ic_small; 
notification.contentIntent = pIntent; 
startForeground(START_NOTIFICATION_ID, notification); 

これらのコードはandroid Mでよくやります。しかし、それはandroid Nで異常に実行されます。 btn_stopボタンを最初にクリックすると、電話システムはこれをPendingIntentに送信しないので、SoundRecorderService.classを開始しません。次にそれをもう一度クリックして、それが動作します。

答えて

0

大変申し訳ございません。

<ImageView 
      android:id="@+id/btn_stop" 
      android:layout_width="17dp" 
      android:layout_height="17dp" 
      android:layout_gravity="center_vertical" 
      android:background="@drawable/notification_background" 
      android:focusable="true" 
      android:focusableInTouchMode="true" 
      android:src="@drawable/notification_stop" 

アンドロイド:アンドロイドへfocusableInTouchMode = "true" を修正:クリッカブル= "true" を正しいコード:

<ImageView 
      android:id="@+id/btn_stop" 
      android:layout_width="17dp" 
      android:layout_height="17dp" 
      android:layout_gravity="center_vertical" 
      android:focusable="true" 
      android:clickable="true" 
      android:src="@drawable/notification_stop" /> 
マイ通知remoteviewレイアウトは一点、エラーコードを修正します
関連する問題