Share intent option using Shortcut android

后端 未结 2 2114
孤城傲影
孤城傲影 2021-02-10 10:30

By default iOS is providing \"Share appname\" option in the shortcut options,when the app is downloaded from the app store.

Refer the image belo

2条回答
  •  天命终不由人
    2021-02-10 11:32

    You can use App shortcuts

    but the main disadavtange of this option is that it is available from Oreo and above version of android

    Here is the sample code

    Create a resource file: res/xml directory (Screenshot)

    
        
            
            
        
    
    

    Now you need to register your shortcut in your manifest file under activity tag

    
    
    
        
    
            
    
            
                
                    
                    
    
                    
                
    
                
    
            
    
        
    
    
    

    Now create a simple share acivity to share your app link

    import android.content.Intent;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    
    public class ShareActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_home);
    
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT,
                    "Hey check out my app at: https://play.google.com/store/apps/details?id=neel.com.demo");
            sendIntent.setType("text/plain");
            startActivity(sendIntent);
            finish();
        }
    }
    

    OUTPUT

    When user long press on app icon your shortcut will display like below image

    after click of shortcut

    UPDATE use android:excludeFromRecents="true" in your ShareActivity

    
    
        
    
        
            
                
                
    
                
            
    
            
    
        
    
    
    

提交回复
热议问题