Communication between Chrome and Android Device

253 Views Asked by At

Hi guys I'm try to send string from Chrome app to another app following documentation but without result.

My page opened on Chrome app:

<!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>

My activity

@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");
    }
}

And manifest

<?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>

When I click in browser, load something but never load app. Do you have any ideas?

0

There are 0 best solutions below