I create own control extends from TextView. I try use this control in RemoteViews on notification. But problem, if I try show notify, get error:
java.lang.ClassNotFoundException: {namespace}.{myClass}.
But if I add same control in activity layout. All ok. What's the problem?
My TextView:
public class ScrollingTextView extends TextView {
public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ScrollingTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollingTextView(Context context) {
super(context);
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if (focused)
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
@Override
public void onWindowFocusChanged(boolean focused) {
if (focused)
super.onWindowFocusChanged(focused);
}
@Override
public boolean isFocused() {
return true;
}
}
My notify layout:
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="@+id/notification_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="@drawable/ic_launcher" />
<TextView
android:id="@+id/notification_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/notification_image"
android:text="notification_title"
android:textStyle="bold" />
<{namespace}.ScrollingTextView
android:id="@+id/notification_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/notification_title"
android:layout_toRightOf="@+id/notification_image"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="notification_message" />
Notification call:
Intent intent = new Intent(context, NotificationActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification(R.drawable.ic_launcher, tickerText, System.currentTimeMillis());
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
RemoteViews contentView = new RemoteViews(_context.getPackageName(), R.layout.notify);
contentView.setImageViewResource(R.id.notification_image, R.drawable.ic_launcher);
contentView.setTextViewText(R.id.notification_title, state.contentTitle);
contentView.setTextViewText(R.id.notification_message, state.contentText);
notification.contentView = contentView;
_notificationManager.notify(1, notification);
In android manifest I have value package="com.test".
Under {namespace} I understoo com.test, and {myClass} - ScrollingTextView. ScrollingTextView placed at package com.test.
Error occured: android.view.InflateException: Binary XML file line #25: Error inflating class com.test.ScrollingTextView.
Where line 25 is line, where declared ScollingTextView:
<com.test.ScrollingTextView ...
Full error:
couldn't inflate view for notification com.test/0x1
android.view.InflateException: Binary XML file line #25: Error inflating class com.test.ScrollingTextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.widget.RemoteViews.apply(RemoteViews.java:1580)
at com.android.systemui.statusbar.tablet.TabletStatusBar.inflateViews(TabletStatusBar.java:1938)
at com.android.systemui.statusbar.tablet.TabletStatusBar.addNotificationViews(TabletStatusBar.java:1744)
at com.android.systemui.statusbar.tablet.TabletStatusBar.addNotification(TabletStatusBar.java:891)
at com.android.systemui.statusbar.CommandQueue$H.handleMessage(CommandQueue.java:231)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.test.ScrollingTextView
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.view.LayoutInflater.createView(LayoutInflater.java:552)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
... 16 more
RemoteView only works with the handful of standard android views that are mentioned here. In particular, you cannot use your own custom views with it.
This is because the remote view is actually being run in a different process, and it does not have access to the custom view classes that you have defined.
If the other process was allowed to load and use your custom view, this would allow you to inject arbitrary code into that other process, and essentially take it over.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With