覆盖onActivityResult本机脚本

时间:2019-01-31 10:24:04

标签: android nativescript

我尝试创建一个Nativescript插件以使用Linkedin帐户登录。使用Android,我需要更改主要活动的onActivityResult方法,并尝试使用@JavaProxy覆盖主要活动,但出现以下错误:

Exception in thread "main" java.io.IOException: File already exists. This may lead to undesired behavior. Please change the name of one of the extended classes.

我的代码:

@JavaProxy("com.tns.NativeScriptLinkedinActivity")
class Activity extends android.app.Activity {
   private _callbacks: AndroidActivityCallbacks;

   public onCreate(savedInstanceState: android.os.Bundle): void {
      if (!this._callbacks) {
        setActivityCallbacks(this);
      }

      this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
   }

   public onSaveInstanceState(outState: android.os.Bundle): void {
       this._callbacks.onSaveInstanceState(this, outState, 
       super.onSaveInstanceState);
   }

   public onStart(): void {
       this._callbacks.onStart(this, super.onStart);
   }

   public onStop(): void {
        this._callbacks.onStop(this, super.onStop);
   }

   public onDestroy(): void {
       this._callbacks.onDestroy(this, super.onDestroy);
   }

   public onBackPressed(): void {
       this._callbacks.onBackPressed(this, super.onBackPressed);
   }

   public onRequestPermissionsResult(requestCode: number, permissions: Array<string>, grantResults: Array<number>): void {
       this._callbacks.onRequestPermissionsResult(this, requestCode, permissions, grantResults, undefined /*TODO: Enable if needed*/);
    }

    public onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent): void {
        super.onActivityResult(requestCode, resultCode, data);
        console.log("ON ACTIVITY RESULT");
        console.log(requestCode + " - " + resultCode);
        com.linkedin.platform.LISessionManager.getInstance(app.android.context).onActivityResult(this, requestCode, resultCode, data);
        this._callbacks.onActivityResult(this, requestCode, resultCode, data, super.onActivityResult);
     }

}

然后我更新了AndroidManifest:

<application
        android:name="com.tns.NativeScriptApplication"
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity
            android:name="com.tns.NativeScriptLinkedinActivity"
            android:label="@string/title_activity_kimera"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:theme="@style/LaunchScreenTheme">

            <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.tns.ErrorReportActivity"/>
    </application>

你能帮我吗?

1 个答案:

答案 0 :(得分:0)

如果您使用的是{N} 5.x或更高版本,则应该扩展android.support.v7.app.AppCompatActivity而不是android.app.Activity