Android 按钮不起作用,请佩戴自定义卡

Android 按钮不起作用,请佩戴自定义卡,android,wear-os,android-cards,android-wear-notification,Android,Wear Os,Android Cards,Android Wear Notification,我正在尝试在android wear应用程序中创建一张自定义卡(该卡由WearableListenerService创建),我的问题是当卡出现并且我的应用程序关闭时,卡上的按钮不起作用,但当应用程序运行时,按钮工作正常。我最近表示要开发android,但我还没有解决这个问题,有人能帮我吗? 多谢各位 服务 public class ListenerService extends WearableListenerService { private static final String

我正在尝试在android wear应用程序中创建一张自定义卡(该卡由WearableListenerService创建),我的问题是当卡出现并且我的应用程序关闭时,卡上的按钮不起作用,但当应用程序运行时,按钮工作正常。我最近表示要开发android,但我还没有解决这个问题,有人能帮我吗? 多谢各位

  • 服务
  •  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 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);
    
            }
        }
    }
    
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.wearable.view.BoxInsetLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/background"
            android:layout_height="match_parent"
            android:layout_width="match_parent">
    
            <android.support.wearable.view.CardScrollView
                android:id="@+id/card_scroll_view"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                app:layout_box="bottom">
    
                <android.support.wearable.view.CardFrame
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent">
    
                    <LinearLayout
                        android:layout_height="wrap_content"
                        android:layout_width="match_parent"
                        android:orientation="vertical"
                        android:paddingLeft="5dp">
    
                        <TextView
                            android:fontFamily="sans-serif-light"
                            android:layout_height="wrap_content"
                            android:layout_width="100dp"
                            android:text="Text titulo"
                            android:textColor="@color/black"
                            android:textSize="20sp"/>
                        <TextView
                            android:fontFamily="sans-serif-light"
                            android:layout_height="wrap_content"
                            android:text="textDescricao"
                            android:textColor="@color/black"
                            android:layout_width="100dp"
                            android:textSize="14sp"/>
    
    
                        <ImageButton
                            android:layout_width="50dp"
                            android:layout_height="50dp"
                            android:id="@+id/btnStopSong"
                            android:src="@drawable/ic_end_white_36dp"
                            android:background="@drawable/button_round"
                            android:layout_gravity="bottom" />
    
                    </LinearLayout>
                </android.support.wearable.view.CardFrame>
            </android.support.wearable.view.CardScrollView>
        </android.support.wearable.view.BoxInsetLayout>
    
    </RelativeLayout>
    
    公共类CardCall扩展活动{
    ClientAction客户端=ClientAction.getInstance();
    BoxInsettLayout_boxBK;
    ImageButton imgCancel;
    @凌驾
    创建时受保护的void(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cards_main);
    CardScrollView CardScrollView=
    (CardScrollView)findViewById(R.id.card\u scroll\u视图);
    cardScrollView.setCardGravity(Gravity.BOTTOM);
    imgCancel=(ImageButton)findViewById(R.id.btnStopSong);
    _boxBK=(BoxInsetLayout)findViewById(R.id.background);
    _boxBK.setBackgroundColor(颜色:蓝色);
    imgCancel.setOnClickListener(新视图.OnClickListener(){
    @凌驾
    公共void onClick(视图v){
    新建TaskStop().execute();
    }
    });
    }
    私有类TaskStop扩展了异步任务
    {
    @凌驾
    受保护的void onPreExecute(){
    super.onPreExecute();
    }
    @凌驾
    受保护的Void doInBackground(Void…参数){
    客户。StopSong(“”);
    返回null;
    }
    @凌驾
    受保护的void onPostExecute(void避免){
    super.onPostExecute(避免);
    }
    }
    }
    

  • 卡片布局
  • 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);
    
            }
        }
    }
    
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.wearable.view.BoxInsetLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/background"
            android:layout_height="match_parent"
            android:layout_width="match_parent">
    
            <android.support.wearable.view.CardScrollView
                android:id="@+id/card_scroll_view"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                app:layout_box="bottom">
    
                <android.support.wearable.view.CardFrame
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent">
    
                    <LinearLayout
                        android:layout_height="wrap_content"
                        android:layout_width="match_parent"
                        android:orientation="vertical"
                        android:paddingLeft="5dp">
    
                        <TextView
                            android:fontFamily="sans-serif-light"
                            android:layout_height="wrap_content"
                            android:layout_width="100dp"
                            android:text="Text titulo"
                            android:textColor="@color/black"
                            android:textSize="20sp"/>
                        <TextView
                            android:fontFamily="sans-serif-light"
                            android:layout_height="wrap_content"
                            android:text="textDescricao"
                            android:textColor="@color/black"
                            android:layout_width="100dp"
                            android:textSize="14sp"/>
    
    
                        <ImageButton
                            android:layout_width="50dp"
                            android:layout_height="50dp"
                            android:id="@+id/btnStopSong"
                            android:src="@drawable/ic_end_white_36dp"
                            android:background="@drawable/button_round"
                            android:layout_gravity="bottom" />
    
                    </LinearLayout>
                </android.support.wearable.view.CardFrame>
            </android.support.wearable.view.CardScrollView>
        </android.support.wearable.view.BoxInsetLayout>
    
    </RelativeLayout>