0

在 Api 级别高于 24 的异常是

W/System: ClassLoader referenced unknown path: /data/app/com.example.admin.emoji_test-2/lib/x86    

在 Aapi 级别低于 24 的异常是

08-20 11:45:32.481 1951-1951/com.android.systemui E/StatusBar: couldn't inflate view for notification com.mechmocha.unityproject/0xf
android.view.InflateException: Binary XML file line #24: Error inflating class io.github.rockerhieu.emojicon.EmojiconTextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.widget.RemoteViews.apply(RemoteViews.java:2462)
at com.android.systemui.statusbar.BaseStatusBar.inflateViews(BaseStatusBar.java:662)
at com.android.systemui.statusbar.BaseStatusBar.createNotificationViews(BaseStatusBar.java:835)
at com.android.systemui.statusbar.phone.PhoneStatusBar.addNotification(PhoneStatusBar.java:1084)
at com.android.systemui.statusbar.CommandQueue$H.handleMessage(CommandQueue.java:267)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5021)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "io.github.rockerhieu.emojicon.EmojiconTextView" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib, /system/lib/arm, /data/downloads]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:559)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.widget.RemoteViews.apply(RemoteViews.java:2462) 
at com.android.systemui.statusbar.BaseStatusBar.inflateViews(BaseStatusBar.java:662) 
at com.android.systemui.statusbar.BaseStatusBar.createNotificationViews(BaseStatusBar.java:835) 
at com.android.systemui.statusbar.phone.PhoneStatusBar.addNotification(PhoneStatusBar.java:1084) 
at com.android.systemui.statusbar.CommandQueue$H.handleMessage(CommandQueue.java:267) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5021) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643) 
at dalvik.system.NativeStart.main(Native Method) 
08-20 11:45:32.481 1951-1951/com.android.systemui W/StatusBar: removeNotification for unknown key: android.os.BinderProxy@4f384f64

这是使用 io.github.rockerhieu.emojicon.EmojiconTextView 的自定义 R.layout.custom_notification xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <io.github.rockerhieu.emojicon.EmojiconTextView
        android:id="@+id/notification_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="I \u263A emojicon"
        />
</LinearLayout>

通知生成器java代码我使用remoteview将它传递给使用.setCustomContentView(remoteCollapsedView)的通知

RemoteViews remoteCollapsedView = new RemoteViews(this.getPackageName(), R.layout.custom_notification); remoteCollapsedView.setTextViewText(R.id.notification_text_view,"hi "+"\u263A "); 
Bundle bundle = new Bundle(); 
bundle.putString("jay","jay");
if(Build.VERSION.SDK_INT >= 24) { 
Notification n = new Notification.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com") 
.setContentText("Subject") 
.setSmallIcon(R.drawable.thumb) 
.setExtras(bundle)
.setCategory("true") 
.setAutoCancel(true) 
.setGroup("hey")
.setCustomContentView(remoteCollapsedView)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, n);
}

我已将库添加到 gradle

compile 'io.github.rockerhieu:emojicon:+'

当收到通知时,应用程序会因上述异常而崩溃,如果这是不可能的,或者我遗漏了什么,我会感到困惑

4

1 回答 1

-1

我使用了这个库,您需要先将其初始化到您的使用活动中。参考下面的代码。

import io.github.rockerhieu.emojiconize.Emojiconize;

public class MyActivity extends AppCompatActivity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
        //call it before super method call.. 
        Emojiconize.activity(this).go();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

希望这有帮助..看看这里了解更多信息..

于 2017-08-21T14:15:42.583 回答