My app crash after i press "Log in with Facebook" React-native fbsdk - facebook

i tried to integrate my app with facebook like this:
const FBSDK = require('react-native-fbsdk');
const {
GraphRequest,
GraphRequestManager,
AccessToken,
LoginButton,
LoginManager
} = FBSDK;
....
<LoginButton
style={styles.facebookRegButton}
readPermissions={['public_profile']}
onLogoutFinished={() => alert("User logged out")} />
now when i press on the facebook login button my app crash with the error:
"appname stopped".
i working with android
this is my mainActivity.java file:
package com.students;
import com.facebook.react.ReactActivity;
import com.oblador.vectoricons.VectorIconsPackage;
import com.github.yamill.orientation.OrientationPackage;
import com.BV.LinearGradient.LinearGradientPackage;
import android.content.Intent;
import android.os.Bundle;
import com.facebook.FacebookSdk;
import com.facebook.CallbackManager;
import com.facebook.react.ReactPackage;
public class MainActivity extends ReactActivity {
CallbackManager mCallbackManager = MainApplication.getCallbackManager();
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "students";
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
}
and MainApplication.java file:
package com.students;
import android.app.Application;
import android.util.Log;
import com.facebook.react.ReactApplication;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.imagepicker.ImagePickerPackage;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.CallbackManager;
import com.facebook.FacebookSdk;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.facebook.appevents.AppEventsLogger;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private static CallbackManager mCallbackManager =
CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager() {
return mCallbackManager;
}
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
#Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new FBSDKPackage(mCallbackManager),
new ImagePickerPackage()
);
}
};
#Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
}
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
My react native version is: 0.36.1
tnx a lot

You don't must edit MainActivity.java only MainApplication.java.
To solve it:
MainActivity.java to default
You must configure strings.xml. That file is in android\app\src\main\res\values\strings.xml. Write this line inside <resources> tag.
<string name="facebook_app_id">IDFACEBOOKAPP</string>
Put your facebook app id inside.

Related

Use Datawedge with flutter

