日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

rk3288 添加系统广播

發布時間:2023/12/14 windows 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 rk3288 添加系统广播 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

可在自己需要的位置注冊接受廣播的action,這邊是注冊在Intent上。

1.添加action字符串
修改位置

frameworks/base/core/java/android/content/Intent.java + /** + *@hide + * @hide必須要加 + **/ + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_demo="android.intent.action.demo";

2.注冊該廣播
修改位置

frameworks/base/core/res/AndroidManifest.xml + <!-- for demo --> + <protected-broadcast android:name="android.intent.action.demo" />

在需要的地方發送廣播

+ Intent intent = new Intent(Intent.ACTION_demo); + intent.putExtra("state",state); + sendBroadcastToAll(intent);+ private void sendBroadcastToAll(Intent intent) { + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); + intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); + final long ident = Binder.clearCallingIdentity(); + try { + mContext.sendBroadcastAsUser(intent, UserHandle.ALL); + } finally { + Binder.restoreCallingIdentity(ident); + } + }

3.可在系統中寫個接收的廣播,此例中,添加一個服務,在服務中注冊接收廣播
新建服務:
在frameworks/base/packages/SystemUI/src/com/android/systemui/文件夾新建一個自己的目錄,新建一個服務。
eg:frameworks/base/packages/SystemUI/src/com/android/systemui/test/TestService.java

+package com.android.systemui.test; + +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.IBinder; +import android.util.Log; + + +public class TestService extends Service { + + private static final String TAG = "TestService"; + private SwitchAppReceiver receiver; + + @Override + public void onCreate() { + super.onCreate(); + Log.i(TAG,"TestService oncreate"); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Log.i(TAG,"TestService onStartCommand"); + registerReceiver(); + return super.onStartCommand(intent, flags, startId); + + } + + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public void onDestroy() { + Log.i(TAG,"TestService onDestroy"); + unRegistReceiver(); + super.onDestroy(); + } + + private void registerReceiver() { + receiver = new SwitchAppReceiver(); + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_TES_SWITCH_APP); + registerReceiver(receiver, filter); + } + + private void unRegistReceiver() { + try { + this.unregisterReceiver(receiver); + } catch (Exception e) { + + } + } +}

新建廣播

eg:frameworks/base/packages/SystemUI/src/com/android/systemui/test/SwitchAppReceiver.java

+package com.android.systemui.test; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.PackageManager; +import android.util.Log; + +public class SwitchAppReceiver extends BroadcastReceiver { + + public static final String TAG = "swith_app"; + + @Override + public void onReceive(Context context, Intent intent) { + Log.i(TAG, "SwitchAppReceiver onReceive=="); + //do something+ } + +}

4.在合適的地方開啟服務

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.javapublic PhoneStatusBarPolicy(Context context, StatusBarIconController iconController) {/* start test switch app */Log.d("TestService","##################");Intent mIntent = new Intent(mContext,TesService.class); mContext.startService(mIntent);}

總結

以上是生活随笔為你收集整理的rk3288 添加系统广播的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。