大家好,我正在尝试根据文档将字符串从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>
当我在浏览器中单击时,加载某些内容但从不加载应用程序。 你有什么想法吗?