自定义通知不';不要穿Android Wear跑步

自定义通知不';不要穿Android Wear跑步,android,wear-os,Android,Wear Os,我正在玩Wear SDK并尝试创建一个Wear应用程序。 我想显示自定义通知,但它不起作用 这是我的活动代码: public class WearActivity extends Activity { private Button notifyBtn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

我正在玩Wear SDK并尝试创建一个Wear应用程序。 我想显示自定义通知,但它不起作用

这是我的活动代码:

public class WearActivity extends Activity {
    private Button notifyBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wear);
        final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);

        stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {

            @Override
            public void onLayoutInflated(WatchViewStub stub) {
                notifyBtn = (Button) stub.findViewById(R.id.notifyBtn);
                notifyBtn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        createNotification();

                    }
                });
            }
        });
    }

    private void createNotification(){
        Toast.makeText(this, "Press", Toast.LENGTH_LONG).show();
        //Create Intent
        Intent notificationIntent =
                new Intent(this, WearNotificationActivity.class)
                        .putExtra("EXTRA_STRING", "Hi, I'm an EXTRA!");
        PendingIntent pendingNotificationIntent =
                PendingIntent.getActivity(this,0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);

        Notification notification =
                new Notification.Builder(this)
                        .extend(new Notification.WearableExtender()
                                .setDisplayIntent(pendingNotificationIntent)
                                .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM))
                        .build();

        NotificationManager notificationManager =
                (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);

        notificationManager.notify(0, notification);
    }
}
尽管按钮按下已触发,但不会显示自定义通知。 我也编辑了清单:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tizianobasile.wearactivity" >

    <uses-feature android:name="android.hardware.type.watch" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.DeviceDefault.Light" >
        <activity
            android:name=".WearActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".WearNotificationActivity"
            android:label="@string/title_activity_wear_notification"
            android:exported="true"
            android:allowEmbedded="true"
            android:taskAffinity=""
            android:theme="@android:style/Theme.DeviceDefault.Light">
        </activity>
    </application>

</manifest>


我真的找不到原因,我的代码与文档代码几乎相同。

一般来说,Android Wear中的通知必须使用
smallIcon
。根据我的测试,尽管在带有自定义卡布局的通知(
setDisplayIntent
)中,图标甚至没有显示-您仍然需要指定它才能在Android Wear上显示

例如:

Notification notification =
    new Notification.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .extend(new Notification.WearableExtender()
            .setDisplayIntent(pendingNotificationIntent)
            .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM))
        .build();

通常,Android Wear中的通知必须使用
smallIcon
。根据我的测试,尽管在带有自定义卡布局的通知(
setDisplayIntent
)中,图标甚至没有显示-您仍然需要指定它才能在Android Wear上显示

例如:

Notification notification =
    new Notification.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .extend(new Notification.WearableExtender()
            .setDisplayIntent(pendingNotificationIntent)
            .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM))
        .build();

通常,Android Wear中的通知必须使用
smallIcon
。根据我的测试,尽管在带有自定义卡布局的通知(
setDisplayIntent
)中,图标甚至没有显示-您仍然需要指定它才能在Android Wear上显示

例如:

Notification notification =
    new Notification.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .extend(new Notification.WearableExtender()
            .setDisplayIntent(pendingNotificationIntent)
            .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM))
        .build();

通常,Android Wear中的通知必须使用
smallIcon
。根据我的测试,尽管在带有自定义卡布局的通知(
setDisplayIntent
)中,图标甚至没有显示-您仍然需要指定它才能在Android Wear上显示

例如:

Notification notification =
    new Notification.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .extend(new Notification.WearableExtender()
            .setDisplayIntent(pendingNotificationIntent)
            .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM))
        .build();

多么奇怪的行为!在添加smallIcon后,它就可以工作了…非常感谢你,Maciejwhat a奇怪的行为!在添加smallIcon后,它就可以工作了…非常感谢你,Maciejwhat a奇怪的行为!在添加smallIcon后,它就可以工作了…非常感谢你,Maciejwhat a奇怪的行为!在添加smallIcon后它就可以工作了…非常感谢Maciej