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)

廣播適配

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

 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)

針對這種情況通過注冊一個靜態廣播的空殼,來繞過系統的檢測 ,

MQTT動態注冊:

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

發送廣播:

    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中動態注冊的廣播,在在發送廣播得時候回出現                                                                Sending non-protected broadcast
           *   這個reciver主要是作為空殼,繞過系統檢查
           * 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>

系統應用針對靜態注冊的需添加權限,方可解除警告:

        <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進程發過來的廣播,可將對應的action添加到清單文件。
    2.EmptyIotReciver:主要用于iot進程,android:permission="com.yunzong.spacebridge.permissions.MQTT_BROCAST"
    主要用于接收主進程發的廣播,可將對應的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>
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,412評論 6 532
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,514評論 3 416
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
    開封第一講書人閱讀 176,373評論 0 374
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,975評論 1 312
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,743評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,199評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,262評論 3 441
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,414評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,951評論 1 336
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,780評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,983評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,527評論 5 359
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,218評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,649評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,889評論 1 286
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,673評論 3 391
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,967評論 2 374

推薦閱讀更多精彩內容