Android Wear自定义通知未显示活动

时间:2015-06-21 08:55:23

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

我正在处理Android Wear的自定义通知,该通知应在向上滑动通知时显示自定义活动。显示通知,甚至可穿戴功能(如背景和自定义大小)都可见,但活动永远不会加载也不会显示。

此外,MainActivityPlaybackNotificationActivity都应该在创建日志时向日志写入消息。 MainActivity写入消息,但后者不写。

可能是什么问题?

MainActivity.java

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new NotificationBuilder(this).showNotification();
        Log.e("MainActivity", "Reached");
        finish();
    }
}

NotificationBuilder.java

public class NotificationBuilder {
    private final Context mContext;

    public NotificationBuilder(Context context) {
        mContext = context;
    }

    public Notification buildNotification() {
        Notification.Builder builder = new Notification.Builder(mContext)
                .setContentTitle("Title")
                .setContentText("Content text")
                .setSmallIcon(R.mipmap.ic_launcher);

        Intent playbackIntent = new Intent(mContext, PlaybackNotificationActivity.class);

        PendingIntent playbackPendingIntent = PendingIntent.getActivity(
                mContext, 0, playbackIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        Notification.WearableExtender extender = new Notification.WearableExtender()
                .setBackground(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher))
                .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)
                .setDisplayIntent(playbackPendingIntent);

        builder.extend(extender);

        return builder.build();
    }

    public void showNotification() {
        Notification notification = buildNotification();

        NotificationManager manager = (NotificationManager)
                mContext.getSystemService(Context.NOTIFICATION_SERVICE);

        manager.notify(1, notification);
    }
}

PlaybackNotificationActivity.java

public class PlaybackNotificationActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_playback_notification);

        Log.e("NotificationActivity", "Reached");
        Toast.makeText(this,  "Toast", Toast.LENGTH_SHORT).show();
    }
}

1 个答案:

答案 0 :(得分:0)

事实证明,Android Wear的模拟器应该受到指责,它可以在物理智能手表上完美运行,但不能在模拟器上运行。