1

我想在 react-native-navigation 的帮助下设置从intent.ACTION_SEND 获得的initialProps。

MainActivity.java

public class MainActivity extends SplashActivity {

String sharedText;
Uri sharedImage;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if(Intent.ACTION_SEND.equals(action) && type != null){
        if(type.startsWith("text/")){
            handleSendText(intent);
        }else if(type.startsWith("image/")){
            handleSendImage(intent);
        }
    }
}



void handleSendText(Intent intent){
    sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
}

void handleSendImage(Intent intent){
    sharedImage = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
}


/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */


 @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Intent intent = new Intent("onConfigurationChanged");
    intent.putExtra("newConfig", newConfig);
    this.sendBroadcast(intent);

}

protected String getMainComponentName() {
    return "Atmiyo";
}
}

MainApplication.java

public class MainApplication extends NavigationApplication {

    @Override
     public boolean isDebug() {
         // Make sure you are using BuildConfig from your own application
         return BuildConfig.DEBUG;
     }

protected List<ReactPackage> getPackages() {
         // Add additional packages you require here
         // No need to add RnnPackage and MainReactPackage
         return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
        new ReactNativeContacts(),
        new SyncAdapterPackage(),
        new RNSoundPackage(),
        new OrientationPackage(),
        new ReactNativeOneSignalPackage(),
        new BlurViewPackage(),
        new Interactable(),
        new SvgPackage(),
        new RNGooglePlacesPackage(),
        new RNVideoProcessingPackage(),
        new A0Auth0Package(),
            new RNFirebaseAdMobPackage(),
            new LinearGradientPackage(),
            new RNSpinkitPackage(),
            new ReactVideoPackage(),
            new RNReactNativeLinkPreviewPackage()

         );
     }

     @Nullable
     @Override
     public List<ReactPackage> createAdditionalReactPackages() {
         return getPackages();
     }

@Override
public void onCreate() {
    super.onCreate();
    setActivityCallbacks(new ActivityCallbacks(){


        @Override
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
            super.onActivityCreated(activity, savedInstanceState);
            activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        }


        @Override
        public void onActivityStarted(Activity activity) {
            super.onActivityStarted(activity);
        }

        @Override
        public void onActivityResumed(Activity activity) {
            super.onActivityResumed(activity);
        }

        @Override
        public void onActivityPaused(Activity activity) {
            super.onActivityPaused(activity);
        }

        @Override
        public void onActivityStopped(Activity activity) {
            super.onActivityStopped(activity);
        }

        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
        }

        @Override
        public void onActivityDestroyed(Activity activity) {
            super.onActivityDestroyed(activity);
        }
    });
}

如您所见,我可以从 MainActivity.java 中的 intent.ACTION_SEND 获取意图数据,但我无法弄清楚如何在 app.android.js 中传递该值。

谁能帮我这个?

4

0 回答 0