1

I've checked the following question, As seen i understood that i can only use compatible views with RemoteViews, i'm using a Linear and ImageView which are working, every time i trigger the Notification method, i get the " Couldn't expand Remoteviews " error .

My layout is as the following :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="5dp">


<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp">


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/AppIcon1" />
</LinearLayout>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/AppIcon2" />
</LinearLayout>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/AppIcon3" />
</LinearLayout>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/AppIcon4" />
</LinearLayout>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/AppIcon5" />
</LinearLayout>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="5dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/AppIcon6" />
</LinearLayout>
</LinearLayout>

Sending Notify Code :

private void SendNotifyShortcuts(){


        UpdatePreferences();

        nBuilder = new NotificationCompat.Builder(this)
                .setAutoCancel(true)
                .setOngoing(true);
        remoteView = new RemoteViews(getPackageName(), R.layout.notification_layout);

        if (App_1 == null) {
            remoteView.setImageViewResource(R.id.AppIcon1, R.drawable.app_fab);
        } else {
            Drawable icon = null;
            Bitmap AppIcon = null;
            final PackageManager pm = getApplicationContext().getPackageManager();
            try {
                ApplicationInfo ai = pm.getApplicationInfo(App_1, 0);
                icon = getPackageManager().getApplicationIcon(App_1);
                AppIcon = ((BitmapDrawable) icon).getBitmap();
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }

            remoteView.setImageViewBitmap(R.id.AppIcon1, AppIcon);
        }

        if (App_2 == null) {
            remoteView.setImageViewResource(R.id.AppIcon2, R.drawable.app_fab);
        } else {
            Drawable icon = null;
            Bitmap AppIcon = null;
            final PackageManager pm = getApplicationContext().getPackageManager();
            try {
                ApplicationInfo ai = pm.getApplicationInfo(App_2, 0);
                icon = getPackageManager().getApplicationIcon(App_2);
                AppIcon = ((BitmapDrawable) icon).getBitmap();
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }

            remoteView.setImageViewBitmap(R.id.AppIcon2, AppIcon);
        }

        if (App_3 == null) {
            remoteView.setImageViewResource(R.id.AppIcon3, R.drawable.app_fab);
        } else {
            Drawable icon = null;
            Bitmap AppIcon = null;
            final PackageManager pm = getApplicationContext().getPackageManager();
            try {
                ApplicationInfo ai = pm.getApplicationInfo(App_3, 0);
                icon = getPackageManager().getApplicationIcon(App_3);
                AppIcon = ((BitmapDrawable) icon).getBitmap();
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }

            remoteView.setImageViewBitmap(R.id.AppIcon3, AppIcon);
        }

        if (App_4 == null) {
            remoteView.setImageViewResource(R.id.AppIcon4, R.drawable.app_fab);
        } else {
            Drawable icon = null;
            Bitmap AppIcon = null;
            final PackageManager pm = getApplicationContext().getPackageManager();
            try {
                ApplicationInfo ai = pm.getApplicationInfo(App_4, 0);
                icon = getPackageManager().getApplicationIcon(App_4);
                AppIcon = ((BitmapDrawable) icon).getBitmap();
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }

            remoteView.setImageViewBitmap(R.id.AppIcon4, AppIcon);
        }

        if (App_5 == null) {
            remoteView.setImageViewResource(R.id.AppIcon5, R.drawable.app_fab);
        } else {
            Drawable icon = null;
            Bitmap AppIcon = null;
            final PackageManager pm = getApplicationContext().getPackageManager();
            try {
                ApplicationInfo ai = pm.getApplicationInfo(App_5, 0);
                icon = getPackageManager().getApplicationIcon(App_5);
                AppIcon = ((BitmapDrawable) icon).getBitmap();
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }

            remoteView.setImageViewBitmap(R.id.AppIcon5, AppIcon);
        }

        if (App_6 == null) {
            remoteView.setImageViewResource(R.id.AppIcon6, R.drawable.app_fab);
        } else {
            Drawable icon = null;
            Bitmap AppIcon = null;
            final PackageManager pm = getApplicationContext().getPackageManager();
            try {
                ApplicationInfo ai = pm.getApplicationInfo(App_6, 0);
                icon = getPackageManager().getApplicationIcon(App_6);
                AppIcon = ((BitmapDrawable) icon).getBitmap();
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }

            remoteView.setImageViewBitmap(R.id.AppIcon6, AppIcon);
        }


        setListeners(remoteView, this);

        nBuilder.setContent(remoteView);

        nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nManager.notify(NOFIY_ID, nBuilder.build());

}

public static void CancelNotify(){
    try {
        nManager.cancel(NOFIY_ID);
    } catch (Exception e){
        e.printStackTrace();
    }
}

public static void setListeners(RemoteViews view, Context context){

    Intent App1 = new Intent("App1");
    PendingIntent App1P = PendingIntent.getBroadcast(context, 0, App1, 0);
    view.setOnClickPendingIntent(R.id.AppIcon1, App1P);

    Intent App2 = new Intent("App2");
    PendingIntent App2P = PendingIntent.getBroadcast(context, 1, App2, 0);
    view.setOnClickPendingIntent(R.id.AppIcon2, App2P);

    Intent App3 = new Intent("App3");
    PendingIntent App3P = PendingIntent.getBroadcast(context, 3, App3, 0);
    view.setOnClickPendingIntent(R.id.AppIcon2, App3P);

    Intent App4 = new Intent("App4");
    PendingIntent App4P = PendingIntent.getBroadcast(context, 4, App4, 0);
    view.setOnClickPendingIntent(R.id.AppIcon2, App4P);

    Intent App5 = new Intent("App5");
    PendingIntent App5P = PendingIntent.getBroadcast(context, 5, App5, 0);
    view.setOnClickPendingIntent(R.id.AppIcon2, App5P);

    Intent App6 = new Intent("App6");
    PendingIntent App6P = PendingIntent.getBroadcast(context, 6, App6, 0);
    view.setOnClickPendingIntent(R.id.AppIcon2, App6P);

}

What's the fix ? And i've seen in the questions that i can make a ListView in a notification, What's the way ? as there is no official doc or guide to do it .

Community
  • 1
  • 1
Jaeger
  • 1,646
  • 8
  • 27
  • 59

0 Answers0