I'm attempting to update a plugin for a react native project that was originally developed and worked in 0.40.0.
Our current project is now on:
react-native-cli: 2.0.1
react-native: 0.60.0
In the code we have this method:
private void sendEvent(ReactContext reactContext,
String eventName,
#Nullable Object params) {
reactContext
.getJSModule(RCTNativeAppEventEmitter.class)
.emit(eventName, params);
}
Which uses this import to get the Nullable class:
import android.support.annotation.Nullable;
The problem is that when we run react-native run-android
We get an error:
error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
^
Any idea how I can get access to this Nullable class again or re-create the functionality such that I can pass in either a null field or like an int?
Examples of how I'd call it:
public void UpdatePoints(int points) {
sendEvent(this.reactContext, "UpdatePoints", points);
}
#Override
public void onPointsEarned() {
sendEvent(this.reactContext, "onPointsEarned", null);
}
I found another SO article that recommended this:
// build.gradle
implementation "androidx.annotation:annotation:1.1.0"
// where use it
import androidx.annotation.Nullable;
But that didn't work. I've found a few things mentioning a transition from support to androidX and it seems like this may be related.
Looks like all you need to do is handle androidx by adding import androidx.annotation.Nullable; instead of import android.support.annotation.Nullable;
Related
How to implement on-demand Play Asset Delivery in flutter through methodchannels.
Actually i am trying to make a dashboard for some app which accesses assets using ContentProvider so i thought play asset delivery might work here.
I know that same can be achieved using deferred components and I have already tried deferred components which is provided by flutter.
You can find it here
Currently, there is an issue with flutter which causes assets to not load when deferred. You can find a link to the issue here.
I do not have any idea of native language and this is the only option I have right now which is implementing a methodchannel so any help would be appreciated
I dont think you can achieve the same thing using play asset delivery. You can try a workaround for this
Disable android:enabled by default by adding android:enabled="false" in your content provider and then use below methodchannel to enable it later
package dev.blah.blah;
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodChannel;
import android.content.ContextWrapper;
import android.widget.Toast;
public class MainActivity extends FlutterActivity {
private static final String CHANNEL = "dev.dhanraj.kwgt.test.dashboard";
#Override
public void configureFlutterEngine(#NonNull FlutterEngine flutterEngine) {
super.configureFlutterEngine(flutterEngine);
new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
.setMethodCallHandler(
(call, result) -> {
// Note: this method is invoked on the main thread.
if (call.method.equals("enable")) {
ContextWrapper aContext = new ContextWrapper(getApplicationContext());
aContext.getPackageManager().setComponentEnabledSetting(new android.content.ComponentName(aContext, "org.kustom.api.Provider"), android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 1);
result.success(null);
Toast.makeText(this, "Done", Toast.LENGTH_SHORT).show();
} else{
result.notImplemented();
}
}
);
}
}
Attempting to create an Android view to use in ReactNative later on.
This is the code that I wrote following the official tutorial, but I'm still getting some troubles compiling.
Here is the error message that I get:
Error:(15, 53) error: constructor ReactImageView in class ReactImageView cannot be applied to given types;
required: Context,AbstractDraweeControllerBuilder,GlobalImageLoadListener,Object
found: no arguments
reason: actual and formal argument lists differ in length
Here instead is the code:
package com.androidbridge;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.views.image.ReactImageView;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.drawee.backends.pipeline.Fresco;
import javax.annotation.Nullable;
public class ReactImageManager extends SimpleViewManager<ReactImageView> {
public static final String REACT_CLASS = "RCTImageView";
private Object mCallerContext;
public ReactImageManager(Object mCallerContext) {
this.mCallerContext = mCallerContext;
}
#Override
public String getName() {
return REACT_CLASS;
}
#Override
protected ReactImageView createViewInstance(ThemedReactContext reactContext) {
return new ReactImageView(reactContext, Fresco.newDraweeControllerBuilder(), mCallerContext);
}
}
I am kind of lost as the code is derived from the official tutorial.
It seems like the signature of the class ReactImageView has changed since the tutorial was written, the constructor now also require you to pass an object of type GlobalImageLoadListener. It is marked as nullable as of the latest react-native version, so you can try just passing a null reference.
I just got started myself and find the tutorial somewhat lacking.
I'm trying to use the LoaderManager in my code however I'm getting an incompatible types error:
#Override
public Loader<List<String>> onCreateLoader(int id, Bundle args) {
return new FileLoader(MainActivity.this);
}
shouldn't this statement return new FileLoader(MainActivity.this) returns a Loader? And here is the implementation of the LoaderManager:
public class FileLoader extends AsyncTaskLoader<List<String>>{
public FileLoader(Context context){
super(context);
}
#Override
public List<String> loadInBackground() {
.........
........
return listFiles;
}
}
I had the same problem(incompatible types required), but when see your post ,it helps me to learn more.In my code, it was imported:
"import androidx.loader.content.AsyncTaskLoader;"
, so i change it to:
"import android.content.AsyncTaskLoader;"
then my problem solved.
Because "AsyncTaskLoader" : This class was deprecated in API level 28,by below ref.
https://developer.android.com/reference/android/content/AsyncTaskLoader
by this advice,"You should also consider migrating existing projects to AndroidX", the webpage below:
https://developer.android.com/jetpack/androidx/migrate/class-mappings
finally I succeeded to solve the problem ... it was that didn't Import the support library in the AsyncTaskLoader file , while using it at the Main file ...so i just removed
import android.content.AsyncTaskLoader;
and Import the following support library
import android.support.v4.content.AsyncTaskLoader;
I have an Android application.
I want to scan for all classes within a package for a specify annotation.
I have:
package com.sample.package;
import com.sample.core.Controller;
import com.sample.core.ProtocolId;
#Controller
public class OtherController implements ControllerInterface{
#ProtocolId(id=100)
public void doSomething(){
//do something
}
}
I'm finding for classes annotated with #Controller for a specify #ProtocolId number.
I'm using Google Reflections library.
Here is how I'm scanning:
package com.sample.package;
import org.reflections.ReflectionUtils;
import org.reflections.Reflections;
import com.sample.core.Controller;
import com.sample.core.ProtocolId;
public class FrontController {
public void executeProperControllerMethodBasedOnId(){
Reflections ref = new Reflections("com.sample.package");
Set<Class<?>> classes = ref.getTypesAnnotatedWith(Controller.class);
System.out.println(classes.size()); //THE SIZE IS 0!!!
//The reflection doesn't worked! It didn't found any class!
}
}
The above code doesn't find any class annotated with specify annotation. Is
there something which I miss when I'm using google reflection library on
android?
In camera.java, I need to get property in system. However, I can't import android.os.SystemProperties, compile camera always complains:
packages/apps/Camera/src/com/android/camera/Camera.java:53: cannot find symbol
symbol : class SystemProperties
location: package android.os
import android.os.SystemProperties;
In the beginning of camera.java, I included:
import android.os.Message;
import android.os.MessageQueue;
import android.os.SystemClock;
import android.os.SystemProperties; /* (this is in line 53)*/
It seems SystemProperties is not in android.os package, but I have checked the frameworks source code, it's indeed in it.
This happen in camera app. I found many apps under packages/app dir using SystemProperties in this manner. It's really strange.
SystemProperties class is setted 'hide' annotation.
So you want to use this class in application layer,
you have to use refelection.
the definition of SystemProperties class is below.
package android.os;
/**
* Gives access to the system properties store. The system properties
* store contains a list of string key-value pairs.
*
* {#hide}
*/
public class SystemProperties
i have encounter the same problem as you have, and i use the code below, and solve the problem by using refelection. hope it would be help
//set SystemProperties as you want
public static void setProperty(String key, String value) {
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method set = c.getMethod("set", String.class, String.class);
set.invoke(c, key, value );
} catch (Exception e) {
Log.d(LOGTAG, "setProperty====exception=");
e.printStackTrace();
}
}