How to make my Android app appear in the share lis

2019-01-05 02:32发布

<action android:name="android.intent.action.SEND" />     
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />

this is in my manifest file

this will make my app appear on the share list of all apps but I want my app to appear in the share list of another specific app and I don't own the other app

5条回答
我命由我不由天
2楼-- · 2019-01-05 02:47

I would check to see if there is any API for this app you want to work with.

If so, you can benefit by knowing

  • a more specific implicit action for your filter
  • or perhaps add a category other than DEFAULT
  • If you can find something like these, it would be unlikely to be seen by other apps.

    查看更多
    倾城 Initia
    3楼-- · 2019-01-05 02:48

    this worked well for me for getting all web pages, for my app that scans for mp3 files on a web page, and sets alarms from them. It opens up my new url activity, when you share a web page:

    Here is what this code results in: enter image description here

      <activity
            android:name=".NewUrl"
            android:label="@string/title_activity_new_url"
            android:windowSoftInputMode="stateUnchanged">
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="text/*"/>
            </intent-filter>
        </activity>
    

    Then to receive the link in the app, I got awsome info from this tutorial: http://code.tutsplus.com/tutorials/android-sdk-receiving-data-from-the-send-intent--mobile-14878

    查看更多
    forever°为你锁心
    4楼-- · 2019-01-05 02:54

    In order to do this, you need to know the Intent that the application is creating and create an IntentFilter that will add your application to the specific list.

    Receiving an Implicit Intent on Intents and Filters (Android Developers)

    The application probably uses a specific action name that you could hook to.

    <intent-filter . . . >
        <action android:name="com.example.project.SHOW_CURRENT" />
        <action android:name="com.example.project.SHOW_RECENT" />
        <action android:name="com.example.project.SHOW_PENDING" />
        . . .
    </intent-filter>
    

    Or it could be looking for applications accepting a certain type of file.

    <intent-filter . . . >
        <data android:mimeType="video/mpeg" android:scheme="http" . . . /> 
        <data android:mimeType="audio/mpeg" android:scheme="http" . . . />
        . . .
    </intent-filter>
    

    The name of the application and what it is sharing would help me give a more specific response.

    查看更多
    Luminary・发光体
    5楼-- · 2019-01-05 03:02

    Add this code in the activity you want opened first when sharing a content from outside the app, call this method in onCreate()

    private void onSharedIntent() {
        Intent receiverdIntent = getIntent();
        String receivedAction = receiverdIntent.getAction();
        String receivedType = receiverdIntent.getType();
    
        if (receivedAction.equals(Intent.ACTION_SEND)) {
    
            // check mime type 
            if (receivedType.startsWith("text/")) {
    
                String receivedText = receiverdIntent
                        .getStringExtra(Intent.EXTRA_TEXT);
                if (receivedText != null) {
                    //do your stuff
                }
            }
    
            else if (receivedType.startsWith("image/")) {
    
                Uri receiveUri = (Uri) receiverdIntent
                        .getParcelableExtra(Intent.EXTRA_STREAM);
    
                if (receiveUri != null) {
                    //do your stuff
                    fileUri = receiveUri;// save to your own Uri object
    
                    Log.e(TAG,receiveUri.toString());
                }
            }
    
        } else if (receivedAction.equals(Intent.ACTION_MAIN)) {
    
            Log.e(TAG, "onSharedIntent: nothing shared" );
        }
    }
    

    Add this in Manifest,

     <activity
                android:name="your-package-name.YourActivity">
                <intent-filter>
                    <action android:name="android.intent.action.SEND" /> 
    
                    <category android:name="android.intent.category.DEFAULT" />      
                    <data android:mimeType="image/*" />
                    <data android:mimeType="text/*" />
                </intent-filter>
            </activity>
    
    查看更多
    欢心
    6楼-- · 2019-01-05 03:11

    add this to your mainefist file

    <activity android:name=".ShareActivity">
    <intent-filter
        android:label="Share with my app">
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    

    this link may help you

    查看更多
    登录 后发表回答