深层链接打开应用程序的问题

问题描述 投票:0回答:1

我制作了这个应用程序,当用户单击链接时就会打开。

如果我在 Whatsapp 上分享链接,会发生的事情是我的应用程序开始在 Whatsapp 进程上运行。这怎么可能?我还附上了正在发生的事情的屏幕截图,以便更好地解释我:

正如您通过此图片所看到的,我的应用程序在屏幕左侧运行,但我也有 Whatsapp 进程显示我的应用程序需要显示的内容。

我没有太多代码要展示,但我会尝试将最重要的部分粘贴在这里:

链接重定向用户的活动:

 import androidx.annotation.RequiresApi;
 import androidx.appcompat.app.AppCompatActivity;

 import android.annotation.SuppressLint;
 import android.content.Intent;
 import android.content.res.ColorStateList;
 import android.graphics.Color;
 import android.graphics.PorterDuff;
 import android.media.MediaPlayer;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.text.SpannableString;
 import android.util.Log;
 import android.view.MotionEvent;
 import android.view.View;
 import android.widget.Button;
 import android.widget.TableLayout;
 import android.widget.TableRow;
 import android.widget.TextView;

 import com.github.nkzawa.emitter.Emitter;
 import com.github.nkzawa.socketio.client.IO;
 import com.github.nkzawa.socketio.client.Socket;

 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;

 import java.io.IOException;
 import java.io.StringReader;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;

 import okhttp3.Call;
 import okhttp3.Callback;
 import okhttp3.OkHttpClient;
 import okhttp3.Request;
 import okhttp3.Response;

