Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.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_Bitmap - Fatal编程技术网

Android 从包解析位图

Android 从包解析位图,android,bitmap,Android,Bitmap,我正在尝试解析谷歌地图通知。我设法分析了所有的行。 问题是,我需要解析谷歌地图通过它定义的图像,以确定下一步行动的方向。我使用下面的代码执行了选项“java.lang.RuntimeException:无法解析位图” if (sbn.getPackageName().equals("com.google.android.apps.maps")){ Notification not = sbn.getNotification(); RemoteViews

我正在尝试解析谷歌地图通知。我设法分析了所有的行。 问题是,我需要解析谷歌地图通过它定义的图像,以确定下一步行动的方向。我使用下面的代码执行了选项“java.lang.RuntimeException:无法解析位图”

   if (sbn.getPackageName().equals("com.google.android.apps.maps")){
         Notification not = sbn.getNotification();
         RemoteViews views = (RemoteViews) not.bigContentView;
         List<String> text = new ArrayList<String>();
            try
               {
                Field field = views.getClass().getDeclaredField("mActions");
                 field.setAccessible(true);

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

                 // Find the setText() and setTime() reflection actions
                   for (Parcelable p : actions)
                       {
                       Parcel parcel = Parcel.obtain();
                       p.writeToParcel(parcel, 0);
                       parcel.setDataPosition(0);

                // The tag tells which type of action it is (2 is ReflectionAction, from the source)
                 int tag = parcel.readInt();
                  if ( ( tag != 2 ) && ( tag != 12 )) {
                         continue;
                      }

                   // View ID
                   parcel.readInt();
                    String methodName = parcel.readString();
                    if (methodName == null){
                          continue;
                        }else if (methodName.equals("setImageBitmap")){
                        parcel.setDataPosition(0);
                        Bitmap bm = Bitmap.CREATOR.createFromParcel(parcel);
                              sendBroadcast(i2);
                       }
                       // Save strings
              else if (methodName.equals("setText"))
              {
                 // Parameter type (10 = Character Sequence)
                   parcel.readInt();

                   // Store the actual string
                String t = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel).toString().trim();
               text.add(t);
                }
        // Save times. Comment this section out if the notification time isn't important
          else if (methodName.equals("setTime"))
               {
                   // Parameter type (5 = Long)
                   parcel.readInt();

                  String t = new SimpleDateFormat("h:mm a").format(new Date(parcel.readLong()));
                   text.add(t);
               }
                  parcel.recycle();

            }
      }

  // It's not usually good style to do this, but then again, neither is the use of reflection...
  catch (Exception e)
   {
     Log.e("NotificationClassifier", e.toString());
   }
 }
if(sbn.getPackageName().equals(“com.google.android.apps.maps”)){
Notification not=sbn.getNotification();
RemoteView视图=(RemoteView)not.bigContentView;
列表文本=新的ArrayList();
尝试
{
Field=views.getClass().getDeclaredField(“mActions”);
字段。setAccessible(true);
@抑制警告(“未选中”)
ArrayList操作=(ArrayList)字段.get(视图);
//查找setText()和setTime()反射操作
用于(可包裹p:操作)
{
地块=地块。获取();
p、 书面包裹(包裹,0);
包裹。setDataPosition(0);
//标记告诉它是哪种类型的操作(2是ReflectionAction,来自源)
int tag=parcel.readInt();
如果((标记!=2)和(&(标记!=12)){
继续;
}
//视图ID
parcel.readInt();
String methodName=parcel.readString();
if(methodName==null){
继续;
}else if(methodName.equals(“setImageBitmap”)){
包裹。setDataPosition(0);
位图bm=Bitmap.CREATOR.createFromParcel(地块);
发送广播(i2);
}
//保存字符串
else if(methodName.equals(“setText”))
{
//参数类型(10=字符序列)
parcel.readInt();
//存储实际字符串
字符串t=TextUtils.CHAR\u SEQUENCE\u CREATOR.createFromParcel(parcel.toString().trim();
增加(t);
}
//节省时间。如果通知时间不重要,请将此部分注释掉
else if(methodName.equals(“setTime”))
{
//参数类型(5=长)
parcel.readInt();
字符串t=新的SimpleDataFormat(“h:mm a”).format(新日期(packet.readLong());
增加(t);
}
包裹回收();
}
}
//这样做通常不是一种好的风格,但再一次,反射的使用也是如此。。。
捕获(例外e)
{
e(“NotificationClassifier”,e.toString());
}
}

编辑:我现在不在乎内存,而且我正在阅读谷歌地图图像,不会将图像从一个活动发送到另一个活动。

尝试从drawable Over parcel传递字节[]

但是:


  • @vamp你看,在包或包裹中传递大量字节并不是真正推荐的。这不仅会减慢应用程序的速度,还会导致内存问题*

所以,正如我所说,你不应该将
位图
放入
包裹或
捆绑包中,这将导致你的应用程序速度显著减慢,并可能导致内存问题

你该怎么办 如果您真的需要将图像从一个地方传递到另一个地方,请保存它。只需创建临时文件并将路径传递到此临时文件即可

如何从通知中获取位图? 你能吗


想了想,我打赌你就是做不到。但是,你能做的就是截屏。尝试找到ImageView的位置并捕获屏幕部分。那你想干什么就干什么

我想你在做与我相同或相似的事情。无论如何,我也在为同样的任务而挣扎。如果你不反对使用库,这对我来说非常有效。我在普通的ContentView上运行了它,尽管它也可以在BigContentView上运行

如果需要的话,只需稍微修改一下就可以了

RemoteViews remoteViews = sbn.getNotification().contentView;
RemoteViewsInfo info = RemoteViewsReader.read(this, sbn.getNotification().contentView);
RemoteViewsInfo info = RemoteViewsReader.read(this, remoteViews);
for (RemoteViewsAction action : info.getActions()) {
  if (!(action instanceof BitmapReflectionAction))
    continue;
  BitmapReflectionAction concrete = (BitmapReflectionAction)action;
  Bitmap bmp = concrete.getBitmap();
}


希望这有助于

系统
位图
不实现
包裹
,因此您无法对其进行解析。不要扩展位图来实现它,请不要扩展。你会遇到巨大的内存问题。所以,如果我想从谷歌地图通知中获得方向,你有什么建议?永远不要在真正的应用程序中这样做。请。@eCalips我这样做是出于个人目的,但为什么呢?@vamp你看,在
包中传递大量字节
,实际上并不推荐这样做。这不仅会减慢你的应用程序速度,还会导致内存问题。我不会传递包裹。我必须使用包裹,因为这是阅读谷歌地图通知的方式,这实际上是我的问题。怎么做?