since hours I am trying to figure out why my facebook-connect is not working properly. I always have to click it two times.. the first time I click it I see that the facbeook dialog is opening but its not calling any kind of callback so my Login-Activity is just "resuming".
public void onClick_fbIcon(View v) {
if(!buttonsEnabled)
return;
buttonsEnabled = false;
tryFacebookConnect();
}
#SuppressWarnings("deprecation")
private void tryFacebookConnect() {
Log.d("debug", "start fbc");
doingFacebooklogin = true;
facebook.authorize(this, new DialogListener() {
public void onComplete(Bundle values) {
end();
toast("Complete");
Log.d("debug", "#0");
// .. continue with main code
}
public void onFacebookError(FacebookError error) {
end();
Log.d("debug", "#1");
}
public void onError(DialogError e) {
end();
Log.d("debug", "#2");
}
public void onCancel() {
end();
Log.d("debug", "#3");
}
private void end() {
Log.d("debug", "fbc complete");
doingFacebooklogin = false;
}
});
}
The first click I only get "start fbc" but nothing after that, so I guess that no callback method is called.
I found out that when the facebook-connect is not working the first time, "onResume is called". The next time onActivityResult is called.
#SuppressWarnings("deprecation")
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("debug", "Main: onActivityResult");
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
My login activity is an intent started by my main activity that is specifing if a login is needed at all:
Intent intent = new Intent(this, Login.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
Sometimes I can see the following error:
11-22 10:23:39.684: D/Facebook-publish(7317): Can NOT get FbInjector instance! Probably because this method was called in ContentProvider's onCreate.
Please take a look at this Tutorial. I just Follow this and I make it all works perfectly.
Hope that it will help you too.
http://www.youtube.com/watch?v=xndi6s9Tn_U
I don't know why but the problem is obviously part of the facebook-sdk. I found out that this problem does not occur if I have no facebook-app installed on my device. So I changed my code like this:
facebook.authorize(a, new String[] { }, **Facebook.FORCE_DIALOG_AUTH**, new DialogListener() {
...
Related
I need to build an app which will recognize QR codes without forcing the user to install other apps. In future, I will also need to manipulate the scanned image before recognizing the code (codes scanned by me will have inverted colors).
Trying to follow hints and tutorials from these links:
Integrating the ZXing library directly into my Android application
Embedding ZXing in android app
http://karanbalkar.com/2013/12/tutorial-65-implement-barcode-scanner-using-zxing-in-android/
After creating some basic code and running the app I click my Scan button and get an error that No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN (has extras) }
What I've done:
Create new project
Copy core-3.2.1.jar to libs/
Add intent calling and result handling
intent/result code added by me:
private Button scan;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scan= (Button)findViewById(R.id.btnScan);
scan.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
MultiFormatWriter writer = new MultiFormatWriter();
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
Log.i("App","Scan unsuccessful");
}
}
}
How to start the intent? What am I doing wrong?
you should launch scan like this:
#Override
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
//in case you want to customize a bit.
integrator.setPrompt("Scan a QR/Bar code");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.initiateScan();
}
Receive results like this:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case IntentIntegrator.REQUEST_CODE: {
if (resultCode != RESULT_CANCELED) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
String data = scanResult.getContents();
// use this data
} else {
// error
}
break;
}
}
}
Edit 1:
Add this to build.gradle of your app as dependencies:
compile 'com.journeyapps:zxing-android-embedded:3.0.2#aar'
compile 'com.google.zxing:core:3.2.0'
Try the below link it worked for me:
https://github.com/dlazaro66/QRCodeReaderView
I have a WebActivity that sets a JavascriptInterface for a WebView, on the Interface I have created various methods to be called with Javascript for different tasks, one of them is to send a file through Bluetooth.
The file sends just fine, but I want to inform the user when the file has already been accepted and transmited completely on the other end.
I am trying to use onActivityResult on my main WebActivity and also have tried on the separate class that handles the Bluetooth transmission and has a method called on the JavascriptInterface but I am not getting any callback results after the file is succesfully sent:
//First attempt
public class WebActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
//some code here
//Here I set the interface
myWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
}
#Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == 0) {
//This message is shown after the file transfer has started but no
//finished
Toast.makeText(this, "File Sent", Toast.LENGTH_SHORT).show();
if(resultCode == Activity.RESULT_OK){
//It doesn't work here either I always get Activity.RESULT_CANCELED (0)
//flag afer the file transfer has started
}
}
}
}
//Second Attempt
public class BluetoothTasks {
//code here
private void startTransferIntent() {
//some more code here
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
File file_to_transfer = new File(Environment.getExternalStorageDirectory() +
"/txtTransfer.txt");
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(file_to_transfer));
//some more code here
Activity act = (Activity) mContext;
act.startActivityForResult(intent, TRANSFER_RESULT);
}
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == TRANSFER_RESULT) {
//Not working here either
//code that is not executed
}
}
}
Could you please tell me if there is a way to do this and if so how would be accomplished?. Thank you.
It's a bit weird but maybe someone has an idea.
Activity A opens Activity B. In Activity B i press a button and it should be closed
returning to Activity A and then close it as well.
However, sometimes (1 to 7 times maybe) Activity B closes but Activity A remains.
Activity A
public void Foo() {
if (bIsVerifyClicked)
{
Intent intent = new Intent(ActivityA.this, ActivityB.class);
startActivityForResult(intent, 1000);
}
else
{
setResult(RESULT_OK);
finish();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(Logger.TAG, "=============requestCode: " + requestCode + " resultCode: " + resultCode);
if (resultCode == RESULT_OK)
{
setResult(RESULT_OK);
finish();
}
super.onActivityResult(requestCode, resultCode, data);
}
Activity B
mNextButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(Logger.TAG, "ActivityB ==== finish()");
setResult(RESULT_OK);
finish();
}
});
i thought maybe there is a memory leak in Activity B and thus the onResult get lost or something,
but it's java and i don't see anything strange.
do you have any lead what should i look for?
or how can i better debug this?
I am not able to figure out the exact issue.
But in your code i can see onActivityResult() of Activity A, no need of
setResult(RESULT_OK);
You can directly finish() activity A.
I've got a problem. I want to change the text of a textview after selecting an item (ringtone). I got the selected ringtone title and wanted to write it on the text attribute of textview, but it doesn't work (I am in the UI Thread not in a seperate thread).
Here's the code, where i want to update the text:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(resultCode) {
case RESULT_OK:
String ringtoneTitle = null;
ringtoneUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if(ringtoneUri != null) {
ringtoneValue = ringtoneUri.toString(); //diesen Wert später in Datenbank abspeichern !!
ringtoneTitle = RingtoneManager.getRingtone(this, ringtoneUri).getTitle(this); //Titel getten
}
textViewRingtone.append(": " + ringtoneTitle); //Titel zu TextView setzen
break;
}
}
Can somebody help ?
Use the post(Runnable) method of the View class :
textViewRingtone.post(new Runnable() {
#Override
public void run() {
textViewRingtone.append(": " + ringtoneTitle);
}
};
Try setting textview inside a handler:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(resultCode) {
case RESULT_OK:
String ringtoneTitle = null;
ringtoneUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if(ringtoneUri != null) {
ringtoneValue = ringtoneUri.toString(); //diesen Wert später in Datenbank abspeichern !!
ringtoneTitle = RingtoneManager.getRingtone(this, ringtoneUri).getTitle(this); //Titel getten
}
new Handler().post(new Runnable() {
#Override
public void run() {
textViewRingtone.append(": " + ringtoneTitle); //Titel zu TextView setzen
}
});
break;
}
}
OK,
i've found the solution, it was a really, really silly mistake of mine, that you couldnt know, because i didnt show that code to you.
In the onClick Method, in which i start the intent of showing the ringtone picker i accidentally called startActivity(intent) instead of startActivityForResult(intent, requestCode) so onActivityResult couldn't get called.
Thanks to #codeMagic, who made me realize this mistake.
I have an MainActivity which has two TextView. User has an option to start another activity and choose data from ListView to fill those TextView. My main activity has an OnClickListener which starts an Activty from which user can select data and come back to main activity.My OnClickListener code looks likes this:
private static final int PICK_START = 0;
private static final int PICK_END = 1;
#Override
public void onClick(View v) {
Log.i(MainActivity, "view clicked");
int id = v.getId();
if (id == R.id.searchR) {
//do nothing
} else if (id == R.id.startSearch) {
Intent startIntent = new Intent(this, SList.class);
startActivityForResult(startIntent, PICK_START);
} else if (id == R.id.endSearch) {
Intent startIntent = new Intent(this, SList.class);
startActivityForResult(startIntent, PICK_END);
}
}
When the above onClick method gets called and after that its starts another activity SList.class.In that I have a listview from which user can select the value and upon selecting value the result will be set and activity will finish itself.Code for this is:
sListview.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Station selectedS = sArray.get(position);
Intent returnIntent = new Intent();
returnIntent.putExtra("_id", selectedS.getId());
returnIntent.putExtra("name", selectedS.getName());
setResult(RESULT_OK, returnIntent);
finish();
}
});
In above code activity sets the result and finishes itself.Till here everything is working accordingly.But after that when the previous activity is started, the onActivityResult() method nevers gets called.The code for onActivityResult() is :
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i(MainActivity, "" + requestCode);
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// Check which request we're responding to
if (requestCode == PICK_START) {
//data.getStringExtra("_id");
Log.i(MainActivity, data.getStringExtra("name"));
} else if (requestCode == PICK_END) {
Log.i(MainActivity, data.getStringExtra("name"));
}
}
}
I dont know why onActivityResult is never triggered .Someone even
wrote on his blog that There is bug in android API. In
startActivityForResult(intent, requestCode); This function does work
as long as requestCode = 0. However, if you change the request code to
anything other than zero, the ApiDemos will fail (and onActivityResult()
won't be called).
I found the solution to my problem.I just needed to restart my eclipse and my code started working.