[英]How use notification icon from React Native app to some RNBridge?
我創建了一個到 React Native 的橋梁,以便與 Oracle-Responsys SDK 一起工作。
橋運行得很好,但我唯一被卡住的是如何將通知圖標從我的 react 本機應用程序設置到這個橋。
根據 Responsys 的文檔:
PushIOManager.getInstance(this).setDefaultSmallIcon(R.drawable.emo_im_surprised);
PushIOManager.getInstance(this).setDefaultLargeIcon(R.drawable.emo_im_happy);
注意: Integer 值必須是構建系統生成的資源 ID。 在上述調用中,圖標名稱代表 Integer 值。 例如,R.drawable.emo_im_surprised 是已放置在可繪制文件夾中的圖標 emo_im_surprised.png 的 Integer 值。
我知道了,但是這個R.drawable
引用了我的橋的可繪制對象而不是應用程序可繪制對象,我如何在我的橋中使用我的應用程序中的圖標?
我通過創建這個 function 解決了這個問題:
private int getDrawableId(String name) {
String packageName = getReactApplicationContext().getPackageName();
return getReactApplicationContext().getResources().getIdentifier(name, "drawable", packageName);
}
並像這樣使用它:
Integer notificationIcon = getDrawableId("ic_responsys_alt");
pushIOManager.setDefaultSmallIcon(notificationIcon);
使用此代碼,您只需在 app drawable 文件夾中添加一個名為ic_responsys_alt
的圖標。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.