我有这个应用程序:
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());
}
}
然后我将 AndroidManifest 中的意图定义为:
<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>
但是,在测试应用程序时,Intent 捕捉器只会挂起并显示屏幕“AuthTestLabel”。
似乎 MainActivity 根本没有执行。我做错了什么?
我创建了一个空白的 Android 项目(没有任何界面),因为这个应用程序应该只计算一次密码并在对话框中(或将其放在剪贴板中)显示在屏幕上,具体取决于应用程序是从单击的链接调用的还是扫描的二维码。(这就是为什么我定义了 2 个 urlhandlers,sqrsa 和 cqrsa)
应用程序有什么问题?