Open cloud6605 opened 2 months ago
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)
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();
}
}
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.
After upgrading to v0.2.15, it works well now, thanks for your help