I am trying to use the datawedge intent API with my flutter application, on a Zebra android scanner. I started to use the Zebra EMDK API from a git repository, which works perfectly. Now I want to migrate it (which is recommended by Zebra) because I want it to be also available on mobiles (if it is possible).
I am trying to follow the instructions from this page and merge it with the code from the git repo, but no scan event is detected in my app.
Has someone already done this and could help me?
Here is my MainActivity.java:
package com.example.test_datawedge;
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
// import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.EventChannel.EventSink;
import io.flutter.plugin.common.EventChannel.StreamHandler;
import io.flutter.plugins.GeneratedPluginRegistrant;
import java.util.ArrayList;
public class MainActivity extends FlutterActivity {
private static final String BARCODE_RECEIVED_CHANNEL = "samples.flutter.io/barcodereceived";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
// setContentView(R.layout.activity_main);
IntentFilter filter = new IntentFilter();
filter.addCategory(Intent.CATEGORY_DEFAULT);
filter.addAction(getResources().getString(R.string.activity_intent_filter_action));
// registerReceiver(myBroadcastReceiver, filter);
new EventChannel(getFlutterView(), BARCODE_RECEIVED_CHANNEL).setStreamHandler(
new StreamHandler() {
private BroadcastReceiver barcodeBroadcastReceiver;
#Override
public void onListen(Object arguments, EventSink events) {
Log.d("FLUTTERDEMO", "EventChannelOnListen");
barcodeBroadcastReceiver = createBarcodeBroadcastReceiver(events);
registerReceiver(
barcodeBroadcastReceiver, new IntentFilter("readBarcode"));
}
#Override
public void onCancel(Object arguments) {
Log.d("FLUTTERDEMO", "EventChannelOnCancel");
unregisterReceiver(barcodeBroadcastReceiver);
barcodeBroadcastReceiver = null;
}
}
);
}
// #Override
// protected void onDestroy()
// {
// super.onDestroy();
// unregisterReceiver(myBroadcastReceiver);
// }
//
// After registering the broadcast receiver, the next step (below) is to define it.
// Here it's done in the MainActivity.java, but also can be handled by a separate class.
// The logic of extracting the scanned data and displaying it on the screen
// is executed in its own method (later in the code). Note the use of the
// extra keys are defined in the strings.xml file.
//
private BroadcastReceiver createBarcodeBroadcastReceiver(final EventSink events) {
return new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d("FLUTTERDEMO", "createBarcodeBroadcastReceiver " + action);
if(action.equals("readBarcode")){
String barcode = intent.getStringExtra("barcode");
String barcodetype = intent.getStringExtra("barcodetype");
Log.d("FLUTTERDEMO", "createBarcodeBroadcastReceiver " + barcode);
events.success(barcode);
}
}
};
}
//
// The section below assumes that a UI exists in which to place the data. A production
// application would be driving much of the behavior following a scan.
//
// private void displayScanResult(Intent initiatingIntent, String howDataReceived)
// {
// String decodedSource = initiatingIntent.getStringExtra(getResources().getString(R.string.datawedge_intent_key_source));
// String decodedData = initiatingIntent.getStringExtra(getResources().getString(R.string.datawedge_intent_key_data));
// String decodedLabelType = initiatingIntent.getStringExtra(getResources().getString(R.string.datawedge_intent_key_label_type));
// final TextView lblScanSource = (TextView) findViewById(R.id.lblScanSource);
// final TextView lblScanData = (TextView) findViewById(R.id.lblScanData);
// final TextView lblScanLabelType = (TextView) findViewById(R.id.lblScanDecoder);
// lblScanSource.setText(decodedSource + " " + howDataReceived);
// lblScanData.setText(decodedData);
// lblScanLabelType.setText(decodedLabelType);
// }
}
Zebra EMDK retrieves data by overriding the 'onStatus' and 'onData' functions.
Retrieve your barcode data from 'onData'

JavaScript method window.open() is not opening new window in my JavaFX browser

I have built an web browser in JavaFX. I want to add new popup window feature in my browser. when I use JavaScript method window.open(). It will execute code and open new popup window.
package browser;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.event.ActionEvent;
import javafx.event.EventTarget;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javax.swing.JOptionPane;
import netscape.javascript.JSObject;
public class BrowserController implements Initializable {
#FXML
BorderPane browserBP;
#FXML
WebView browserWV;
#FXML
ImageView stopReloadIV;
#FXML
TextField addressBarTF;
#FXML
ProgressIndicator progressPI;
#FXML
Label statusL;
/**
* Initializes the controller class.
*/
#Override
public void initialize(URL url, ResourceBundle rb)
{
popup pop_up = new popup();
browserWV.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>()
{
#Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
statusL.setText("loading... " + browserWV.getEngine().getLocation());
stopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/stoploading.png")));
progressPI.setVisible(true);
if(newValue == Worker.State.SUCCEEDED) {
//
JSObject window = (JSObject) browserWV.getEngine().executeScript("window");
window.setMember("window",pop_up);
addressBarTF.setText(browserWV.getEngine().getLocation());
statusL.setText("loaded");
progressPI.setVisible(false);
stopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/reload.png")));
if(browserBP.getParent() != null) {
TabPane tp = (TabPane)browserBP.getParent().getParent();
for(Tab tab : tp.getTabs()) {
if(tab.getContent() == browserBP) {
tab.setText(browserWV.getEngine().getTitle());
break;
}
}
}
}
}
});
WebEngine webEngine = browserWV.getEngine();
webEngine.setJavaScriptEnabled(true);
}
#FXML
private void browserBackButtonAction(ActionEvent event) {
if(browserWV.getEngine().getHistory().getCurrentIndex() <= 0) {
return;
}
browserWV.getEngine().getHistory().go(-1);
}
#FXML
private void browserForwardButtonAction(ActionEvent event) {
if((browserWV.getEngine().getHistory().getCurrentIndex() + 1) >= browserWV.getEngine().getHistory().getEntries().size()) {
return;
}
browserWV.getEngine().getHistory().go(1);
}
#FXML
private void browserGoButtonAction(ActionEvent event) {
String url = addressBarTF.getText().trim();
/*if(url.isEmpty())
{
JOptionPane.showMessageDialog(null, "No url provided");
return;
}
if(!url.startsWith("http://") && !url.startsWith("https://")) {
url = "http://"+url;
}*/
browserWV.getEngine().load(url);
//browserStopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/stoploading.png")));
}
#FXML
private void browserStopReloadButtonAction(ActionEvent event) {
if(browserWV.getEngine().getLoadWorker().isRunning()) {
browserWV.getEngine().getLoadWorker().cancel();
statusL.setText("loaded");
progressPI.setVisible(false);
stopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/reload.png")));
} else {
browserWV.getEngine().reload();
stopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/stoploading.png")));
}
}
#FXML
private void browserHomeButtonAction(ActionEvent event) {
browserWV.getEngine().loadContent("<html><title>New Tab</title></html>");
addressBarTF.setText("");
}
private TextField setText(String ur1) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
It's popup class to open new popup window.But when I use window.open method in JavaScript. It's working but in same window.How it will be open in new window?
package browser;
import java.net.URL;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.web.PopupFeatures;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Callback;
import static sun.plugin.javascript.navig.JSType.URL;
public class popup
{
public void open(String url)
{
WebView browserWV = new WebView();
Platform.runLater(new Runnable()
{
#Override
public void run()
{
browserWV.getEngine().setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>()
{
#Override
public WebEngine call(PopupFeatures p) {
Stage stage = new Stage(StageStyle.UTILITY);
WebView wv2 = new WebView();
stage.setScene(new Scene(wv2));
stage.show();
WebEngine webEngine = new WebEngine();
webEngine.setJavaScriptEnabled(true);
return wv2.getEngine();
}
});
VBox root = new VBox();
TextField address_bar = new TextField();
root.getChildren().add(address_bar);
root.getChildren().add(browserWV);
Scene scene = new Scene(root, 1370, 700);
Stage primaryStage = new Stage();
primaryStage.setTitle("Popup");
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setIconified(true);
browserWV.getEngine().load(url);
address_bar.setText(browserWV.getEngine().getLocation());
}
});
}
}

Android Studio says "Expression expected"

Android Studio tells there is an error in Java file, in string summonButton2(); Android Studio says "Expression expected".
I want the method summonButton2 to be launched automatically. I undesrtand that I'm doing it wrong. What exactly and is there any other way to start a method, except adding it to onCreate method? Thanks in advance.
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
int numberOfLinesLeft = 3;
Button secondaryActivityAddButton;
LinearLayout llForSecondaryButton;
LinearLayout llForSecondaryEditText;
EditText et;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
summonButton2();
}
public void summonButton2(View view){
llForSecondaryButton = findViewById(R.id.secondaryButton);
secondaryActivityAddButton = new Button(this);
secondaryActivityAddButton.setText("" + numberOfLinesLeft);
llForSecondaryButton.addView(secondaryActivityAddButton);
secondaryActivityAddButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
plusTextField();
if(numberOfLinesLeft == 0) {
view.setVisibility(View.GONE);
}
}
});
}
public void plusTextField() {
llForSecondaryEditText = findViewById(R.id.linearLayout1);
// add edittext
et = new EditText(this);
et.setText("text" + numberOfLinesLeft );
llForSecondaryEditText.addView(et);
numberOfLinesLeft--;
secondaryActivityAddButton.setText("" + numberOfLinesLeft);
}
}
summonButton2(new View(this));
Helped in my case.

