0

This is the link which i created to share an url of a particular product in java class

   String url="http://www.example.com/productId/";
                            String finalurl = url + productId.getText().toString();
                            Intent i = new Intent(Intent.ACTION_SEND);
                            i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            i.setType("*/*");
                            i.putExtra(Intent.EXTRA_STREAM, getLocalBitmapUri(bitmap));
                            i.putExtra(Intent.EXTRA_TEXT, name.getText().toString()+ "\n" + finalurl);
                            startActivity(Intent.createChooser(i, "Share Image"));

this is the intent filter that has created to an activity through App links Assistant

  <activity
        android:name=".login.Launchscreen"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <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:host="www.example.com"
                android:pathPrefix="/productId"
                android:scheme="http" />
        </intent-filter>

        <tools:validation testUrl="http://www.example.com/productId/" />
    </activity>

this is the java code through which i can extract the data which i appended to my link

  Intent intent = getIntent();
                    String appLinkAction = intent.getAction();
                    Uri appLinkData = intent.getData();
                    if (Intent.ACTION_VIEW.equals(appLinkAction) && appLinkData != null) {
                        proid = appLinkData.getLastPathSegment();
                    }


  through above code i can share url through whatsapp and when i click on the shared app link it is redirecting to my app successfully but what i need is i want to redirect the user to play store when my application is not in his device and when the application is in his device he should be navigated to particular activity. can anyone help me please.All i want is in android app.Thanks in advance
Swapna
  • 127
  • 1
  • 10

2 Answers2

0

You can check whether app is installed or not using package manager

final boolean isAppInstalled = appInstalledOrNot(\\ your URL package name\\);

