首页 > 解决方案 > 无法使用 com.tns 查找课程

问题描述

我正在尝试使用 Nativescript 和 Angular 制作一个小部件。

我用这个例子来进一步帮助我,但现在我被困在这段代码上。

我在互联网上找不到任何帮助,我自己也无法弄清楚。

这是我的组件,与我使用的示例非常相似,因为我是 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);
    }
}

在布局文件中没有文本属性,我想从组件中设置它。

com.tns.MyWidget当我调用意图时,它会卡在零件上。

标签: androidangulartypescriptandroid-widgetnativescript

解决方案


您已将 JavaProxy 声明为a.b.MyWidget,因此您必须访问它而不是com.tns.MyWidget示例。


推荐阅读