【发布时间】:2022-11-14 04:25:50
【问题描述】:
当我的 socket-io 收到事件时,在用户点击主页按钮后,我试图将我的应用程序置于前台,在我的 Javascript 组件和我的 java 模块之间创建一个桥梁后,该功能工作正常,但我的应用程序没有出现在前
这是我的活动(这个活动也很好):
const onEvent = () => {
newRideCall.bringTheApp();
}
这是我的模块
package com.taxitecdriverapp;
import android.content.Intent;
import android.widget.Toast;
import android.content.Context;
import android.app.ActivityManager;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import javax.annotation.Nonnull;
public class NewRideCallModule extends ReactContextBaseJavaModule {
public static final String REACT_CLASS = "NewRideCall";
private static ReactApplicationContext reactContext;
public NewRideCallModule(@Nonnull ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}
@Nonnull
@Override
public String getName() {
return REACT_CLASS;
}
@ReactMethod
public void bringTheApp() {
//I have ben try this first, not workin
Intent i = new Intent(reactContext, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT|Intent.FLAG_ACTIVITY_NEW_TASK);
reactContext.startActivity(i);
// and now this, both of them not working
Context context = getReactApplicationContext();
String pn = context.getApplicationContext().getPackageName();
Intent li = context.getPackageManager().getLaunchIntentForPackage(pn);
context.startActivity(li);
// this Toast shows up fine
Toast.makeText(reactContext, "TAXITEC wakeLockPhone called 0", Toast.LENGTH_LONG).show();
}
}
【问题讨论】:
标签: javascript java android react-native