1

I need my Android app to be in Open With dialog for SQLite files.

Like when you install new web-browser it will appears in Open With dialog for html-files.

How can I do that?

Stephan
  • 41,764
  • 65
  • 238
  • 329
Tim Tolparov
  • 79
  • 1
  • 9

2 Answers2

4

This answer I found in Russian StackOverflow : https://ru.stackoverflow.com/a/420927/180697

<activity name="com.your.activity">
<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:scheme="file" />
    <data android:mimeType="*/*" />
    <data android:pathPattern=".*\\.sqlite" />
</intent-filter>

This is what you need to add to your Activity class:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    final Intent intent = getIntent();  
    final String action = intent.getAction();

    if(Intent.ACTION_VIEW.equals(action)){
        Uri uri = intent.getData();
        new File(uri.getPath()); //дальше делаем все, что надо с файлом 
    } else {
        Log.d(TAG, "intent was something else: "+action);
    }
}

So I only need to understand what to write in activity!)) Thanks!

Community
  • 1
  • 1
Tim Tolparov
  • 79
  • 1
  • 9
  • I want to play song using my player. I have put this code in my app. But when I play songs from Xender that time my app not listed in default app dialog, otherwise working fine. What I should do for this problem, to list-out my app in Xender app when user select a song for play. – Sumit Pansuriya Jun 26 '19 at 04:14
  • Did exactly this at this time. Now, with Android 10, is not shown anymore in the Dialog. What changed? – user7174483 Jan 29 '20 at 09:05
3

To appear in the 'Open With' dialog, your Android app must declare in its manifest that it handles a particular intent and then specify the mime-type of the file in the intent. For example :

<intent-filter >
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="application/x-sqlite" />
</intent-filter>

Note that the mime type for SQLite may not be recognised as I don't think this is yet a standard. You may want to use application/octet-stream instead and then in your own code, double check that the file being provided is actually a valid SQLite file (which you should do anyway).

You can find more information on tags here and on intent-filters in general here

Dave Durbin
  • 3,562
  • 23
  • 33
  • Thanks! But how will the app work with this file? In my case app should save SQLite file in '/data/data/package-name/databases' – Tim Tolparov May 05 '15 at 03:57
  • I'm not sure I understand the question. How are you attempting to open the file? i.e. where is the SQLite file that you are trying to get your app to open ? – Dave Durbin May 05 '15 at 07:00