我正在为公司开发内部应用程序。使用Android Studio 2.2.3作为开发环境,使用AVD模拟器和Android 6.0虚拟设备进行测试。
我们有一个Web应用程序,用于创建销售发票。Android应用程序基本上需要接收发票号码,然后从Web服务读取发票数据,并打印到蓝牙打印机上。
因此,我在我的Web应用程序中尝试了这两个链接:
我们有一个Web应用程序,用于创建销售发票。Android应用程序基本上需要接收发票号码,然后从Web服务读取发票数据,并打印到蓝牙打印机上。
因此,我在我的Web应用程序中尝试了这两个链接:
<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默认的Web浏览器中都适用?如果没有,我需要至少能在Chrome中使用。