Search code examples
androidangulartypescriptandroid-widgetnativescript

Can't use com.tns to find a class


I am trying to make a widget with Nativescript and Angular.

I used this example to help me further but now I am stuck on this code.

I can't find any help for this on the internet and can't figure it out myself.

This is my Component a lot is similar to the example I used as I am new to Nativescript.

@JavaProxy("a.b.MyWidget")
export class WidgetComponent extends android.appwidget.AppWidgetProvider {

    onUpdate(context, appWidgetManager, appWidgetIds): void {
      var appWidgetsLen = appWidgetIds.length

      for (let i = 0; i < appWidgetsLen; i++) {
        this.updateWidget(context, appWidgetManager, appWidgetIds, appWidgetIds[i]);
      }
    }

    updateWidget(ontext, appWidgetManager, appWidgetIds, widgetId){
      const context = app.android.context;

      let views:any = context.getResources().getIdentifier("appwidget", "layout", context.getPackageName());
      let resourceId:any = context.getResources().getIdentifier("appwidget", "id", context.getPackageName())

      var textView = new android.widget.RemoteViews(context.getPackageName(), views);
      textView.setTextViewText(resourceId.taps_text, "Just for testing");

      var intent: android.content.Intent = new android.content.Intent(context, com.tns.MyWidget);

      intent.setAction(android.appwidget.AppWidgetManager.ACTION_APPWIDGET_UPDATE);
      intent.putExtra(android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

      var startAppIntent = new android.content.Intent(context, com.tns.NativeScriptActivity.class); // the activity defined in AndroidManifest
      startAppIntent.putExtra(android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);


      appWidgetManager.updateAppWidget(widgetId, textView);
    }
}

In the layout file is no text attribute and I want to set it from the component.

It goes stuck on the part com.tns.MyWidget when I call the intent.


Solution

  • You have declared the JavaProxy as a.b.MyWidget, so you must be accessing the same instead of com.tns.MyWidget in example.