android8.0適配

1.logo適配

logo適配
懸浮框適配

https://blog.csdn.net/saberhao/article/details/53909841
java.lang.RuntimeException: Unable to create application cn.com.xiyun.canteen.base.application.BaseApplication: java.lang.SecurityException: Not allowed to change Do Not Disturb state
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5743)
at android.app.ActivityThread.-wrap1(Unknown Source:0)

 Caused by: java.lang.SecurityException: Not allowed to change Do Not Disturb state
    at android.os.Parcel.readException(Parcel.java:2013)
    at android.os.Parcel.readException(Parcel.java:1959)
    at android.media.IAudioService$Stub$Proxy.setStreamVolume(IAudioService.java:943)

廣播適配

系統(tǒng)應用廣播適配
普通應用廣播
針對8.0的普通廣播彤悔,動態(tài)注冊即可。
太空橋作為系統(tǒng)應用廣播限制就比較多了:
太空橋包含主進程吓肋、iot進程灾常,兩個進程之間通信有很多使用的是廣播,可查看源碼
ActivityManagerService 會對系統(tǒng)廣播進行安全校驗:

 private void checkBroadcastFromSystem(Intent intent, ProcessRecord callerApp,
        String callerPackage, int callingUid, boolean isProtectedBroadcast, List receivers) {
    if ((intent.getFlags() & Intent.FLAG_RECEIVER_FROM_SHELL) != 0) {
        // Don't yell about broadcasts sent via shell
        return;
    }

    final String action = intent.getAction();
    if (isProtectedBroadcast
            || Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
            || Intent.ACTION_DISMISS_KEYBOARD_SHORTCUTS.equals(action)
            || Intent.ACTION_MEDIA_BUTTON.equals(action)
            || Intent.ACTION_MEDIA_SCANNER_SCAN_FILE.equals(action)
            || Intent.ACTION_SHOW_KEYBOARD_SHORTCUTS.equals(action)
            || Intent.ACTION_MASTER_CLEAR.equals(action)
            || Intent.ACTION_FACTORY_RESET.equals(action)
            || AppWidgetManager.ACTION_APPWIDGET_CONFIGURE.equals(action)
            || AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)
            || LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION.equals(action)
            || TelephonyIntents.ACTION_REQUEST_OMADM_CONFIGURATION_UPDATE.equals(action)
            || SuggestionSpan.ACTION_SUGGESTION_PICKED.equals(action)
            || AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION.equals(action)
            || AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION.equals(action)) {
        // Broadcast is either protected, or it's a public action that
        // we've relaxed, so it's fine for system internals to send.
        return;
    }

    // This broadcast may be a problem...  but there are often system components that
    // want to send an internal broadcast to themselves, which is annoying to have to
    // explicitly list each action as a protected broadcast, so we will check for that
    // one safe case and allow it: an explicit broadcast, only being received by something
    // that has protected itself.
    if (receivers != null && receivers.size() > 0
            && (intent.getPackage() != null || intent.getComponent() != null)) {
        boolean allProtected = true;
        for (int i = receivers.size()-1; i >= 0; i--) {
            Object target = receivers.get(i);
            if (target instanceof ResolveInfo) {
                ResolveInfo ri = (ResolveInfo)target;
                if (ri.activityInfo.exported && ri.activityInfo.permission == null) {
                    allProtected = false;
                    break;
                }
            } else {
                BroadcastFilter bf = (BroadcastFilter)target;
                if (bf.requiredPermission == null) {
                    allProtected = false;
                    break;
                }
            }
        }
        if (allProtected) {
            // All safe!
            return;
        }
    }

    // The vast majority of broadcasts sent from system internals
    // should be protected to avoid security holes, so yell loudly
    // to ensure we examine these cases.
    if (callerApp != null) {
        Log.wtf(TAG, "Sending non-protected broadcast " + action
                        + " from system " + callerApp.toShortString() + " pkg " + callerPackage,
                new Throwable());
    } else {
        Log.wtf(TAG, "Sending non-protected broadcast " + action
                        + " from system uid " + UserHandle.formatUid(callingUid)
                        + " pkg " + callerPackage,
                new Throwable());
    }
}

  ####異常警告::
  system_process E/ActivityManager: Sending non-protected broadcast com.xiyun.spacebridge.iot.service.amqUpdateTopic from system 1637:com.yunzong.spacebridge/1000 pkg com.yunzong.spacebridge
java.lang.Throwable
    at com.android.server.am.ActivityManagerService.checkBroadcastFromSystem(ActivityManagerService.java:19126)
    at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:19731)
    at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:19873)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:240)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2922)
    at android.os.Binder.execTransact(Binder.java:697)

針對這種情況通過注冊一個靜態(tài)廣播的空殼,來繞過系統(tǒng)的檢測 畦娄,

MQTT動態(tài)注冊:

  IntentFilter filter = new IntentFilter(ACTION);
    registerReceiver(receiver, filter,BrocastPermissions.BROCAST_PERMISSION_MQTT,null);//需要添加權限

發(fā)送廣播:

    Intent intent = new Intent();
    intent.setPackage(context.getPackageName());
    intent.setAction(MQTTService.ACTION);
    intent.putExtra("type", Key.KEY_HEART_CHECK);
    intent.putExtra(PreferenceKeys.BIND_PACAGE_NAME, context.getPackageName());
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    context.sendBroadcast(intent, BrocastPermissions.BROCAST_PERMISSION_MQTT);//添加權限