private boolean appInstalledOrNot(String packagname) {
    PackageManager pm = getActivity().getPackageManager();
    try {
        pm.getPackageInfo(packagname, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {

        return false;
    }
}

// now check on your button click

if (isAppInstalled) 
{          
    Intent LaunchIntent = getContext().getPackageManager().getLaunchIntentForPackage(\\ your URL package name\\);
    getContext().startActivity(LaunchIntent);
} else {
    try {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(\\your URL\\));

    } catch (android.content.ActivityNotFoundException anfe) {

        anfe.printStackTrace();
    }
}
Mahendra Gohil
  • 380
  • 1
  • 3
  • 21
SAVALIYA REENA
  • 218
  • 2
  • 15
0

you can use branch.io for create deep link and check app is not install go
to play store.

 https://branch.io/how-branch-links-work/

step 1: Above link sign up 
step 2: open branch dashboard
step 3. select Set Up SDK then open new page that page select your device
step 4: if you select android open new page that page contain this option 
      follow this              
        1.Enter app information
        2.Get the SDK files
        3.Configure Manifest
        4.Start a Branch session

step 5: come back to dashboard see first option LIVE and TEST
        1.you click live then select Account Setting see live key
        2.you click test then select Account Setting see test key

       <meta-data
        android:name="io.branch.sdk.BranchKey"
        android:value="put live key" />
       <meta-data
        android:name="io.branch.sdk.BranchKey.test"
        android:value="put test key" />

    if use test key for testing perpose, if you go to live set false
       <meta-data
        android:name="io.branch.sdk.TestMode"
        android:value="true" />


step 6: go to link setting 

       1.see android 
           1.select two check box one I have an Android App and Enable app link

       2.see Android URI Scheme enter your uri for if you install the app 
         you click the deep link open the app.

         (example:appName://open)

       3.see google play search for if you not install the app then redirect to     
         google play store 
           1.first you upload app to play store then search and set

       4.set SHA256 Cert Fingerprints

       5.see link domain option 
           1.use Default Link Domain link

    <activity
        android:name=".MainActivity"
        android:alwaysRetainTaskState="true"
        android:configChanges="orientation"
        android:hardwareAccelerated="true"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:theme="@style/MyAppTheme">

        <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:host="open"
                android:scheme="set your android Scheme uri" />
            <data
                android:host="Default Link Domain link"
                android:pathPrefix="/"
                android:scheme="https" />
        </intent-filter>
    </activity>



 step 7: click deep link handle on MainAtivity 

     public void onStart() {
super.onStart();
    Branch branch = Branch.getInstance();

   // Branch init
    branch.initSession(new Branch.BranchReferralInitListener() {
       @Override
     public void onInitFinished(JSONObject referringParams, BranchError error) {
        if (error == null) {
            if(referringParams.has("post_id")){
             mPostId = referringParams.getString("post_id");
          }
        } else {
            Log.i("BRANCH SDK", error.getMessage());
        }
    }
 }, this.getIntent().getData(), this);
}

step 8: create deep link for post or news in your app

    try {
        BranchUniversalObject buo = new BranchUniversalObject()
                .setCanonicalIdentifier("app/launch")
                .setTitle("appName")
                .setContentDescription(postContent)
                .setContentImageUrl(imageUrl)
                .setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PUBLIC)
                .setContentMetadata(new ContentMetadata()
                        .addCustomMetadata("install", "true")
                        .addCustomMetadata("TYPE", "POST")
                        .addCustomMetadata("post_id", "" + postId));

        LinkProperties lp = new LinkProperties().setChannel("url_share")
                .setFeature("sharing")
                .setCampaign("post share")
                .setStage("cricspace")
                .addControlParameter("$desktop_url", "your app web link")
                .addControlParameter("mobile", mobileNo)
                .addControlParameter("post_id", "" + postId)
                .addControlParameter("TYPE", "POST")                  
                .addControlParameter("custom_random",       
          Long.toString(Calendar.getInstance().getTimeInMillis()));

        ShareSheetStyle shareSheetStyle = new ShareSheetStyle(context, "Check this  
        out!", postContent)

       .setCopyUrlStyle(context.getResources().
        getDrawable(android.R.drawable.ic_menu_send), "Copy", "Added to  
        clipboard")
        .setMoreOptionStyle(context.getResources().
           getDrawable(android.R.drawable.ic_menu_search), "Show more")
           .addPreferredSharingOption(SharingHelper.SHARE_WITH.FACEBOOK)
           .addPreferredSharingOption(SharingHelper.SHARE_WITH.WHATS_APP)
           .addPreferredSharingOption(SharingHelper.SHARE_WITH.GMAIL)
           .addPreferredSharingOption
            (SharingHelper.SHARE_WITH.FACEBOOK_MESSENGER)
            .addPreferredSharingOption(SharingHelper.SHARE_WITH.HANGOUT)
            .addPreferredSharingOption(SharingHelper.SHARE_WITH.INSTAGRAM)
            .addPreferredSharingOption(SharingHelper.SHARE_WITH.WECHAT)
            .addPreferredSharingOption(SharingHelper.SHARE_WITH.TWITTER)
                .setAsFullWidthStyle(true)
                .setSharingTitle("Share With");

        // buo.setContentDescription(postModel.getPostContent()+"\n\n"  
       +deepLinkReferralURL );

        buo.generateShortUrl(context, lp, (url, error) -> {
            if (error == null) {
                buo.showShareSheet((AppCompatActivity) context, lp,   
          shareSheetStyle, new Branch.BranchLinkShareListener() {
                    @Override
                    public void onShareLinkDialogLaunched() {
                        onCallBack.onShareLinkDialog();
                    }

                    @Override
                    public void onShareLinkDialogDismissed() {
                    }

                    @Override
                    public void onLinkShareResponse(String sharedLink, String 
              sharedChannel, BranchError error) {
                    }

                    @Override
                    public void onChannelSelected(String channelName) {
                    }
                });
            }
        });
    } catch (Exception e) {
        Log.e("error", e.toString());
    }
Nagendran P
  • 96
  • 1
  • 5