Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using sendBroadcast in a system app

Tags:

android

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).

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);

I'm getting this warning in Logcat:

Calling a method in the system process without a qualified user

This is being pumped out by ContextImpl.java in the warnIfCallingFromSystemProcess() process.

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

like image 863
Graeme Avatar asked Apr 15 '13 11:04

Graeme


People also ask

How do you send a broadcast from one app to another?

Android provides three ways for apps to send broadcast: The sendOrderedBroadcast(Intent, String) method sends broadcasts to one receiver at a time. As each receiver executes in turn, it can propagate a result to the next receiver, or it can completely abort the broadcast so that it won't be passed to other receivers.

How do you manage broadcast receivers?

An application listens for specific broadcast intents by registering a broadcast receiver in AndroidManifest. xml file. Consider we are going to register MyReceiver for system generated event ACTION_BOOT_COMPLETED which is fired by the system once the Android system has completed the boot process.

Does broadcast receiver work in background?

As an Android developer, you'll often run into the scenario where you need to perform tasks and display notifications for your app in the background. To retain battery power on our users device we are going to run background tasks using a broadcast receiver.


1 Answers

Use below function instead of sendBroadcast(Intent intent).

void sendBroadcastAsUser(Intent intent, UserHandle user)

for example:

context.sendBroadcastAsUser(newIntent, new UserHandle(UserHandle.USER_CURRENT));
like image 81
sMiLo Avatar answered Oct 01 '22 10:10

sMiLo