空殼Reciver

                  /**
                 * 由于在mqttservice中動態(tài)注冊的廣播,在在發(fā)送廣播得時候回出現(xiàn)                                                                Sending non-protected broadcast
           *   這個reciver主要是作為空殼弊仪,繞過系統(tǒng)檢查
           * Created by zhangxiaoping on 2019/3/29 17:31
           */
        public class EmptyIotReciver extends BroadcastReceiver {
            @Override
            public void onReceive(Context context, Intent intent) {
              Log.e("TestIotReciver","TestIotReciver..........");
                }
        }

  <receiver
        android:name=".receiver.EmptyIotReciver"
        android:permission="com.yunzong.spacebridge.permissions.MQTT_BROCAST">
        <intent-filter>
            <action android:name="com.xiyun.spacebridge.iot.service.amqUpdateTopic" />
        </intent-filter>
    </receiver>

系統(tǒng)應用針對靜態(tài)注冊的需添加權限熙卡,方可解除警告:

        <receiver android:name=".receiver.MqServiceMsgBrocast"
        android:permission="com.yunzong.spacebridge.permissions.SPACE_BROCAST">
        <intent-filter>
            <action android:name="com.xiyun.spacebridge.iot.INFORM_AUTH" />
        </intent-filter>
    </receiver>

太空橋項目主要用兩個空殼Reciver:

    1.EmptySpaceReciver :主要用于主進程  android:permission="com.yunzong.spacebridge.permissions.SPACE_BROCAST"  
    主要用于接收iot進程發(fā)過來的廣播,可將對應的action添加到清單文件励饵。
    2.EmptyIotReciver:主要用于iot進程驳癌,android:permission="com.yunzong.spacebridge.permissions.MQTT_BROCAST"
    主要用于接收主進程發(fā)的廣播,可將對應的action添加到清單文件役听。
     <receiver
        android:name=".receiver.EmptyIotReciver"
        android:permission="com.yunzong.spacebridge.permissions.MQTT_BROCAST">
        <intent-filter>
            <action android:name="com.xiyun.spacebridge.iot.service.amqUpdateTopic" />
        </intent-filter>
    </receiver>

    <receiver
        android:name=".receiver.EmptySpaceReciver"
        android:permission="com.yunzong.spacebridge.permissions.SPACE_BROCAST">
        <intent-filter>
            <action android:name="connet_success" />
            <action android:name="connet_faile" />
            <action android:name="task_progress" />
            <action android:name="finish_sync_app" />
        </intent-filter>
    </receiver>
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末颓鲜,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子典予,更是在濱河造成了極大的恐慌甜滨,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,509評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件熙参,死亡現(xiàn)場離奇詭異艳吠,居然都是意外死亡麦备,警方通過查閱死者的電腦和手機孽椰,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評論 3 394
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來凛篙,“玉大人黍匾,你說我怎么就攤上這事∏喊穑” “怎么了锐涯?”我有些...
    開封第一講書人閱讀 163,875評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長填物。 經(jīng)常有香客問我纹腌,道長霎终,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,441評論 1 293
  • 正文 為了忘掉前任升薯,我火速辦了婚禮莱褒,結果婚禮上,老公的妹妹穿的比我還像新娘涎劈。我一直安慰自己广凸,他們只是感情好,可當我...
    茶點故事閱讀 67,488評論 6 392
  • 文/花漫 我一把揭開白布蛛枚。 她就那樣靜靜地躺著谅海,像睡著了一般。 火紅的嫁衣襯著肌膚如雪蹦浦。 梳的紋絲不亂的頭發(fā)上扭吁,一...
    開封第一講書人閱讀 51,365評論 1 302
  • 那天,我揣著相機與錄音盲镶,去河邊找鬼智末。 笑死,一個胖子當著我的面吹牛徒河,可吹牛的內(nèi)容都是我干的系馆。 我是一名探鬼主播,決...
    沈念sama閱讀 40,190評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼顽照,長吁一口氣:“原來是場噩夢啊……” “哼由蘑!你這毒婦竟也來了?” 一聲冷哼從身側響起代兵,我...
    開封第一講書人閱讀 39,062評論 0 276
  • 序言:老撾萬榮一對情侶失蹤尼酿,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后植影,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體裳擎,經(jīng)...
    沈念sama閱讀 45,500評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,706評論 3 335
  • 正文 我和宋清朗相戀三年思币,在試婚紗的時候發(fā)現(xiàn)自己被綠了鹿响。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,834評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡谷饿,死狀恐怖惶我,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情博投,我是刑警寧澤绸贡,帶...
    沈念sama閱讀 35,559評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響听怕,放射性物質(zhì)發(fā)生泄漏捧挺。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,167評論 3 328
  • 文/蒙蒙 一尿瞭、第九天 我趴在偏房一處隱蔽的房頂上張望松忍。 院中可真熱鬧,春花似錦筷厘、人聲如沸鸣峭。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽摊溶。三九已至,卻和暖如春充石,著一層夾襖步出監(jiān)牢的瞬間莫换,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評論 1 269
  • 我被黑心中介騙來泰國打工骤铃, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留拉岁,地道東北人。 一個月前我還...
    沈念sama閱讀 47,958評論 2 370
  • 正文 我出身青樓惰爬,卻偏偏與公主長得像喊暖,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子撕瞧,可洞房花燭夜當晚...
    茶點故事閱讀 44,779評論 2 354

推薦閱讀更多精彩內(nèi)容