Content shared using dynamic link not getting displayed as same as it was shared after opening it

夙愿已清 提交于 2019-12-02 08:14:12

问题


I'm developing an android app. Some data is getting retrieved from the FirebaseDatabase and is getting shown in a RecyclerView in my app.

The RecyclerView has cards in it. In every card, the images and text is shown. On the card there is a 'share' button, by clicking on which a dynamic-link is generated and is getting shared with anybody. When I click on the shared dynamic-link, the app gets open and what happens is that the image which was on the same card the share button was clicked is getting displayed, but the text is always getting displayed of the last saved data. I hope you got my point.

Here's how I'm generating dynamic-link:

        Button btnShare = (Button) holder.itemView.findViewById(R.id.btn_share);
        btnShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Uri BASE_URL = Uri.parse("http://www.appwebsite.com/");
                holder.APP_URI = BASE_URL.buildUpon().path(imageUIDh).build();

                packageName = holder.itemView.getContext().getPackageName();

                deepLinkTS = Uri.parse("https://u9p25.app.goo.gl/?link="+holder.APP_URI+"&apn="+packageName+"&amv="+16+"&ad="+0);

                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_TEXT, "Please help this needy: " + deepLinkTS.toString() + "\n-shared through app.");

                holder.itemView.getContext().startActivity(Intent.createChooser(intent, "Share via..."));

            }
        });

Here's how I'm handling dynamic-link in onCreate() method of MainActivity.class:

