I have an app that can handle ".arr" files. In order to do it, I add the proper parameters at the AndroidManifest:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.arr" android:mimeType="*/*"/>
</intent-filter>
Then, when opening this kind of file from a file explorer, I get the URI with:
Uri uri = intent.getData();
The problem is that at the History Stack, its saved the Intent with its data (the file). So, if I then close my app and re-open it from history, it detects again as if I were opening the file again.
I want to keep the app in the History Stack but without the information of the file!!
Related
I have deployed an Android app that is designed to view files, some users reporting that my app isn't appearing when they try to open a file but does appear when selecting Open with....
For example, when I try to open a file in some apps I am presented with a dialog like this:
When I press Open with... I am presented with a dialog like this:
I think what is happening here is the Open with... is starting an ACTION_CHOOSER intent whereas pressing the file starts an ACTION_VIEW intent.
My questions are:
Is my assumption surrounding the ACTION_CHOOSER reasonable?
Why do some apps appear in ACTION_CHOOSER that don't appear in ACTION_VIEW?
Is the ACTION_VIEW list somehow dependent on a device?
If so, what would cause my app to not appear in this list?
For reference, my activity's intent filter looks like this:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:mimeType="*/*"
android:scheme="content" />
<data
android:pathPattern=".*\\.xml"
android:scheme="file" />
<!-- about a hundred other file types -->
<intent-filter>
I have an app which records Audio and video. Then there is a list in the app which displays these recorded files. When user clicks on one of this file, I would like to display an option of apps that user can choose to play this clicked file. An example of it is shown below.
All the examples I have looked on internet is of using a media player which I am already doing but I would like the pause, stop etc function to be handled by an already available app in the users device.
Is this possible to do? If so how?
I guess your Activity which handles Audio and Video should have this in AndroidManifest.
The below intent-filer is for Audio files, similarly you can add for Video files for the same Activity.
<activity ...>
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="audio/*"/>
</intent-filter>
</activity>
EDIT:
For your Activity
Suppose you show a list of audio files and user is suppose to click one. So when the user clicks some item. You just need to set the result.
Ex.
setResult(RESULT_OK, new Intent().setData(YOUR_URI));
The 2nd param is just the data which we need to pass to the calling Application basically we pass the URI of the data.
EDIT 2: The RESULT_OK is inherited variable of Activity. You don't need to define it.
I hope it helps you.
I found the answer by readin up on the internet.
First prepare the file location and then open an intent with the data at this location
Uri fileURi = Uri.parse(tempFileURi); //i.e. /storage/emulated/0/Android/data/com.sahilsaid.appname/files/Music/Recording200.3gp
File file = new File(fileURi.toString());
if (file.exists()) {
Uri finalFileUri = Uri.fromFile(file);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(finalFileUri, URLConnection.guessContentTypeFromName(finalFileUri.toString()));
startActivity(intent);
}
You will also need to modify your AndroidManifest.xml file and add intent-filter as suggested above by #Aky
<activity
android:name=".exampleActivity"
android:label="#string/title_activity_example">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="audio/*"/>
</intent-filter>
</activity>
For more info visit this article:
https://software.intel.com/en-us/blogs/2014/03/20/video-playing-with-android-media-player
I've just added the ability for a user to restore their data in my app by backing up a custom file type. When the file is opened from a file explorer with my app, my root (main) activity is opened, but in a new instance. For example, if my app is open and the restore file is opened from a file explorer, a new instance of my app opens at my root activity. In android's task manager, this looks like my app running within the file explorer, if that makes sense. Since the restore process changes user data, it's possible that the original instance of my app stops functioning because it was in a data-dependent activity.
How can I prevent multiple instances of my app when it is accessed via a different intent like this? Thanks.
Update: I've searched around and still can't find a solution. Help would be appreciated.
intent-filter for my root activity in the manifest:
<manifest
android:launchMode="singleInstance"
...
<application
android:... >
<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.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" android:pathPattern=".*\\.grdcsv" android:mimeType="*/*" android:host="*"/>
</intent-filter>
<!-- For email attachments -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/octet-stream" android:pathPattern=".*\\.grdcsv" android:scheme="content" />
</intent-filter>
How can I prevent multiple instances of my app when it is accessed via a different intent like this?
You can try to use android:launchMode="singleTask" in your activity declaration in manifest. If you see the docs, it says:
The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one.
This probably won't create a new instance as you mentioned in the question. Try it. Let me know if you still face the same issue.
We have developed an Android app which is used for rendering files of our custom file type (.vds). I am able to launch my app for all the files (.vds file) which are stored on local storage, but if the files is stored on Box and I try to access them using the Box Android App then I am facing issues. I have created the following intent filter:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.vds" />
The problem is that in the corresponding activity I am able to get the intent, but if I try to read the URI (as our rendering logic is based upon file location) it gives me a path which doesn't exists on the SD card. What happens if we try to open a file using Box Android Native App? Where is the file downloaded and how should the downloaded file be accessed?
This may solve ur problem. Add the bellow intent filter.
<activity android:name=".Activity"
android:screenOrientation="portrait"
android:label="#string/app_name">
<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.VIEW"/>
<action android:name="android.intent.action.EDIT"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:pathPattern="*.snowdragon"/>
<data android:mimeType="text/snowdragon"/>
</intent-filter>
</activity>
As noted above I've run into the same problem. While I've not found what I would consider to be The Right Solution(TM) I do have a couple of things to add that might be useful to others:
First, I've discovered that if I download the file in Box (not the same as mark for offline) then clicking the item in either the download result dialog or in the subsequent notification that appears at the bottom of the app works. Once you've dismissed that notification however, there does not seem to be a way to get back to the downloaded file from within Box.
Second, and let me qualify this by saying that I've not looked very closely at it yet but I think one could use the filename info in the intents for non-existent files to retrieve the file via the Box API, either directly from the cloud or possibly via API call to retrieve offline items. I'm wondering if this is actually what Box is trying to get us to do with these bogus file paths, considering that they are so blatantly bogus:
12-04 10:09:29.318: INFO/ActivityManager(607): START u0
{act=android.intent.action.VIEW dat=file:///non_existent_dummy_folder/foo.abcdef typ=application/abcdef cmp=com.foo.bar/.app.FooViewer}
What I want: To be able to send my custom file by mail and import it with my application from the preview button in GMail or when opening it in a file browser.
What I know: I've read a lot of custom mime type handlers, that android doesn't care about file extension etc., but how to create the mime type for my custom file?
The question: Do I need to be a content provider? I just want to import files (from backup) not provide anything. I've seen people having handlers for "application/abc" saying it's working fine, but how to add that connection for my file "myFile.abc" and the mime type?
Some direction how to register/map custom mime types would be appreciated! :)
As far as I can tell, mime types are pretty flexible (I created mine as application/whatever) and they're accepted immediately by Android, as far back as Dalvik version 2.1. To handle them properly, I added this intent-filter:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/whatever" />
</intent-filter>
There is a caveat though. Even though I always set the type of the send Intent with intent.setType("application/whatever");, on some phones I've seen the actual data on arrival as application/octet (to see the value, I assigned the incoming Intent and inspected its value directly Intent currentIntent = getIntent();). The receiving Android device didn't know what to do with the incoming data and told me so. So I added
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/octet-stream" />
</intent-filter>
This approach could be troublesome of course, but the problem with Gmail at least is that it doesn't necessarily write the file with the name as it comes in, which renders any Path I choose to define useless. And at least with an incoming octet-stream you know it's not any app's specific data you're stealing away... Still, you should validate the data afterwards and not just assume it's valid for your app.
I have added custom mime type in android contacts list. After a long research i decided to share this with you guys, i have tested this on all Android cell phone including android 9.0.
here is my Github link
Untested, but something like this should work. Put it in your AndroidManifest.xml with the activity you want to open the file:
<activity name=".ActivityHere">
<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="mimeTypeHere" />
</intent-filter>
</activity>
<activity
android:name="MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<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="{your mime}.com"
android:scheme="http" >
</data>
</intent-filter>
</activity>
<!--
android:scheme="http" will make android "think" thats this is a link
-->
Now, when you receiving a sms with the text "http://{your mime}.com" or clicking link on the web with this text, your activity (MainActivity) will run.
You also can add parameters:
text = "http://{your mime}.com/?number=111";
Then in onCreate() or onResume() methods you'll add:
Intent intentURI = getIntent();
Uri uri = null;
String receivedNum = "";
Log.d("TAG", "intent= "+intentURI);
if (Intent.ACTION_VIEW.equals(intentURI.getAction())) {
if (intentURI!=null){
uri = intentURI.getData();
Log.d("TAG", "uri= "+uri);
}
if (uri!=null)
receivedNum = uri.getQueryParameter("number");
}
Register a custom mime type using android.webkit.MimeTypeMap