根据Google提供给Android O的迁移指南,大多数隐式广播意图不应在Manifest中注册(减去此处的一些例外情况),但显式广播意图仍未触及.
我们希望将任何所需的广播从清单中移除.但是我们如何识别接收器是否隐含?有一般规则吗?
以下是我们在清单中注册的广播示例.我们应该只查看"action"标记,看看它是否被列入白名单以便将其保留在清单中?
<receiver
android:name=".receiver.ImageBroadcastReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="android.hardware.action.NEW_PICTURE" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="image/*" />
</intent-filter>
</receiver>
<receiver
android:name=".receiver.InstallReferrerReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<receiver android:name=".receiver.JoinEventReceiver" >
<intent-filter>
<action android:name="JOIN_ACTION" />
<action android:name="CANCEL_ACTION" />
<action android:name="DECLINE_ACTION" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
例如,"com.android.vending.INSTALL_REFERRER"意图未列入白名单.我们应该在活动中注册吗?如果是这样,它不会被解雇,因为当我们注册它时,应用程序已经安装?当我试图理解广播接收器是隐式的还是显式的时,这让我感到困惑,因为我认为我只需要检查"动作"标签.
android android-manifest android-intent android-broadcast android-8.0-oreo
TL; DR:我的应用正在占用用户的麦克风.当其他应用需要使用麦克风时,我可以自动将其关闭吗?
我有一个Android应用程序,有一些非常酷的麦克风功能,类似于亚马逊Alexa,一直在后台服务.问题是,我的应用程序占用了用户的麦克风,使其无法使用:
但是,这对我来说是一种糟糕的应用行为,我想尽力避免它.当另一个应用程序请求使用麦克风时,是否可以通知我,以便我可以自动停止我的服务?
PS:我正在使用Pocketsphinx库进行连续的背景语音识别.
据我所知,应用程序无法为自己的卸载获取意图:
但是Dolphin Browser如何设法接收"已删除"事件并启动浏览器,如附图所示?

ADB:
10-20 12:37:00.997: D/BackupManagerService(527): Received broadcast Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:mobi.mgeek.TunnyBrowser flg=0x8000010 (has extras) }
10-20 12:37:00.997: V/BackupManagerService(527): removePackageParticipantsLocked: uid=10112 #1
10-20 12:37:01.007: D/dalvikvm(527): GC_EXPLICIT freed 2247K, 12% free 20128K/22868K, paused 3ms+10ms, total 212ms
10-20 12:37:01.107: D/dalvikvm(527): GC_FOR_ALLOC freed 1508K, 15% free 19649K/22868K, paused 60ms, total 60ms
10-20 12:37:01.137: D/AndroidRuntime(4028): Calling main entry com.android.commands.am.Am
10-20 12:37:01.137: D/dalvikvm(4028): Note: class Landroid/app/ActivityManagerNative; has 163 unimplemented (abstract) methods
10-20 12:37:01.147: I/ActivityManager(527): START u0 {act=android.intent.action.VIEW dat=http://survey.dolphin.com/int/uninstall?id=014f4d1981d6f88bb56630e7a3a7550a&pn=mobi.mgeek.TunnyBrowser&v=248&s=ofw&it=1382250136565&ut=1382250127000&m=Nexus 4&os=android&osv=4.3&cc=US&no=40471&lang=en&jk=uninstalled&ft=212&ht=957&ct=0&nt=1&res=768*1184&ifi=1<s=1&iow=0&iom=0&iospd=0&iogs=0&debug=false&t=1382252820000 flg=0x10000000 …Run Code Online (Sandbox Code Playgroud) 我正试图用广播接收器捕捉蓝牙状态变化.
我的清单:
<uses-permission android:name="android.permission.BLUETOOTH" />
<application>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".BluetoothBroadcastReceiver"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
<action android:name="android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED" />
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
</intent-filter>
</receiver>
</application>
Run Code Online (Sandbox Code Playgroud)
接收onReceive方法:
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d("BroadcastActions", "Action "+action+"received");
int state;
BluetoothDevice bluetoothDevice;
switch(action)
{
case BluetoothAdapter.ACTION_STATE_CHANGED:
state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
if (state == BluetoothAdapter.STATE_OFF)
{
Toast.makeText(context, "Bluetooth is off", Toast.LENGTH_SHORT).show();
Log.d("BroadcastActions", "Bluetooth is …Run Code Online (Sandbox Code Playgroud) 我在应用程序中使用服务来监听用户按下他/她的电源按钮的次数.实施在所有设备上都运行良好.但是当我在Android Kitkat上测试应用程序时,我注意到了一些错误.
只要我将应用程序从最近的应用程序中移开,应用程序就不再会监听电源按钮.
这是我正在使用的代码:
public class Receiver extends Service {
Notification notification;
private static final int NOTIFICATION_ID = 0;
NotificationManager manager;
PendingIntent toOpen;
Intent intent;
private BroadcastReceiver POWER_BUTTON = new Powerbuttonrecceiver();
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(POWER_BUTTON, filter);
startNotify();
return START_STICKY;
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
unregisterReceiver(POWER_BUTTON);
dismissNotification();
super.onDestroy(); …Run Code Online (Sandbox Code Playgroud) 我在我的Android应用程序上使用广播消息(从io.socket我发送广播消息到我的活动页面).在某些设备上,三星SM-G950F和SM-A520F出现错误" Fatal Exception: android.app.RemoteServiceException: can't deliver broadcast".我在Fabric crashlytics上遇到此错误,但我无法重现此问题.这是我从Fabric获得的日志,
Fatal Exception: android.app.RemoteServiceException: can't deliver broadcast
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1813)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Run Code Online (Sandbox Code Playgroud) java android broadcastreceiver android-broadcast android-broadcastreceiver
是)我有的:
我有一个使用aidl在进程上运行的库.我有一个使用此库的应用程序,在消息传递活动中,我连接服务以发送消息,我有一个广播接收器来管理传入的消息.
问题?
如果这个库将由同一设备上的两个应用程序使用,则广播操作将是相同的,并且当我发送广播时我将遇到问题.
我有什么疑问?
什么是"收听"我在我的库中收到的新传入消息并将其发送到应用程序的最佳方式.也许回调?还是有更好的解决方案?
更多信息
该库提供了一些启动会话的方法,以及用于发送不同类型的消息(图像,文本,位置等等)的其他方法,并且我从另一个库中接收回调,该库使用C和C++,当一个新的消息传入.
如果您需要更多信息,请随时提出.
我的代码:
IRemote.aidl
interface IRemote
{
int sendTextMessage(String to, String message);
}
Run Code Online (Sandbox Code Playgroud)
WrapperLibrary.java
public class MyLibrary extends Service {
// Current context, used to sendbroadcast() from @Callbacks
private Context mContext = this;
private static MyLibrary instance = new MyLibrary();
//Executor to start a new thread from the service.
final ExecutorService service;
@Override
public IBinder onBind(Intent arg0) {
//Return the interface.
return mBinder;
}
/** Return the current instance */
public static WrapperLibrary …Run Code Online (Sandbox Code Playgroud) 我们所有人都知道我们注册了两种类型的BroadcastReceiver
1)Static Registration
2)Dynamic Registration
但我怀疑的是,当我们需要使用时Static以及何时需要使用Dynamic?
我为我的申请安排了警报.
我已经实现了一旦闹钟时间到达就会触发广播接收器.
如何手动调用广播接收器来执行onReceive方法内部的代码,而无需复制代码两次.
我想在实用程序单例调用中使用代码,并通过从任何地方使用util类实例来调用该方法.
但是,是否有任何其他方式直接调用onReceive方法或广告意图有问题.
android:exported ="false"//在清单文件中定义时接收者的附加参数.
另一个问题是导出的参数意味着什么.请帮我理解这个.
android broadcastreceiver android-manifest android-intent android-broadcast
我有一个BroadcastReceiver并声明它是这样的:
<receiver
android:name="com.services.Receiver"
android:enabled="true"
android:exported="true" >
<intent-filter android:priority="999" >
<action android:name="android.intent.action.WALLPAPER_CHANGED" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
接收者是:
@Override
public void onReceive(final Context context, final Intent intent)
{
change_wallpepar.myPrefs = context.getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
Log.d("MAYUR", "<< wallpepar changed >>");
if (change_wallpepar.myPrefs.getLong("temp_for_change", 1) == 0)
{
context.stopService(new Intent(context, change_wallpepar.class));
}
else
{
SharedPreferences.Editor e = change_wallpepar.myPrefs.edit();
e.putLong("temp_for_change", 0);
e.commit();
}
}
}, 4000);
}
Run Code Online (Sandbox Code Playgroud)
当我在这里更改壁纸时,它应该被调用一次.它实际上是按照我的期望工作了一段时间,在几分钟后它会调用onreceive()多次(10-18)次,即使壁纸的更改已完成一次.更奇怪的是,它在三星Galaxy平板电脑版本4.4.2上运行良好,但不适用于摩托罗拉(Moto E 4.4.4).
我的服务:
public class change_wallpepar extends Service {
@Override …Run Code Online (Sandbox Code Playgroud)