I have this app:
import android.R.drawable;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String b64encoded = null;
Intent intent = getIntent();
Uri data = intent.getData();
b64encoded = data.getEncodedSchemeSpecificPart();
if (b64encoded != null) {
if (data.getScheme() == "cqrsa") {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Authentication");
builder.setMessage("Clicked: " + b64encoded);
builder.setCancelable(false);
builder.setIcon(drawable.ic_lock_lock);
builder.setNeutralButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
android.os.Process.killProcess(android.os.Process.myPid());
}
});
AlertDialog alert = builder.create();
alert.show();
}
if (data.getScheme() == "sqrsa") {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Authentication");
builder.setMessage("Scanned: " + b64encoded);
builder.setCancelable(false);
builder.setIcon(drawable.ic_lock_lock);
builder.setNeutralButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
android.os.Process.killProcess(android.os.Process.myPid());
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
else
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Authentication");
builder.setMessage("No data was supplied");
builder.setCancelable(false);
builder.setIcon(drawable.ic_dialog_alert);
builder.setNeutralButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
android.os.Process.killProcess(android.os.Process.myPid());
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
@Override
public void onDestroy() {
super.onDestroy();
android.os.Process.killProcess(android.os.Process.myPid());
}
}
and then I defined the intent in AndroidManifest as:
<activity android:name="eu.sebbe.www.qrsaauthentication.MainActivity" android:label="AuthTestLabel">
<intent-filter>
<data android:scheme="cqrsa" />
<data android:scheme="sqrsa" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
However, when testing the application, the Intent catcher only hangs and show the screen "AuthTestLabel".
It seems like MainActivity doesn't get executed at all. What Im doing wrong?
I created a blank Android Project (without any Interface) since this app should only calculate a one time password and show it onscreen in a dialog box (or put it in clipboard) depending on if the app was called from a clicked link or a scanned QR code. (this is why I define 2 urlhandlers, sqrsa and cqrsa)
What is the problem with the app?
You are comparing the String with ==
operator in the if statement,in that condition may return false
you need to compare the string with equals()
like change this data.getScheme() == "sqrsa"
with (data.getScheme().equals ("sqrsa"))