Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate with UniSat app #56

Open
cloud6605 opened this issue Jul 12, 2024 · 7 comments
Open

integrate with UniSat app #56

cloud6605 opened this issue Jul 12, 2024 · 7 comments

Comments

@cloud6605
Copy link
Collaborator

image
image
image

@cloud6605
Copy link
Collaborator Author

image

@cloud6605
Copy link
Collaborator Author

image

@cloud6605
Copy link
Collaborator Author

image

@GainLee
Copy link

GainLee commented Aug 7, 2024

I've written an app to simulate UniSat app's behavior, let's call it AppB. AppB's configuration is defined as follows:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="unisat" android:host="request" />
</intent-filter>

After receiving the intent, it returns:

private fun sendResultBackToAppA(result: String) {
    // val intent = Intent(Intent.ACTION_VIEW, Uri.parse("testapp://response?result=$result"))
    val intent = Intent(Intent.ACTION_VIEW, Uri.parse("testapp://response?error=InRlc3RlcnJvciI=&nonce=1234"))
    startActivity(intent)
}

My AppA can receive this, but when I choose the UniSat app, there's no response.

The configuration for my AppA is as follows:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Configure custom protocol and path -->
    <data android:scheme="testapp" android:host="response" />
</intent-filter>

The code for sending the intent is as follows:

var nonce = System.currentTimeMillis()
var uri = Uri.parse("unisat://request?method=connect&from=testapp&nonce=${nonce}")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivityLauncher.launch(intent)

@abangZ
Copy link
Collaborator

abangZ commented Aug 8, 2024

I write a test code, it's worked. hope those can help you:

create ResponseActivity.java

package io.unisat.connecttest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

public class ResponseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_response);

        Intent intent = getIntent();
        if (intent != null) {
            onNewIntent(intent); 
        }
    }


    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Uri dataUri = intent.getData();
        if (dataUri != null) {
            TextView textView = findViewById(R.id.textView);
            textView.setText(dataUri.toString());
        }

    }
}

create activity_response.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ResponseActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        tools:layout_editor_absoluteX="175dp"
        tools:layout_editor_absoluteY="336dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

update AndroidManifest.xml

<activity
            android:name=".ResponseActivity"
            android:autoVerify="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="testuu" android:host="response" />
            </intent-filter>
            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
</activity>

and the onClick method for one button

public void onClick(View view) {
                // create intent
                Intent intent = new Intent(Intent.ACTION_VIEW);
                // set URI
                String deepLinkUri = "unisat://request?method=connect&from=testuu&nonce=xxxxx123";
                intent.setData(Uri.parse(deepLinkUri));

                // start
                try {
                    startActivity(intent);
                } catch (Exception e) {
                    Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
                }
}

@Goose0x01
Copy link

Thanks for your rep

I write a test code, it's worked. hope those can help you:我写了一个测试代码,它成功了。希望这些可以帮助你:

create ResponseActivity.java创建ResponseActivity.java

package io.unisat.connecttest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

public class ResponseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_response);

        Intent intent = getIntent();
        if (intent != null) {
            onNewIntent(intent); 
        }
    }


    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Uri dataUri = intent.getData();
        if (dataUri != null) {
            TextView textView = findViewById(R.id.textView);
            textView.setText(dataUri.toString());
        }

    }
}

create activity_response.xml创建activity_response.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ResponseActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        tools:layout_editor_absoluteX="175dp"
        tools:layout_editor_absoluteY="336dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

update AndroidManifest.xml更新AndroidManifest.xml

<activity
            android:name=".ResponseActivity"
            android:autoVerify="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="testuu" android:host="response" />
            </intent-filter>
            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
</activity>

and the onClick method for one button以及一个按钮的 onClick 方法

public void onClick(View view) {
                // create intent
                Intent intent = new Intent(Intent.ACTION_VIEW);
                // set URI
                String deepLinkUri = "unisat://request?method=connect&from=testuu&nonce=xxxxx123";
                intent.setData(Uri.parse(deepLinkUri));

                // start
                try {
                    startActivity(intent);
                } catch (Exception e) {
                    Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
                }
}

Thank you for your reply. I looked over your code and it’s similar to mine, so I’ll give it a try. My local Unisat app version is 0.2.7, and I noticed the latest version is 0.2.12, so I’ll upgrade to the new one and see how it goes.

@GainLee
Copy link

GainLee commented Aug 9, 2024

After upgrading to v0.2.15, it works well now, thanks for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants