在一个系统中的应用程序使用sendBroadcast [英] using sendBroadcast in a system app

查看:2096
本文介绍了在一个系统中的应用程序使用sendBroadcast的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法发送广播从一个应用程序是在一个定制ROM作为系统的应用程序被加载(使用安卓sharedUserId =android.uid.system清单)。

I'm having trouble sending a Broadcast from an app which is be loaded in a custom rom as a system app (Using android:sharedUserId="android.uid.system" in the Manifest).

我收到的问题是试图执行一个简单的sendBroadcast时:

The problem I'm getting is when trying to perform a simple sendBroadcast:

Intent newIntent = new Intent(intent.getExtras().getString(BUNDLE_ACTION_TO_REPLY_ON));
newIntent.putExtra(BUNDLE_FILE_URI, bitmapFile.getAbsolutePath());
newIntent.putExtra(BUNDLE_REPLY_WIDTH, width);
newIntent.putExtra(BUNDLE_REPLY_HEIGHT, height);
newIntent.putExtra(BUNDLE_REPLY_EXTRA, extra);
context.sendBroadcast(newIntent);

我收到这样的警告在logcat中:

I'm getting this warning in Logcat:

调用系统中的进程的方法没有限定的用户

这是被抽通过<一个href="http://mirror.yongbok.net/linux/android/repository/frameworks/base/core/java/android/app/ContextImpl.java"><$c$c>ContextImpl.java warnIfCallingFromSystemProcess()的过程。

有谁知道为什么(如果我需要解决的话)?

Does anybody know why (and if I need to "fix" it)?

推荐答案

使用下面的函数,而不是sendBroadcast(意向意图)。

Use below function instead of sendBroadcast(Intent intent).

无效sendBroadcastAsUser(意向意图,UserHandle用户)

void sendBroadcastAsUser(Intent intent, UserHandle user)

例如,

context.sendBroadcastAsUser(newIntent,新UserHandle(UserHandle.USER_CURRENT));

context.sendBroadcastAsUser(newIntent, new UserHandle(UserHandle.USER_CURRENT));

这篇关于在一个系统中的应用程序使用sendBroadcast的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