Last active
February 29, 2020 11:21
-
-
Save rafaelpadovani/8a703018034e7de442ca6f12a07c46da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//DeviceInfoModule.java | |
package com.deviceinfoexample; | |
import com.facebook.react.bridge.ReactApplicationContext; | |
import com.facebook.react.bridge.ReactContextBaseJavaModule; | |
import com.facebook.react.bridge.Callback; | |
import com.facebook.react.bridge.ReactMethod; | |
import com.facebook.react.uimanager.IllegalViewOperationException; | |
import com.facebook.react.bridge.Callback; | |
import android.app.PendingIntent; | |
import android.content.Intent; | |
import android.provider.Settings.Secure; | |
import android.content.Context; | |
import com.facebook.react.bridge.Callback; | |
import android.os.AsyncTask; | |
public class DeviceInfoModule extends ReactContextBaseJavaModule { | |
public DeviceInfoModule(ReactApplicationContext reactContext) { | |
super(reactContext); //required by React Native | |
} | |
@Override | |
//getName is required to define the name of the module represented in JavaScript | |
public String getName() { | |
return "DeviceInfoGet"; | |
} | |
@ReactMethod | |
public void getDeviceID(final Callback callback) { | |
getDeviceIDHandler(callback); | |
} | |
private void getDeviceIDHandler(final Callback callback) { | |
AsyncTask<Void,Void,Void> myAsyncTask = new AsyncTask<Void,Void,Void>() { | |
@Override | |
protected Void doInBackground(final Void ... params) { | |
Context context = getReactApplicationContext(); | |
String android_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); | |
callback.invoke(null, android_id); | |
return null; | |
} | |
}; | |
myAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment