1
private void notification() { 

    NotificationManagerCompat manager = NotificationManagerCompat.from(getApplication()); 

    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplication()); 
    builder.setAutoCancel(false); 
    builder.setSmallIcon(R.mipmap.ic_launcher); 

    Notification notification = builder.getNotification(); 
    notification.flags |= Notification.FLAG_ONGOING_EVENT; 
    notification.flags |= Notification.FLAG_NO_CLEAR; 
    notification.flags |= Notification.FLAG_SHOW_LIGHTS; 
    builder.setContentTitle(getResources().getString(R.string.app_name)); 

    if (WearableListener.STATE_CONNECTED == WearableManager.getInstance().getConnectState()) { 
     builder.setContentText(getResources().getString(R.string.connected)); 
     builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); 
    } else { 
     builder.setContentText(getResources().getString(R.string.not_connected)); 
    } 

    Intent intent = new Intent(this, homepage.class); 
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); 
    manager.notify(R.mipmap.ic_launcher, builder.build()); 
} 

private static final Intent ACCESSIBILITY_INTENT = new Intent("android.settings.ACCESSIBILITY_SETTINGS"); 
public static final Intent NOTIFICATION_LISTENER_INTENT = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); 

private WearableListener wearableListener = new WearableListener() { 
    @Override 
    public void onConnectChange(int oldState, int newState) { 
     runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 
       updateMainActivity(); 
      } 
     }); 

     bluetoothConnectStateSave = newState; 
     Log.e(TAG, "WearableListener newState=" + newState); 
     switch (newState) { 
      case WearableListener.STATE_NONE://0 
       bluetoothConnectState = newState; 
       break; 
      case WearableListener.STATE_CONNECTING://2 
       pview.removeCallbacks(timeRunnable); 
       bluetoothConnectState = newState; 
       count = 0; 
       count_max = COUNT_MAX - CONNECT_DELAY; 
       count_try_disconnect = 0; 
       pview.post(timeRunnable); 
       break; 
      case WearableListener.STATE_CONNECTED://3 
       handler.removeMessages(HANDLE_MESSAGE_RECONNECT_AUTO); 
       bluetoothConnectState = newState; 
       pview.removeCallbacks(timeRunnable); 
       notification(); 
       break; 
      case WearableListener.STATE_CONNECT_FAIL://4 
      case WearableListener.STATE_CONNECT_LOST://5 
      case WearableListener.STATE_DISCONNECTING://6 
       notification(); 
       break; 
     } 
     Log.e(TAG, "WearableListener bluetoothConnectState=" + bluetoothConnectState + " bluetoothConnectStateSave=" + bluetoothConnectStateSave); 
     Log.e(TAG, "WearableListener count=" + count + " count_max=" + count_max); 
    } 

    @Override 
    public void onDeviceChange(BluetoothDevice bluetoothDevice) { 
     runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 
       updateMainActivity(); 
      } 
     }); 
    } 

    @Override 
    public void onDeviceScan(BluetoothDevice bluetoothDevice) { 

    } 

    @Override 
    public void onNameChange(String s) { 
    } 
}; 
private void updateMainActivity() { 
    device = WearableManager.getInstance().getRemoteDevice(); 
} 

上記は、Bluetooth低エネルギー接続および通知部分のプロジェクトのコードです。私はアンドロイドウェア(時計は彼らが接続されていることを意味する "リスニング"を表示している)とアンドロイド電話の間に接続することができます。ただし、通知は電話でのみ表示され、アンドロイドウェアで通知を受け取ることはできません。私のプロジェクトの問題は何ですか?助けてください。どうもありがとうございました。Androidの着用で通知を表示

答えて

0

これをチェックしてみましたか?support page?あなたが与えられたトラブルシューティングの手順を試してみて、各ステップの後に時計をチェックして、通知が機能し始めるかどうかを確認してください。それでも動作しない場合は、resetting your watch to factory settingsを試してください。時計を再起動することは、ほとんどの人にとっては短期間では効果があるようですが、時には非常に迅速な場合はproblem can re-occurとなります。このAndroid Wear notifications issues forumを確認して、該当する回避策が役立つかどうかを確認することもできます。

関連する問題