-1
我正在處理Android Wear的自定義通知,當通知向上滑動時應顯示自定義活動。顯示通知,甚至可穿戴功能(如背景和自定義尺寸)都可見,但該活動永遠不會加載也不會顯示。Android Wear自定義通知未顯示活動
另外,MainActivity
和PlaybackNotificationActivity
都應該在創建日誌時將消息寫入日誌。 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();
}
}