收到Kitkat后收件箱中不存在短信(SMS message is not present in inbox after receiving in Kitkat)
我正在创建一个小的短信应用程序,并在收到它与我的广播接收器后,它应该存在于收件箱中,它应该可以访问其他短信应用程序,但事实并非如此。 看起来根本没有收到任何消息。 仅当我的应用程序是默认SMS应用程序时才会出现此问题 收到后,是否需要手动将收到的短信添加到收件箱?
I'm creating little sms app, and after receiving it with my Broadcast receiver it is supposed to be present in inbox and it should be accessible to other sms apps as well, but it is not. It looks like no message was received at all. This issue occurs only when my app is default SMS app. Do I need to manually add received SMS to inbox after receiving it?
原文:https://stackoverflow.com/questions/25227440
更新时间:2023-03-20 08:03
最满意答案
我的解决方案是:
class CustomSerializer < ActiveModel::Serializer def initialize(resources, options = {}) resources = sort(resources) super(resources, options) end def sort(resources) top = [] regular = [] resources.each do |article| if article.poster top << article else regular << article end end resources = top + regular end end
My solution is:
class CustomSerializer < ActiveModel::Serializer def initialize(resources, options = {}) resources = sort(resources) super(resources, options) end def sort(resources) top = [] regular = [] resources.each do |article| if article.poster top << article else regular << article end end resources = top + regular end end
相关问答
更多-
您的序列化程序应该被称为ImageSerializer (注意缺少s ),因为您的模型名为Image 。 并确保该文件放在app/serializers/image_serializer.rb 。 Your serializer should be called ImageSerializer (note absence of s), because your model is named Image. And make sure the file is put under app/serializers/ ...
-
排序Rails序列化数据(Sort Rails Serializer Data)[2023-12-30]
在序列化之前确保数据已排序。 因此,您可以在模型中执行根据需要对其进行排序的范围。 然后,在您的控制器中,您只需使用该范围,它应该在收到数据时对其进行序列化。 如果您不熟悉, 这里有一些关于范围的文档。 Make sure the data is sorted before serializing it. So, you could do in the model a scope that sorts it as you wish. Then, in your controller, you'd just ... -
我的解决方案是: class CustomSerializer < ActiveModel::Serializer def initialize(resources, options = {}) resources = sort(resources) super(resources, options) end def sort(resources) top = [] regular = [] resources.each do |article| ...
-
传递的选项可通过@options哈希值获得。 所以如果你这样做: respond_with @event, activity_count: 5 您可以在序列化程序中使用@options[:activity_count] 。 Options passed in are available through the @options hash. So if you do: respond_with @event, activity_count: 5 You can use @options[:activity ...
-
在属性列表中,您还应指定test_id attributes :id, :test_id in the attributes list, you should specify test_id as well attributes :id, :test_id
-
ActiveModel Serializer中的自定义字段与另一个序列化程序(Custom field in ActiveModel Serializer with another serializer)[2023-08-03]
您的代码很好,只需使用UserSessionSerializer.new而不是serializer: UserSessionSerializer render json: { user: UserSerializer.new(@user, session: @session) } attributes :id, :email, :username, :session def session UserSessionSerializer.new(self.instance_options[:sessio ... -
ActiveModel Serializer - 将params传递给序列化程序(ActiveModel Serializer - Passing params to serializers)[2021-09-14]
AMS版本:0.10.6 传递给render任何未为adapter保留的选项在序列化程序中可用作instance_options 。 在你的控制器中: def index @watchlists = Watchlist.belongs_to_user(current_user) render json: @watchlists, each_serializer: WatchlistOnlySerializer, currency: params[:currency] end 然后您可以在序列化程序 ... -
您可以在渲染之前直接序列化它们: json_response = service.errors.merge(attribute1: value1) render json: json_response.merge( collection1: ActiveModelSerializers::SerializableResource.new(@collection).as_json, collection2: ActiveModelSerializers::SerializableResource.n ...
-
如何调用active_model_serializer来显式序列化记录(How to call an active_model_serializer to serialize records explicitly)[2022-06-12]
要调用并能够重用序列化程序: options = {} serialization = SerializableResource.new(resource, options) serialization.to_json serialization.as_json 所以我用它是这样的: def self.get_entries_for_user(current_user) current_user.time_entries .group_by { |item| item.created_at ... -
如何为多对多关系编写activemodel序列化器?(How to write activemodel serializer for many to many relationship?)[2021-10-05]
您得到的“堆栈级别太深”错误,因为每个序列化程序递归嵌入另一个。 我首先确保你在Rails控制器中使用includes : # posts controller def show post = Post.includes(:tags).find_by id: params[:id] render json: post end # tags controller def show tag = Tag.includes(:posts).find_by id: params[:id] rende ...