我正在使用谷歌推送通知,到目前为止它工作得很好,目前推送通知不起作用,因为 onRegistered 从未启动。我认为问题出在清单中(因为问题是接收者从未被调用),但我不确定
这是我的清单
    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.name.name"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.WAKE_LOCK" />
     <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>     
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.SEND_SMS" />
     <uses-permission android:name="android.permission.WRITE_SMS"/>
     <uses-permission android:name="android.permission.RECEIVE_SMS" />
     <uses-permission android:name="android.permission.READ_SMS" />
     <uses-permission android:name="android.permission.RESTART_PACKAGES"/>
     <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
     <uses-permission android:name="com.name.name.permission.C2D_MESSAGE" android:protectionLevel="normal" />  
    <application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.name.name.Disclaimer"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" /> …android push-notification google-cloud-messaging android-broadcast
我的应用程序运行的服务在设备重新启动或重新安装(更新)应用程序时终止.我添加了两个广播接收器来捕获这些事件 - BOOT_COMPLETED和ACTION_MY_PACKAGE_REPLACED.
ACTION_MY_PACKAGE_REPLACED接收器似乎不起作用.这就是我所拥有的:
AndroidManifest.xml中:
    <receiver android:name=".RebootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver>
    <receiver android:name=".ReInstallReceiver">
        <intent-filter>
            <action android:name="android.intent.action.ACTION_MY_PACKAGE_REPLACED"/>
        </intent-filter>
    </receiver>
