【发布时间】:2017-01-07 16:58:19
【问题描述】:
我正在为我的公司开发一个内部应用程序。使用 Android Studio 2.2.3 作为开发环境,AVD Emulator 与 Android 6.0 虚拟设备进行测试。
我们有一个用于创建销售发票的 Web 应用程序。 Android App 基本上需要接收一个 Invoice 号,然后从 Web Service 读取 Invoice 数据,然后打印到蓝牙打印机。
所以基本上,我已经在我的网络应用程序中尝试了这 2 个链接:
<a href="company.printapp://INVOICE/1621696">PRINT INVOICE</a></div>
<a href="intent://INVOICE/1621696/#Intent;scheme=company.printapp;end">PRINT INVOICE</a>
两者都在浏览器中抛出相同的错误(在模拟器中测试):
net:ERR_UNKNOWN_URL_SCHEME
我的清单文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="company.printapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="company.printapp" />
<action android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java:
package company.printapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.List;
import android.net.Uri;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Uri data = getIntent().getData();
String scheme = data.getScheme();
String host = data.getHost();
List<String> params = data.getPathSegments();
String first = params.get(0); // "document type"
String second = params.get(1); // "document No"
BluetoothPrint(first,second);
}
}
是否有适用于 Chrome 和 Android 的默认网络浏览器的解决方案?如果没有,我需要它至少可以与 Chrome 一起使用。
【问题讨论】:
-
这也是另一种方式,我希望它适用于所有网络浏览器...stackoverflow.com/questions/13042278/…