public class activity_multigiocatore_online_stanza extends AppCompatActivity {

private Socket mSocket;

{
    try {
        mSocket = IO.socket("https://limitless-castle-77413.herokuapp.com/");
    } catch (URISyntaxException e) {
    }
}

MyDBHandler myDBHandler;
static int suono = -1;
static int vibrazione = -1;
static int biancoNero = -1;
static int colore = -1;
MediaPlayer suono_bottone;
View activityView;
static TextView tx_idStanza;
TableLayout tableLayout_giocatori;
static String name;
static String idStanza;
static String idGiocatore;
static boolean primo = false;
Button btn_left_diff;
Button btn_right_diff;
Button btn_left_tempo;
Button btn_right_tempo;
TextView tx_diff;
TextView tx_tempo;
static  TextView tx_info;
static Button btn_inizia;
Button btn_share;
static TableLayout tb1;
static boolean amministratore = false;
@SuppressLint("ClickableViewAccessibility")
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_multigiocatore_online_stanza);
    mSocket.connect();
    Intent intent = new Intent(this, ExitService.class);
    startService(intent);
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    myDBHandler = new MyDBHandler(this, null, null, 1);
    suono_bottone = MediaPlayer.create(this, R.raw.sound_general);
    String impostazioni = myDBHandler.getSettings();
    String[] sett = impostazioni.split("-");
    suono = Integer.parseInt(sett[0]);
    vibrazione = Integer.parseInt(sett[1]);
    biancoNero = Integer.parseInt(sett[2]);
    colore = Integer.parseInt(sett[3]);

    tx_info = findViewById(R.id.tx_info);
    tb1 = findViewById(R.id.tableLayout3);
    activityView = findViewById(R.id.activity);
    tx_idStanza = findViewById(R.id.tx_idStanza);
    tableLayout_giocatori = findViewById(R.id.table_giocatori);
    btn_share = findViewById(R.id.btn_condividi);
    btn_left_diff = findViewById(R.id.btn_arrow_left_difficolta);
    btn_left_tempo = findViewById(R.id.btn_arrow_left_tempo);
    btn_right_tempo = findViewById(R.id.btn_arrow_right_tempo);
    btn_right_diff = findViewById(R.id.btn_arrow_right_difficolta);
    tx_diff = findViewById(R.id.tx_difficolta);
    tx_tempo = findViewById(R.id.tx_tempo);
    btn_inizia = findViewById(R.id.btn_inizia);
    ShowDialog.setButton(biancoNero, colore, btn_inizia);
    ShowDialog.setButton(biancoNero, colore, btn_share);

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        amministratore = bundle.getBoolean("amm");
        idStanza = "";
    }
    try {
        Intent appLinkIntent = getIntent();
        String appLinkAction = appLinkIntent.getAction();
        Uri appLinkData = appLinkIntent.getData();
        String[] link = appLinkData.toString().split("/");
        idStanza = (link[3]);
        Intent intent1 = new Intent(this, ExitService.class);
        startService(intent1);
    }catch (Exception e){Log.d("msg",e.getMessage());}

    ShowDialog.show_dialog_stanzamenu_multiOnline(activity_multigiocatore_online_stanza.this, biancoNero, colore, suono, amministratore, idStanza);

    switch (colore) {
        case 1:
            ShowDialog.colorBlue(biancoNero, tableLayout_giocatori);
            break;
        case 2:
            ShowDialog.colorRed(biancoNero, tableLayout_giocatori);
            break;
        case 3:
            ShowDialog.colorGreen(biancoNero, tableLayout_giocatori);
            break;
        case 4:
            ShowDialog.colorOrange(biancoNero, tableLayout_giocatori);
            break;
    }
    if (biancoNero == 1) {
        activityView.setBackgroundColor(getResources().getColor(R.color.Black));
        tx_idStanza.setTextColor(Color.WHITE);
        tx_tempo.setTextColor(Color.WHITE);
        tx_diff.setTextColor(Color.WHITE);
        btn_inizia.setTextColor(Color.WHITE);
        btn_share.setTextColor(Color.WHITE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            btn_left_diff.setForegroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Azure)));
            btn_left_tempo.setForegroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Azure)));
            btn_right_diff.setForegroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Azure)));
            btn_right_tempo.setForegroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Azure)));
            btn_share.setTextColor(Color.WHITE);
        }
    } else {
        activityView.setBackgroundColor(Color.WHITE);
        tx_idStanza.setTextColor(Color.BLACK);
        tx_tempo.setTextColor(Color.BLACK);
        tx_diff.setTextColor(Color.BLACK);
        btn_inizia.setTextColor(Color.BLACK);
        btn_share.setTextColor(Color.BLACK);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            btn_left_diff.setForegroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Black)));
            btn_left_tempo.setForegroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Black)));
            btn_right_diff.setForegroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Black)));
            btn_right_tempo.setForegroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Black)));
            btn_share.setForegroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Black)));
        }
    }

    setListening();

    btn_share.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN: {
                    Button view = (Button) v;
                    switch (colore) {
                        case 1:
                            view.getBackground().setColorFilter(getResources().getColor(R.color.CobaltBlue), PorterDuff.Mode.SRC_ATOP);
                            break;
                        case 2:
                            view.getBackground().setColorFilter(getResources().getColor(R.color.Cranberry), PorterDuff.Mode.SRC_ATOP);
                            break;
                        case 3:
                            view.getBackground().setColorFilter(getResources().getColor(R.color.JungleGreen), PorterDuff.Mode.SRC_ATOP);
                            break;
                        case 4:
                            view.getBackground().setColorFilter(getResources().getColor(R.color.PapayaOrange), PorterDuff.Mode.SRC_ATOP);
                            break;
                    }
                    btn_share.setTextColor(Color.WHITE);
                    v.invalidate();
                    break;
                }
                case MotionEvent.ACTION_UP:
                    if (suono == 1) {
                        suono_bottone.start();
                    }
                    Intent myIntent = new Intent(Intent.ACTION_SEND);
                    myIntent.setType("text/plain");
                    String body = "Ehi stupido coglione, schiaccia la mosca sul link, entra nella mia stanza e scaccoliamoci insime \nhttps://limitless-castle-77413.herokuapp.com/" + tx_idStanza.getText().toString();
                    String sub = "Codice partita";
                    myIntent.putExtra(Intent.EXTRA_SUBJECT, sub);
                    myIntent.putExtra(Intent.EXTRA_TEXT, body);
                    startActivity(Intent.createChooser(myIntent, "Condividi con..."));
                case MotionEvent.ACTION_CANCEL: {
                    if (biancoNero == 2) {
                        btn_share.setTextColor(Color.BLACK);
                    }
                    Button view = (Button) v;
                    view.getBackground().clearColorFilter();
                    view.invalidate();
                    break;
                }
            }
            return true;
        }
    });
    btn_inizia.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN: {
                    Button view = (Button) v;
                    switch (colore) {
                        case 1:
                            view.getBackground().setColorFilter(getResources().getColor(R.color.CobaltBlue), PorterDuff.Mode.SRC_ATOP);
                            break;
                        case 2:
                            view.getBackground().setColorFilter(getResources().getColor(R.color.Cranberry), PorterDuff.Mode.SRC_ATOP);
                            break;
                        case 3:
                            view.getBackground().setColorFilter(getResources().getColor(R.color.JungleGreen), PorterDuff.Mode.SRC_ATOP);
                            break;
                        case 4:
                            view.getBackground().setColorFilter(getResources().getColor(R.color.PapayaOrange), PorterDuff.Mode.SRC_ATOP);
                            break;
                    }
                    btn_inizia.setTextColor(Color.WHITE);
                    v.invalidate();
                    break;
                }
                case MotionEvent.ACTION_UP:
                    if (suono == 1) {
                        suono_bottone.start();
                    }

                case MotionEvent.ACTION_CANCEL: {
                    if (biancoNero == 2) {
                        btn_inizia.setTextColor(Color.BLACK);
                    }
                    Button view = (Button) v;
                    view.getBackground().clearColorFilter();
                    view.invalidate();
                    break;
                }
            }
            return true;
        }
    });

}

我还粘贴了清单代码:

<activity
        android:name=".activity_multigiocatore_online_stanza"
        android:screenOrientation="portrait">
        <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="https"
                android:host="limitless-castle-77413.herokuapp.com" />
        </intent-filter>
</activity>

我该如何解决这个问题?

android android-studio deep-linking
1个回答
0
投票

谁还在寻找答案,这就是你如何解决它:

只需在

AndroidManifest.xml
中添加 android:launchMode="singleTask",这样它始终会单独打开您的应用程序。

 <!-- Deep & App Link -->
 <intent-filter android:autoVerify="true">
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
     <category android:name="android.intent.category.BROWSABLE" />
     <data android:scheme="http" android:host="google.in" />
     <data android:scheme="https" android:host="google.in" />
 </intent-filter>
© www.soinside.com 2019 - 2024. All rights reserved.