按钮无效Android Wear自定义卡

时间:2015-01-30 04:03:16

标签: android wear-os android-cards android-wear-notification

我正在尝试在android Wear应用程序中创建自定义卡(此卡由WearableListenerService创建),我的问题是当卡出现并且我的应用程序关闭时卡上的按钮不起作用,但是当应用程序时运行按钮效果很好。我说最近开发到android并且我没有解决问题,有人可以帮助我吗? 非常感谢你

  1. 服务
  2.  public class ListenerService extends WearableListenerService {
        private static final String _MESSAGE_PATH = "/message_path";
    
        private static final String _NOTIFICATION_NUMBER = "/notificationNumber";
    
        private static Context _context;
    
        public void onMessageReceived(MessageEvent messageEvent) {
    
            switch(messageEvent.getPath()){
                case _MESSAGE_PATH:
                    break;
    
                case _NOTIFICATION_NUMBER:
                    _context = getBaseContext();
                    new Thread(tCards).start();
                    break;
                default:
                    super.onMessageReceived(messageEvent);
                    break;
            }
        }
    
        private Runnable tCards = new Runnable(){
            public void run() {
                Intent _Card = new Intent();
                _Card.setClass(map, CardCall.class);
                _Card.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                _context.startActivity(_Card);
            }
        };
    }
    

    public class ListenerService extends WearableListenerService { private static final String _MESSAGE_PATH = "/message_path"; private static final String _NOTIFICATION_NUMBER = "/notificationNumber"; private static Context _context; public void onMessageReceived(MessageEvent messageEvent) { switch(messageEvent.getPath()){ case _MESSAGE_PATH: break; case _NOTIFICATION_NUMBER: _context = getBaseContext(); new Thread(tCards).start(); break; default: super.onMessageReceived(messageEvent); break; } } private Runnable tCards = new Runnable(){ public void run() { Intent _Card = new Intent(); _Card.setClass(map, CardCall.class); _Card.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); _context.startActivity(_Card); } }; }

    1. CardClass
    2. public class CardCall extends Activity {
      
          ClientAction client = ClientAction.getInstance();
          BoxInsetLayout _boxBK;
          ImageButton imgCancel;
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.cards_main);
      
              CardScrollView cardScrollView =
                      (CardScrollView) findViewById(R.id.card_scroll_view);
              cardScrollView.setCardGravity(Gravity.BOTTOM);
      
              imgCancel = (ImageButton) findViewById(R.id.btnStopSong);
              _boxBK = (BoxInsetLayout) findViewById(R.id.background);
              _boxBK.setBackgroundColor(Color.BLUE);
      
              imgCancel.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      new TaskStop().execute();
                  }
              });
          }
      
          private class TaskStop extends AsyncTask<Void, Void, Void>
          {
              @Override
              protected void onPreExecute() {
                  super.onPreExecute();
      
              }
      
              @Override
              protected Void doInBackground(Void... params) {
                  client.StopSong("");
                  return null;
              }
      
              @Override
              protected void onPostExecute(Void aVoid) {
                  super.onPostExecute(aVoid);
      
              }
          }
      }
      

      1. 卡片布局
      2. public class CardCall extends Activity { ClientAction client = ClientAction.getInstance(); BoxInsetLayout _boxBK; ImageButton imgCancel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cards_main); CardScrollView cardScrollView = (CardScrollView) findViewById(R.id.card_scroll_view); cardScrollView.setCardGravity(Gravity.BOTTOM); imgCancel = (ImageButton) findViewById(R.id.btnStopSong); _boxBK = (BoxInsetLayout) findViewById(R.id.background); _boxBK.setBackgroundColor(Color.BLUE); imgCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new TaskStop().execute(); } }); } private class TaskStop extends AsyncTask<Void, Void, Void> { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected Void doInBackground(Void... params) { client.StopSong(""); return null; } @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); } } }

0 个答案:

没有答案