zoukankan      html  css  js  c++  java
  • sendBroadcast无法接收消息可能原因

    Beginning with Android 8.0 (API level 26), the system imposes additional restrictions on manifest-declared receivers. If your app targets API level 26 or higher, you cannot use the manifest to declare a receiver for most implicit broadcasts (broadcasts that do not target your app specifically).

    意思静态注册的广播在8.0以上是不能用,推荐用代码注册广播。
    解决方案可以这么做:

    配置:

    <receiver android:name="MyStart">

        <intent-filter>
    <action android:name="com.example.y.myapplication" />
    </intent-filter>
    </receiver>
    代码:
    Intent intent = new Intent();
                    intent.setComponent(new ComponentName("com.example.y.myapplication","com.example.y.myapplication.MyStart"));
                    getApplicationContext().sendBroadcast(intent);

  • 相关阅读:
    sscanf功能详解(转)
    String to Integer (atoi)
    Reverse Words in a String
    在一个字符串中寻找某个字串
    回文数
    Two Sum
    java 判断牌型?
    股票的最大利润
    队列的最大值
    加密和解密例子
  • 原文地址:https://www.cnblogs.com/ylwn817/p/10163290.html
Copyright © 2011-2022 走看看