Ich habe 2 Apps, A & B. In App A, ich öffne eine Aktivität von App B mit Deep Link und über startActivityForResult()
, aber wenn Set Ergebniscode in App B und zurück, App A hat gerade RESULT_CANCELED
erhalten! Meine erste Frage ist "Ist es möglich, das Ergebnis zurückzugeben, wenn Deep Link benutzt wird, um eine andere App zu öffnen?", Und wenn ja, wo ist mein Fehler ?!Ergebnis zurückgeben, wenn Deep Link zum Öffnen einer anderen App verwendet wird
Mein Manifest, in App B:
<activity android:name=".activity.TargetActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<!-- note that the leading "/" is required for pathPrefix-->
<data
android:host="www.example.com"
android:pathPrefix="/gizmos"
android:scheme="http" />
<data
android:host="www.example.com"
android:pathPrefix="/gizmos"
android:scheme="https" />
<data
android:host="example.com"
android:pathPrefix="/gizmos"
android:scheme="http" />
<data
android:host="example.com"
android:pathPrefix="/gizmos"
android:scheme="https" />
</intent-filter>
</activity>
In App A:
Uri webpage = Uri.parse("android-app://com.vancosys.payment/http/www.example.com/gizmos?name=FMarket&id=4231");
Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
// Verify it resolves
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(webIntent, 0);
boolean isIntentSafe = activities.size() > 0;
// Start an activity if it's safe
if (isIntentSafe)
{
// '4231' is my request code
startActivityForResult(webIntent, 4231);
}
auch:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == 4231)
{
if (resultCode == RESULT_OK)
{
String id = data.getStringExtra("ID");
Intent i = new Intent(this, ResultActivity.class);
i.putExtra("RESULT", true);
i.putExtra("ID", id);
startActivity(i);
}
else
{
// It JUST equals to RESULT_CANCELED!!!
Intent i = new Intent(this, ResultActivity.class);
i.putExtra("result", false);
startActivity(i);
}
}
}
Und schließlich in App B:
new Handler().postDelayed(new Runnable()
{
public void run()
{
Intent i = new Intent();
TargetActivity.this.setResult(RESULT_OK, i);
i.putExtra("ID", "45651232");
finish();
}
}, 3000);
UPDATE: Intent data
in onActivityResult()
ist null
!!!
Nope! Nicht funktioniert. Returned Intent ist null und Ergebniscode ist RESULT_CANCELED noch ... – YUSMLE
Überprüfen Sie, ob dieser Handler aufgerufen wird ... Überprüfen Sie nach Möglichkeiten, wo die App B geschlossen werden kann, ohne das Ergebnis –