Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在棒棒糖版本中提取状态栏中的通知文本?_Android_Notifications_Android 5.0 Lollipop - Fatal编程技术网

Android 如何在棒棒糖版本中提取状态栏中的通知文本?

Android 如何在棒棒糖版本中提取状态栏中的通知文本?,android,notifications,android-5.0-lollipop,Android,Notifications,Android 5.0 Lollipop,亲爱的所有人,我正在使用下面附加的代码来提取通知文本。但它在棒棒糖版本的android(V5)中不起作用。你能帮我解决这个问题吗 import java.lang.reflect.Field; import java.util.ArrayList; import android.annotation.SuppressLint; import android.app.Notification; import android.os.Build; import android.os.Parcel;

亲爱的所有人,我正在使用下面附加的代码来提取通知文本。但它在棒棒糖版本的android(V5)中不起作用。你能帮我解决这个问题吗

import java.lang.reflect.Field;
import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
import android.widget.RemoteViews;
import de.ecspride.reactor.poc.model.Message;
import de.ecspride.reactor.poc.model.MessageParser;

@SuppressLint("NewApi")
public class DefaultBigView implements MessageParser {
    private static final String TAG = DefaultBigView.class.getName();

    private static final int ID_FIRST_LINE = 16909023; // bigContentView

    @Override
    public Message parse(Notification notification) {
        // use simple method if bigContentView is not supported
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
            return new DefaultView().parse(notification);

        Message result = new Message();

        try {
            RemoteViews views = notification.bigContentView;

            Class<?> rvClass = views.getClass();

            Field field = rvClass.getDeclaredField("mActions");
            field.setAccessible(true);

            @SuppressWarnings("unchecked")
            ArrayList<Parcelable> actions = (ArrayList<Parcelable>) field
                    .get(views);

            for (Parcelable action : actions) {
                try {
                    // create parcel from action
                    Parcel parcel = Parcel.obtain();
                    action.writeToParcel(parcel, 0);
                    parcel.setDataPosition(0);

                    // check if is 2 / ReflectionAction
                    int tag = parcel.readInt();
                    if (tag != 2)
                        continue;

                    int viewId = parcel.readInt();

                    String methodName = parcel.readString();
                    if (methodName == null || !methodName.equals("setText")) {
                        Log.w(TAG, "#Big Not setText: " + methodName);
                        continue;
                    }

                    // should be 10 / Character Sequence, here
                    parcel.readInt();

                    // Store the actual string
                    String value = TextUtils.CHAR_SEQUENCE_CREATOR
                            .createFromParcel(parcel).toString();

                    Log.d(TAG, "Big viewId is " + viewId);
                    Log.d(TAG, "Big Found value: " + value);

                //  if (viewId == ID_FIRST_LINE) {
                        int indexDelimiter = value.indexOf(':');

                        if (indexDelimiter != -1) {
                            result.sender = value.substring(0, indexDelimiter);
                            result.message = value
                                    .substring(indexDelimiter + 2);
                        }
                //  }

                    parcel.recycle();
                } catch (Exception e) {
                    Log.e(TAG, "Big Error accessing object!", e);
                }
            }

            if (result.sender == null || result.message == null)
                return null;

            return result;
        } catch (Exception e) {
            Log.e(TAG, "Big Could not access mActions!", e);

            return null;
        }
    }
}
import java.lang.reflect.Field;
导入java.util.ArrayList;
导入android.annotation.SuppressLint;
导入android.app.Notification;
导入android.os.Build;
导入android.os.packet;
导入android.os.Parcelable;
导入android.text.TextUtils;
导入android.util.Log;
导入android.widget.remoteview;
导入de.ecspride.reactor.poc.model.Message;
导入de.ecspride.reactor.poc.model.MessageParser;
@SuppressLint(“新API”)
公共类DefaultBigView实现MessageParser{
私有静态最终字符串标记=DefaultBigView.class.getName();
私有静态final int ID_FIRST_LINE=16909023;//bigContentView
@凌驾
公共消息解析(通知){
//如果不支持bigContentView,请使用simple方法
if(Build.VERSION.SDK\u INT
它给了我一个错误,即没有声明的变量


感谢

Android 5棒棒糖通知不再直接使用该类,它们现在正在使用它扩展RemoteView类

您应该像这样尝试访问父类mActions字段

Field field = rvClass.getSuperclass().getDeclaredField("mActions");

请张贴日志。