Android 在系统应用程序中使用sendBroadcast
我无法从作为系统应用程序加载到自定义rom中的应用程序(使用Android 在系统应用程序中使用sendBroadcast,android,Android,我无法从作为系统应用程序加载到自定义rom中的应用程序(使用清单中的android:sharedUserId=“android.uid.system”)发送广播 我遇到的问题是在尝试执行简单的sendBroadcast时: Intent newIntent = new Intent(intent.getExtras().getString(BUNDLE_ACTION_TO_REPLY_ON)); newIntent.putExtra(BUNDLE_FILE_URI, bitmapFile.get
清单中的android:sharedUserId=“android.uid.system”
)发送广播
我遇到的问题是在尝试执行简单的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中收到以下警告:
在没有合格用户的情况下调用系统进程中的方法
在warnIfCallingFromSystemProcess()
过程中,这是由泵输出的
有人知道原因吗(如果我需要“修复”它)?使用下面的函数而不是sendBroadcast(Intent-Intent)
例如:
context.sendBroadcastAsUser(newIntent, new UserHandle(UserHandle.USER_CURRENT));
能否显示初始化上下文的位置?它作为广播接收器的一部分传入(public void onReceive(final context context,final Intent Intent)
)此BroadcastReceiver是您的系统应用程序?应用程序中有一个BroadcastReceiver是:)不幸的是,该项目已降低了我的优先级,因此我没有机会尝试@sMiLo的答案,这看起来是一个不错的选择。这不能由未预装的应用程序使用,请阅读此处:@Mat:Yes。它仅用于系统应用程序。什么是UserHandle.USER\u CURRENT
参数?Process.myUserHandle()
而不是new UserHandle(UserHandle.USER\u CURRENT)
为我做了这项工作您不需要新的UserHandle对象,只需使用UserHandle.CURRENT
。
context.sendBroadcastAsUser(newIntent, new UserHandle(UserHandle.USER_CURRENT));