diff --git a/404.html b/404.html index c14f468..b285216 100644 --- a/404.html +++ b/404.html @@ -7,7 +7,7 @@ - +
diff --git a/assets/js/f477c445.974e1f48.js b/assets/js/f477c445.974e1f48.js new file mode 100644 index 0000000..a9c90f0 --- /dev/null +++ b/assets/js/f477c445.974e1f48.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkreact_native_android_widget_docs=self.webpackChunkreact_native_android_widget_docs||[]).push([[9990],{5733:(e,i,n)=>{n.r(i),n.d(i,{assets:()=>c,contentTitle:()=>o,default:()=>g,frontMatter:()=>s,metadata:()=>l,toc:()=>u});var t=n(5893),r=n(1151),a=n(4866),d=n(5162);const s={sidebar_position:4},o="Register widget",l={id:"tutorial/register-widget",title:"Register widget",description:"In order to register our widget so that it can be selected from the launchers widget picker, we need to tell the android app some information about the widget.",source:"@site/docs/tutorial/register-widget.md",sourceDirName:"tutorial",slug:"/tutorial/register-widget",permalink:"/react-native-android-widget/docs/tutorial/register-widget",draft:!1,unlisted:!1,editUrl:"https://github.com/sAleksovski/react-native-android-widget/tree/master/docs/docs/tutorial/register-widget.md",tags:[],version:"current",sidebarPosition:4,frontMatter:{sidebar_position:4},sidebar:"default",previous:{title:"Register task handler",permalink:"/react-native-android-widget/docs/tutorial/register-task-handler"},next:{title:"Register widget in Expo",permalink:"/react-native-android-widget/docs/tutorial/register-widget-expo"}},c={},u=[{value:"Add a widget provider class",id:"add-a-widget-provider-class",level:2},{value:"Create widget preview image",id:"create-widget-preview-image",level:2},{value:"Add widget description string (Optional)",id:"add-widget-description-string-optional",level:2},{value:"Add a widget provider xml file",id:"add-a-widget-provider-xml-file",level:2},{value:"Add services in AndroidManifest.xml",id:"add-services-in-androidmanifestxml",level:2},{value:"Add widget receiver in AndroidManifest.xml",id:"add-widget-receiver-in-androidmanifestxml",level:2},{value:"Add custom fonts used in widgets",id:"add-custom-fonts-used-in-widgets",level:2}];function h(e){const i={a:"a",code:"code",h1:"h1",h2:"h2",img:"img",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(i.h1,{id:"register-widget",children:"Register widget"}),"\n",(0,t.jsx)(i.p,{children:"In order to register our widget so that it can be selected from the launchers widget picker, we need to tell the android app some information about the widget."}),"\n",(0,t.jsx)(i.h2,{id:"add-a-widget-provider-class",children:"Add a widget provider class"}),"\n",(0,t.jsxs)(i.p,{children:["Create a new package ",(0,t.jsx)(i.code,{children:"widget"})," in the native android app."]}),"\n","\n","\n",(0,t.jsxs)(a.Z,{children:[(0,t.jsxs)(d.Z,{value:"Java",label:"Java",default:!0,children:[(0,t.jsxs)(i.p,{children:["Inside it create a class ",(0,t.jsx)(i.code,{children:"Hello.java"})]}),(0,t.jsx)(i.pre,{children:(0,t.jsx)(i.code,{className:"language-java",metastring:'title="android/app/src/main/java/com/yourapppackage/widget/Hello.java"',children:"package com.yourapppackage.widget;\n\nimport com.reactnativeandroidwidget.RNWidgetProvider;\n\npublic class Hello extends RNWidgetProvider {\n}\n"})})]}),(0,t.jsxs)(d.Z,{value:"Kotlin",label:"Kotlin",children:[(0,t.jsxs)(i.p,{children:["Inside it create a class ",(0,t.jsx)(i.code,{children:"Hello.kt"})]}),(0,t.jsx)(i.pre,{children:(0,t.jsx)(i.code,{className:"language-kotlin",metastring:'title="android/app/src/main/java/com/yourapppackage/widget/Hello.kt"',children:"package com.yourapppackage.widget\n\nimport com.reactnativeandroidwidget.RNWidgetProvider\n\nclass Hello : RNWidgetProvider() {\n}\n"})})]})]}),"\n",(0,t.jsxs)(i.p,{children:["The class ",(0,t.jsx)(i.strong,{children:"name"})," will be used to reference our widget."]}),"\n",(0,t.jsx)(i.h2,{id:"create-widget-preview-image",children:"Create widget preview image"}),"\n",(0,t.jsx)(i.p,{children:"When the android launcher shows the widget select popup, we can show a screenshot of our widget to give the user an idea what the widget looks like."}),"\n",(0,t.jsxs)(i.p,{children:["Take a screenshot of the widget, and place it inside ",(0,t.jsx)(i.code,{children:"android/app/src/main/res/drawable/hello_preview.png"})]}),"\n",(0,t.jsx)("pre",{children:"android/app/src/main/res/drawable/hello_preview.png"}),"\n",(0,t.jsx)(i.p,{children:(0,t.jsx)(i.img,{alt:"Hello Widget Preview",src:n(6945).Z+"",width:"327",height:"208"})}),"\n",(0,t.jsx)(i.h2,{id:"add-widget-description-string-optional",children:"Add widget description string (Optional)"}),"\n",(0,t.jsxs)(i.p,{children:["When the android launcher shows the widget select popup, under the name of the widget it can show an optional description about the widget. If we want to show a description for our widget, we need to add a description string in ",(0,t.jsx)(i.code,{children:"strings.xml"})]}),"\n",(0,t.jsx)(i.pre,{children:(0,t.jsx)(i.code,{className:"language-xml",metastring:'title="android/app/src/main/res/values/strings.xml"',children:'\n<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My App Name</string>
<string name="widget_hello_description" translatable="false">This is my first widget</string>
</resources>
Create a new xml file in the resources directory containing the details about the widget.
-<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="320dp"
android:minHeight="120dp"
android:updatePeriodMillis="0"
android:initialLayout="@layout/rn_widget"
android:previewImage="@drawable/hello_preview"
android:description="@string/widget_hello_description"
android:resizeMode="none"
android:widgetCategory="home_screen">
</appwidget-provider>
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="320dp"
android:minHeight="120dp"
android:targetCellWidth="5"
android:targetCellHeight="2"
android:updatePeriodMillis="0"
android:initialLayout="@layout/rn_widget"
android:previewImage="@drawable/hello_preview"
android:description="@string/widget_hello_description"
android:resizeMode="none"
android:widgetCategory="home_screen">
</appwidget-provider>
android:updatePeriodMillis
How often, in milliseconds, that this AppWidget wants to be updated. The task handler will be called with widgetAction = 'UPDATE_WIDGET'
. See the official docs hereandroid:previewImage
should reference the preview image we added previously