目前我想知道是否可以动态提取数据以获得意图。我知道我们可以像这样提取价值观和类别:
String barcode = intent.getStringExtra("barcode");
但是,我正在构建的应用程序可以传递不同的意图。第一个例子可能是:
barcode =“1234”applicationNo =“XYZXX”
第二个例子可能是:
reg =“BG12 YOA”color =“blue”
有没有办法动态提取信息?我尝试过以下但没有运气:
TreeMap<String, String> data = new TreeMap<String, String>();
System.out.println("we hit herefas " + this.getIntent());
Object[] catagories = this.getIntent().getCategories().toArray();
for(Object catagory: catagories) {
data.put(catagory.toString(), this.getIntent().getStringExtra(catagory.toString()));
}
编辑:数据从javascript传递到Android应用程序。它运行以下命令(作为示例):
./adb shell am start -a android.intent.action.VIEW -d "https://print.xxx.cloud?barcode=ABCDEFG"
答案 0 :(得分:1)
You appear to be creating ACTION_VIEW
Intents
with a Uri
like https://print.xxx.cloud?barcode=ABCDEFG
. If so, call getData()
on the Intent
to get the Uri
, and call methods like getQueryParameterNames()
to get the names of the query parameters on that Uri
.