RebootReceiver:
public class RebootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Logg.d("Reboot completed. Restarting service");
        context.startService(new Intent(context, MyService.class));
    }
}
ReInstallReceiver:
public class ReInstallReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Logg.d("App Upgraded or Reinstalled. Restarting service");
        context.startService(new Intent(context, MyService.class));
    }
}
运行minSdk = 16; 在运行KitKat的Galaxy S3上进行测试.通过检查我的服务是否在"设置/应用程序"中运行来测试成功,它在重新启动时执行,但不重新安装.
我已经考虑了以下注释,其中说在Android Studio 1.0+中,清单合并意味着我无法将两个接收器合并为一个类.请参阅ACTION_MY_PACKAGE_REPLACED未收到,并且对于具有相同名称但内容不同的接收者,Android清单合并失败
我的手机正在连接蓝牙设备,工作正常.它连接并且连接成立.我可以更改方向,在后台安装我的应用程序,我可以关闭应用程序,当我将其重新打开时,它将自动连接.但是从应用程序用户那里我得到一些报告说连接在一段时间后丢失(没有检测到模式).我试图重新创建这个,但没有运气.因此,为了避免此问题,我想在连接丢失时实现自动重新连接到之前选择的设备.
我做了一些研究,可以通过实现一个可以检测到的广播接收器来完成: android.bluetooth.device.action.ACL_DISCONNECTED
我的问题是:
感谢您的回答.
蓝牙服务代码:
public class BluetoothService
{
    // Debugging
    private static final String TAG = "BluetoothService";    
    private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
// Member fields
private final BluetoothAdapter mAdapter;
private final Handler mHandler;
private final Context mContext;
private ConnectThread mConnectThread;
private ConnectedThread mConnectedThread;    
private int mState;
// Constants that indicate the current connection state
public static final int STATE_NONE = 0;       // we're doing nothing
public static final int STATE_CONNECTING = 1; // now …为什么OrderedBroadcast在应用程序的调试版本中工作但在发布版本中不工作?我发送以下OrderedBroadcast:
context.sendOrderedBroadcast(sendInt, "xxx.xxxx.permission.API", new BroadcastReceiver() {
        @SuppressLint("NewApi")
        @Override
        public void onReceive(Context receivercontext, Intent intent) {
               Bundle results = getResultExtras(true);
               if (results.getInt("Result", Activity.RESULT_CANCELED) == Activity.RESULT_OK) {
                   Log.d("DEBUG", "OK");
               } else {
                   Log.e("DEBUG", "Failed");
               }
         }
}, null, Activity.RESULT_OK, null, null);
两个应用程序在AndroidManifest.xml文件中都具有相应的权限,接收器声明如下:
<receiver android:name="xxx.xxxx.xxxx.Receiver1"
            android:enabled="true"
            android:exported="true"
            android:permission="xxx.xxxx.permission.API">
            <intent-filter>
                <action android:name="xxx.xxxx.permission.API.1" />
            </intent-filter>
</receiver>
正如我所提到的,如果发送器和接收器应用程序都在调试版本中运行,那么一切都运行正常但是如果我在发布模式下运行接收器应用程序(没有proguard或任何东西),发送者应用程序只是获得RESULT_CANCELLED结果?
这已经困扰了我好几天,所以任何想法都会非常感激.
android broadcastreceiver android-intent android-broadcast android-studio
我正在使用 Android Room 来存储我的应用程序数据。设备重新启动后,我需要检索它们并执行一些功能。我正在使用 LiveData 从数据库获取数据。但我无法将广播接收器绑定为所有者。我应该如何解决这个问题?
public class BootReciever extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
    if (context != null) {
            ProductUIRepository mRepository = new ProductUIRepository(context.getApplicationContext());
            mRepository.findAllProducts().observe(this, new android.arch.lifecycle.Observer<List<ProductUI>>() {
                @Override
                public void onChanged(@Nullable List<ProductUI> productUIS) {
                    NotificationMan.setAlarmForProducts(context, productUIS);
                }
            });
    }
  }
}
使用“this”会使应用程序无法编译。
我的应用程序不使用广播 - 既不使用Context也不使用LocalBroadcastManager. 由于我在应用程序源代码中使用了一些外部库,因此其中一个可能在其中使用广播。
我可以android.app.RemoteServiceException: can't deliver broadcast在 Crashlytics 和 Google Play 控制台中看到很多异常的发生,但我不知道是什么导致了它们。
完整的日志可以在下面找到:
Fatal Exception: android.app.RemoteServiceException: can't deliver broadcast
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6123)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
我已经看到了一些与此错误相关的其他 StackOverflow 问题,例如 this one,但所有这些问题都通过sendBroadcast()逻辑更改解决了。由于我的应用程序不发送广播,这对我没有帮助。
有人知道导致问题的原因是什么吗?谢谢!
我有很多类的实例MyClass,它们全部都从另一个类的一些生成的事件作出反应MyEventClass.我该怎么做?  
我的第一个想法是定义一个监听器MyEventClass并在其中实现它MyClass,但这需要每个实例MyClass设置监听器,并且除了将监听器定义为数组之外MyEventClass.
很多代码/工作.
我认为另一种选择是使用广播MyEventClass和接收器MyClass,但我不确定,可能是过度使用,接收器也要注册(并且未注册onStop())
第三种选择是为类定义监听器实现MyClass,而不是为每个实例定义,这将完全适合,但我不知道它是否可行,我该如何编写它.
然而,我刚刚提出的第四个选项是在父类上实现监听器,MyClass并且只设置此监听器MyEventClass,然后在事件发生循环中通过所有MyClass实例并手动调用其监听器.这节省了我注册每个实例MyEventClass.
我可以借助广播事件(ACTION_TIME_CHANGED和ACTION_DATE_CHANGED)获得时间更改事件。
我需要时间改变后再去上一次。例如,当前时间是10:00。我要将时间更改为12:00。更改时间后,时间将更改为12:00,但是我需要获取更改时间的前一时间(10:00)。
注意:可以从任何其他应用程序或设置中更改时间。
我的服务中有一个广播接收器,当我从我的活动发送广播以停止服务时,我收到以下错误:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.content.BroadcastReceiver.onReceive(android.content.Context, android.content.Intent)' on a null object reference
这是我的服务类:
public class PhraseService extends Service{
public static List<Phrase> phrases;
private Context context;
private static final String PHRASE_SERVICE_BROADCAST_ID = "com.cryogenos.safephrase.PHRASE_SERVICE_BROADCAST_ID";
private BroadcastReceiver command_broadcast_receiver;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    this.context = getApplicationContext();
    LocalBroadcastManager.getInstance(this).registerReceiver(command_broadcast_receiver, new IntentFilter(PHRASE_SERVICE_BROADCAST_ID));
    Log.i("COS", "STARTED SELF");
    /* Handle any command sent by the app here */
    command_broadcast_receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent …在我的应用程序中,我必须在设备连接或断开WIFI网络时收到通知.为此,我必须使用a BroadcastReceiver但在阅读了不同的文章和问题后,我有点困惑,我应该使用哪个广播操作.在我看来,我有三个选择:
为了减少资源,我真的只想在设备CONNECTED进入WIFI网络(并且它已经收到IP地址)或设备有DISCONNECTED来自一个时收到通知.我不关心其他州等CONNECTING.
那么您认为我应该使用的最佳广播动作是什么?而且我必须manully过滤事件(因为我receieve更多然后CONNECTED和DISCONNECTED)的onReceive?
编辑:正如我在下面的评论中所指出的,我认为SUPPLICANT_CONNECTION_CHANGE_ACTION对我来说是最好的选择,但我的申请从未被解雇或收到.其他人对此广播也有同样的问题,但从未提出真正的解决方案(实际上使用了其他广播).有什么想法吗?