android - Chrome 和 Android 设备之间的通信
问题描述
大家好,我正在尝试按照文档将字符串从 Chrome 应用程序发送到另一个应用程序,但没有结果。
我的页面在 Chrome 应用程序上打开:
<!DOCTYPE html>
<html>
<body>
<p>URL: <a
href="intent://#Intent;scheme=printer_receiver;package=
kangel.com.printerhandler;S.name=Andrea;i.age=35;end">Do action</a></p>
</body>
</html>
我的活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mText = findViewById(R.id.textUploaded);
//TRY ONE
Uri data = this.getIntent().getData();
if (data != null && data.isHierarchical()) {
String uri = this.getIntent().getDataString();
Log.i("PrinterHandler", "Deep link clicked " + uri);
mText.setText(uri);
}
//TRY TWO
Bundle extras = getIntent().getExtras();
if (extras != null){
String name = extras.getString("name");
Integer age = extras.getInt("age");
if (name!=null && age!=null) {
mText.setText(name);
}
}else{
mText.setText("No Data");
}
}
并体现
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kangel.com.printerhandler">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<data android:scheme="printer_receiver" />
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
当我在浏览器中单击时,加载一些东西但从不加载应用程序。你有什么想法?
解决方案
推荐阅读
- python-3.x - 计算 Histogram2d 箱中的均值和标准偏差
- oracle - 查找“虚拟”外键
- python-3.x - 如何最大化python效率?
- install4j - 如何在 install4j 中选择文件
- scala - 如何在scalafmt中将lambda参数保持在同一行
- javascript - 覆盖@angular/pwa ngsw-worker.js
- swift - 数据仅一次附加到我的 tableView 和我的 Firebase 数据库
- javascript - 如何修复“未定义不是对象(评估'this.props.navigation')”
- reactjs - Formik FieldArray 验证未验证
- react-native - 如何在多个设备的 react-native 中找出内容的正确左右边距?