boolean autoLaunchDeepLink = false;
        AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, MainActivity.this, autoLaunchDeepLink)
                .setResultCallback(
                        new ResultCallback<AppInviteInvitationResult>() {
                            @Override
                            public void onResult(@NonNull AppInviteInvitationResult result) {
                                if (result.getStatus().isSuccess()) {
                                    // Extract deep link from Intent
                                    Intent intent = result.getInvitationIntent();
                                    final String deepLink = AppInviteReferral.getDeepLink(intent);

                                    // Handle the deep link. For example, open the linked
                                    // content, or apply promotional credit to the user's
                                    // account.

                                    final ProgressDialog openingSharedRequest = new ProgressDialog(MainActivity.this);
                                    openingSharedRequest.setMessage("Opening shared help-request...");
                                    openingSharedRequest.show();

                                    Handler handler = new Handler();
                                    handler.postDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            Intent helpRequestIntent = new Intent(MainActivity.this, HelpRequestThroughDeepLink.class);
                                            helpRequestIntent.putExtra("deepLink", deepLink);
//                                            helpRequestIntent.putExtra("deepLinkTS", HelpRequest.deepLinkTS.toString());
//                                    helpRequestIntent.putExtra("APP_URI", HelpRequest.ViewHolder.APP_URI.toString());
                                            helpRequestIntent.putExtra("postedFrom", postedFromS);
//                                    new AlertDialog.Builder(MainActivity.this)
//                                            .setMessage(deepLink)
//                                            .setPositiveButton("OK", null)
//                                            .create()
//                                            .show();
                                            startActivity(helpRequestIntent);
                                            openingSharedRequest.dismiss();
                                        }
                                    }, 1200);

                                    // [START_EXCLUDE]
                                    // Display deep link in the UI
//                                        ((TextView) findViewById(R.id.link_view_receive)).setText(deepLink);
                                    // [END_EXCLUDE]
                                } else {
//                                        Log.d(TAG, "getInvitation: no deep link found.");
//                                    Toast.makeText(getBaseContext(), "Some error occurred", Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
        // [END get_deep_link]

Here's code from HelpRequestThroughDeepLink.java:

public class HelpRequestThroughDeepLink extends AppCompatActivity {

    String deepLink, deepLinkTS, APP_URI, imageUID, imageUIDFD, hDescription;
    Button btn_accept, btn_reject;
    ImageView hImageHDL;
    TextView imageUIDHDL, hDescriptionHDL;
    DatabaseReference databaseReference1, databaseReferenceUsers;
    MapView mapView;
    ProgressBar progressBar;
    CoordinatorLayout coordinatorLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help_request_through_deep_link);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        coordinatorLayout = (CoordinatorLayout) findViewById(R.id.myCoordinatorLayout);

        databaseReference1 = FirebaseDatabase.getInstance().getReferenceFromUrl("https://humanehelper-e8a22.firebaseio.com/");
        databaseReferenceUsers = FirebaseDatabase.getInstance().getReferenceFromUrl("https://humanehelper-e8a22.firebaseio.com/users");

        if (getIntent().getExtras() != null) {
            deepLink = getIntent().getExtras().getString("deepLink");
            deepLinkTS = getIntent().getExtras().getString("deepLinkTS");
            APP_URI = getIntent().getExtras().getString("APP_URI");
            postedFrom = getIntent().getExtras().getString("postedFrom");
            String imageUIDD = deepLink.substring(28);
            try {
                imageUID = URLDecoder.decode(imageUIDD, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            if (isNetworkAvailable()) {
                operateDeepLinkRequest();
            } else {
                Snackbar.make(findViewById(R.id.myCoordinatorLayout), "No internet connection!", Snackbar.LENGTH_LONG)
                        .setAction("RETRY", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                ifNetworkAvailable();
                            }
                        })
                        .setDuration(Snackbar.LENGTH_INDEFINITE)
                        .show();
            }

        } else {
            Toast.makeText(getBaseContext(), "Some error occurred", Toast.LENGTH_SHORT).show();
        }

        hImageHDL = (ImageView) findViewById(R.id.hImageHDL);
        imageUIDHDL = (TextView) findViewById(R.id.imageUIDHDL);
        hDescriptionHDL = (TextView) findViewById(R.id.homelessDescriptionHDL);

        btn_accept = (Button) findViewById(R.id.btn_accept);
        btn_reject = (Button) findViewById(R.id.btn_reject);
        progressBar = (ProgressBar) findViewById(R.id.progressBar_loading_image);

    }

    public void operateDeepLinkRequest() {
        if (deepLink.contains(imageUID)) {
            if ((imageUID.startsWith("https://firebasestorage.googleapis.com/") || imageUID.startsWith("content://"))) {

                retrieveRespectiveRequest();

            }
        }
    }

    public void retrieveRespectiveRequest() {
        databaseReference1.child("help-requests").addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                Map<String, String> newRequest = (Map<String, String>) dataSnapshot.getValue();
                imageUIDFD = newRequest.get("imageUIDh");
                hDescription = newRequest.get("hDescription");

                progressBar.setVisibility(View.VISIBLE);

                    imageUIDHDL.setText(imageUID);
                    doSomethingWithPicaso(imageUID, hImageHDL);
                    hDescriptionHDL.setText(hDescription);

            }

            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {

            }

            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {

            }

            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

        databaseReference1.child("help-requests").addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

    }

    private void doSomethingWithPicaso(String imageUIDh, ImageView target){
//        Picasso.with(itemView.getContext()).cancelRequest(homelessImage);
        Picasso.with(getBaseContext())
                .load(imageUIDh)
                .error(R.drawable.ic_warning_black_24dp)
                .into(target, new Callback() {
                    @Override
                    public void onSuccess() {
                        progressBar.setVisibility(View.INVISIBLE);
                    }

                    @Override
                    public void onError() {
                        Toast.makeText(getBaseContext(), "Error occurred while loading images. Please retry.", Toast.LENGTH_SHORT).show();
                        progressBar.setVisibility(View.INVISIBLE);
                    }
                });
    }

    private boolean isNetworkAvailable() {
        ConnectivityManager connectivityManager
                = (ConnectivityManager) HelpRequestThroughDeepLink.this.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }

    public void ifNetworkAvailable(){
        if (isNetworkAvailable()) {
            operateDeepLinkRequest();
        } else {
            Snackbar.make(findViewById(R.id.myCoordinatorLayout), "No internet connection!", Snackbar.LENGTH_LONG)
                    .setAction("RETRY", new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            ifNetworkAvailable();
                        }
                    })
                    .setDuration(Snackbar.LENGTH_INDEFINITE)
                    .show();
        }
    }

}

Please let me know how can I achieve this?

来源:https://stackoverflow.com/questions/38171064/content-shared-using-dynamic-link-not-getting-displayed-as-same-as-it-was-shared

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!