如何在应用程序恢复时在 react native 中返回新的bundle



我想在应用恢复时接收图像路径。我是本地反应的新手,我对 android 的 java 了解不多。当我的应用不在后台时,我正在接收图像路径,但是当应用恢复时,我没有收到新的图像路径, 以下是 MainActivity 中的代码.java

package com.myN;
import com.facebook.react.ReactActivity;
//try
import com.facebook.react.ReactActivityDelegate;
import android.content.Intent;
import android.os.Bundle;
import android.net.Uri;
import java.io.InputStream;

import java.io.File;

import android.database.Cursor;

import android.provider.MediaStore;

import com.facebook.react.ReactRootView; //change
//try

public class MainActivity extends ReactActivity {


private ReactRootView mReactRootView; //change
@Override
protected String getMainComponentName() {
return "myN";
}
//try
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {

@Override
protected Bundle getLaunchOptions() {
Intent intent = MainActivity.this.getIntent();
Bundle bundle = new Bundle();
Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);


if (imageUri != null ) {
bundle.putString("image", imageUri.toString());
return bundle;  //returning bunble containing image 
}else{
bundle.putString("image", "");
return bundle;
}

}

};
}
//try

@Override
public Bundle onResume() {
super.onResume();


//what should be the code here to return new bundle which consist of new Image path
}

}

这是我的清单文件中的代码

<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>

现在,当我从图库中共享图像时,我正在接收带有初始道具的图像道具(当应用程序启动时(,并且可以作为 this.props.image 访问,我得到了这个

content://com.android.providers.downloads.documents/document/38 

但问题是,当我再次从图库中共享图像(rn 应用程序是背景(时,我没有收到新的图像路径,尽管我已经与 rn 应用程序共享了新图像,但我收到与以前相同的道具(应用程序恢复时相同的图像文件路径(。 我已经阅读了这里的文档,但我无法理解在哪里为新道具编写。

我对返回新的更新捆绑包没有太多想法,但您可以在清单文件中尝试活动

android:launchMode:"standard"

它将解决您无法收到新道具的问题

最新更新