Search code examples
ionic-frameworkandroid-appwidget

Integrate an App Widget into an ionic project


I'm developing an app widget on Android Studio beside an ionic project. My goal is to to integrate my app widget into the ionic project permitting users having access to the widget by downloading the app.

I started copying pasting some file into the folder platform/android/src but I get the error package R does not exist.

I don't know if it is the right way to do it. If so, which library shall I import to fix this error. I already tried the android.jar from the android-sdk.

Is there any other easiest way to achieve this?

I just want to precise that the widget doesn't communicate with the ionic app, it make just http request to a Rest API.


Solution

  • It is because the hybrid does not have the Class R that manages that part. I'll leave some examples of how I do.

    Instead of using R.layout.new_app_widget

    context.getPackageName(),context.getResources().getIdentifier("new_app_widget", "layout",context.getPackageName());
    

    or

    context.getResources().getIdentifier("new_app_widget", "layout",context.getPackageName());
    

    Instead of using R.id.btn_action

    context.getResources().getIdentifier("btn_action", "id",context.getPackageName());
    

    Instead of using R.string.app_name

    context.getResources().getIdentifier("app_name", "string",context.getPackageName());
    

    Instead of using R.drawable.icon

     context.getResources().getIdentifier("icon", "drawable",context.getPackageName());