Error in creating list

I am new to android and i have a Error creating list....... What is the Error? some one help me out........ I am using api18.........
package com.example.personalinformationmanagement;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends ListActivity {
String list[] = {"PersonalTask", "PersonaFileInformation","WeaklyReports", "Remainder"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setListAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1));
}
/* (non-Javadoc)
* #see android.app.ListActivity#onListItemClick(android.widget.ListView, android.view.View, int, long)
*/
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String choice = list[position];
try{
Class ourClass = Class.forName("com.example.personalinformationmanagement." +choice);
Intent i = new Intent(MainActivity.this,ourClass);
startActivity(i);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
First of all ensure that listview id in your activity_main.xml equals to "android:id="#android:id/list".
In code change line
setListAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1,list));
If you want to manipulate with listView use:
ListView myListView = getListview();

Why isn't the TextView working?

I'm coding an android program that arranges three words in alphabetical order using two simple activities.But in the second(output) activity,either the TextView or the Intents aren't working.The output isn't getting displayed.The java code for first(input) activity is as follows:
`package com.example.names;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Input extends Activity {
EditText t1,t2,t3;
final Context context=this;
String n[]=new String[100];
String t[]=new String[100];
String a1,a2,a3;
Button alpha;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.input);
t1=(EditText)findViewById(R.id.editText1);
t2=(EditText)findViewById(R.id.editText2);
t3=(EditText)findViewById(R.id.editText3);
n[0]=t1.getText().toString();
n[1]=t2.getText().toString();
n[2]=t3.getText().toString();
for(int j=0;j<2;j++)
{
for(int k=j+1;k<3;k++)
{
if(n[j].compareToIgnoreCase(n[k])>0)
{
String temp=n[j];
n[j]=n[k];
n[k]=temp;
}
}
}
a1=n[0];
a2=n[1];
a3=n[2];
alpha=(Button)findViewById(R.id.button1);
alpha.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i=new Intent(Input.this,Output.class);
i.putExtra("x", a1+a2+a3);
Toast.makeText(Input.this, "Method OnClick has been invoked",Toast.LENGTH_SHORT).show();
startActivity(i);
}
});}}`
And the java code for second activity is as follows:
package com.example.names;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class Output extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView p1=new TextView(this);
Bundle extras=getIntent().getExtras();
if (extras!=null){
String ans=extras.getString("x");
p1.setText(ans);
p1.setTextSize(50);
Toast.makeText(Output.this, "All lines have been executed",Toast.LENGTH_LONG).show();
setContentView(p1);
}};}
Why isn't the output getting displayed then???
The application is not crashing also.
Change your code with this below code.
Get edittext value when button is clicked.
Your Input Activity looks like this.
public class Input extends Activity {
EditText t1,t2,t3;
final Context context=this;
String n[]=new String[100];
String t[]=new String[100];
String a1,a2,a3;
Button alpha;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.input);
t1=(EditText)findViewById(R.id.editText1);
t2=(EditText)findViewById(R.id.editText2);
t3=(EditText)findViewById(R.id.editText3);
alpha=(Button)findViewById(R.id.button1);
alpha.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
n[0]=t1.getText().toString();
n[1]=t2.getText().toString();
n[2]=t3.getText().toString();
for(int j=0;j<2;j++)
{
for(int k=j+1;k<3;k++)
{
if(n[j].compareToIgnoreCase(n[k])>0)
{
String temp=n[j];
n[j]=n[k];
n[k]=temp;
}
}
}
a1=n[0];
a2=n[1];
a3=n[2];
Intent i=new Intent(Input.this,Output.class);
i.putExtra("x", a1+a2+a3);
Toast.makeText(Input.this, "Method OnClick has been invoked",Toast.LENGTH_SHORT).show();
startActivity(i);
}
});}}
Your Output Activity is fine it is working no changes in that activity.