List my app in the list of programs that can open a document

Asked

Viewed 656 times

2

When we receive an email with an attached file and click on this file a list of programs that can open this file is shown. How do I make my app also appear in this list?


I’m sorry, I’m new to the tool and I didn’t see the answer. I changed my code and it still doesn’t work.

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*"/>
        </intent-filter>
    </activity>

    <activity android:name=".Arquivos"/>
    <activity android:name=".NomeSenha" />
    <activity android:name=".Bateria" />
    <activity android:name=".Tensao"/>
</application>

  • Artur, I made an edition in the reply based on the information added. I added another link in the documentation that talks about how to allow other applications to start their activity. I tested it here and it works perfectly.

2 answers

1

It is necessary to create a IntentFilter, intention filters, in his Activity within the manifest.xml, that will add your app to the specific list.

An example, when it is clicked on the share would be used <action> in the <intent-filter>:

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

Would look like this:

<activity
    android:name=".ActivityNewUrl"
    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/plain"/>
        <data android:mimeType="image/*" />/>
    </intent-filter>
</activity>

Obs.: You have to check what type of file you want other applications to see. In this example above I define minType as text/plan and image, which means it will show the options when sharing texts or images. See more here how to allow other applications to start their activity.

Imagery:

inserir a descrição da imagem aqui

Read more here:

0

I managed to make it work if in the program that lists the purchases of the phone I select the option "share with". My program appears in the list and runs (now I’m having trouble getting the file but it’s another problem). What I wanted is not this, is to give a short click on the file name and my program appear in the list. Now for example appears text editors, PDF viewer and others. I wanted my app to be on this list, like programs that open this file and not just receive a share.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.