android:layout_with="",Android custom notification layout with RemoteView

I'm trying to create a custom notification for my android app using this post, and I stumbled upon a problem which I tried to resolve for the last 2 hours.

Only the imageview of my layout shows, and I can't figure out how to make it works like intended.

My code:

package be.ac.ucl.lfsab1509.cumulus.services;

import android.app.Notification;

import android.app.PendingIntent;

import android.content.Intent;

import android.support.v4.app.NotificationCompat;

import android.support.v4.app.TaskStackBuilder;

import android.widget.RemoteViews;

import be.ac.ucl.lfsab1509.cumulus.R;

import be.ac.ucl.lfsab1509.cumulus.activities.MainActivity;

import be.ac.ucl.lfsab1509.cumulus.entities.Song;

public class CumulusNotification {

private CumulusService mCtx;

private CumulusMediaPlayer mPlayer;

private Notification mNotification;

private NotificationCompat.Builder mBuilder;

private RemoteViews mContentView;

public CumulusNotification(CumulusService ctx, CumulusMediaPlayer player){

mCtx = ctx;

mPlayer = player;

mBuilder = new NotificationCompat.Builder(

mCtx);

mBuilder.setSmallIcon(R.drawable.ic_stat_cumulus_notification);

//mBuilder.setContentTitle("Cumulus is playing");

//mBuilder.setTicker("Cumulus");

//mBuilder.setContentText(mCtx.getCurrentSong().title());

Intent resultIntent = new Intent(mCtx, MainActivity.class);

resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK

| Intent.FLAG_ACTIVITY_CLEAR_TOP);

resultIntent.setAction(Intent.ACTION_MAIN);

TaskStackBuilder stackBuilder = TaskStackBuilder.create(mCtx);

stackBuilder.addParentStack(MainActivity.class);

stackBuilder.addNextIntent(resultIntent);

PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,

PendingIntent.FLAG_UPDATE_CURRENT);

mBuilder.setContentIntent(resultPendingIntent);

mContentView = new RemoteViews(mCtx.getPackageName(), R.layout.statusbar);

mContentView.setImageViewResource(R.id.notifimage, R.drawable.cumulus_icon);

mContentView.setTextViewText(R.id.notiftitle, "Custom notification");

mContentView.setTextViewText(R.id.notiftext, "This is a custom layout");

mBuilder.setContent(mContentView);

}

public void startNotification() {

mNotification = mBuilder.build();

//mNotification.contentView = mContentView;

mCtx.startForeground(R.integer.NOTIFICATION_ID, mNotification);

}

public void updateSong(Song song){

mBuilder.setContentText(song.title());

mNotification = mBuilder.build();

mCtx.startForeground(R.integer.NOTIFICATION_ID, mNotification);

}

}

The xml file:

android:id="@+id/layout"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="10dp"

android:gravity="left" >

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_alignParentLeft="true"

android:layout_marginRight="10dp" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toRightOf="@id/notifimage" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toRightOf="@id/notifimage"

android:layout_below="@id/notiftitle" />

6c1555302777729326ca3efa0910d9ec.png

Thanks for the help

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值