Extremely weird behaviour, I'm fairly new to Android, but I'm generating some json (first line below) and I'm trying to send it to an application whose manifest says it accepts anything with type "application/xctsk".
The generated file is fine, but the app chooser doesn't offer that application. I can still share the file to Whatsapp and it will be fine, content-wise. However, I still can't open it from Whatsapp.
Meanwhile I can
open the file manually
open other files from other sources, from Whatsapp
Receiving app's Manifest
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/xctsk"
android:host="*"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
<data android:scheme="content"/>
<data android:scheme="file"/>
</intent-filter>
My code
Uri xctskURI= saveTask(somejson);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, xctskURI);
shareIntent.setType("application/xctsk");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Send to XCTrack"));
The receiving app supports only ACTION_VIEW. You are using ACTION_SEND. These don't match. Either change your sending app to use ACTION_VIEW or change the receiving app so that it supports ACTION_SEND.
Turns out to be very strict, resolver was not satisfied with less that a perfect match.
ALL the categories had to be matched. And for some reasons, setting the MIME type erases the data.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_VIEW);
shareIntent.addCategory(Intent.CATEGORY_DEFAULT);
shareIntent.addCategory(Intent.CATEGORY_BROWSABLE);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setDataAndType(xctskURI,"application/xctsk");
startActivity(Intent.createChooser(shareIntent, "Send to XCTrack"));
Related
I am building an app say Tx , which call's the createChooser using the below code.
Intent shareIntent = new Intent("com.myapplication.test");
shareIntent.putExtra(Intent.EXTRA_TITLE, "Sharing ..");
shareIntent.putExtra(Intent.EXTRA_TEXT,"Shared from Tx app.." );
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent,"Choose the app ..")));
I have also built few app's with below in their androidManfiest.xml files.
<intent-filter>
<action android:name="com.myapplication.test" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
When Tx's createChooser is called, I am able to see all the app's where -com.myapplication.test is present & also the title as - Choose the app .. . However, I am not able to see the EXTRA_TITLE which is set to "Sharing ..".
Is there any way I can show this in the chooser? any help would be highly appreciated.
I have an app which saves database files with extension ".swt" in a particular folder. I was able to share this file using intent from one device to other but the device which received the file could not open it through the same app.
Here is my AndroidManifest with intent-filter
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data
android:scheme="file"
android:mimeType="*/*"
android:pathPattern=".*\\.swt"
android:host="*" />
</intent-filter>
Here is my code for sharing the files
ArrayList<Uri>uris = new ArrayList<>();
uris.add(Uri.fromFile(file1));
uris.add(Uri.fromFile(file2));
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,uris);
shareIntent.setType("*/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent,"Share Files Using"))
After searching a while, i got to know about onNewIntent method. But it is also not working.
so how could i make my app to access this file with extension ".swt"?
My app has an activity with the following intent filter.
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:host="m.testsite.com"> </data>
<data android:scheme="http"></data>
<data android:pathPattern=".*"></data>
</intent-filter>
This opens up any link with the url http://m.testsite.com/anypath in the app . However sometimes it so happens that there is no data inside the app with respect to the path and I need to transfer him back to the browser only.
What should be the intent-filter for this?
Edit:-Seems like my question was not very clear .The device had two packages listening to the same intent-filter. One was the browser and the other was my app. I was in a situation where in certain cases, I had to target only the browser and not the app for the same intent-filter. I was hoping that there would be some particular action or category which I could target for just the browser alone. However I managed to solve it . I have put my answer below.
This is how I solved it finally:-
for (ResolveInfo resolveInfo : list) {
if (!activityName.contains("MyApplicationActivity")) {
browserIntent =
packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
ComponentName comp =
new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
browserIntent.setAction(Intent.ACTION_VIEW);
browserIntent.setComponent(comp);
browserIntent.setData(data);
startActivity(browserIntent);
break;
}}
My aplication can generate CSV files that I want to share. I'm using MIME type text/comma_separated_values/csv, but when I send the Intent the chooser isn't shown, I guess my device doesn't know how to handle the file. Which type should I use?
This is my code:
Uri csv = lh.createDailyCSV();
if(csv == null){
Toast.makeText(this, getString(R.string.error_creating_csv), Toast.LENGTH_LONG).show();
}
else{
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/comma_separated_values/csv");
sharingIntent.setData(csv);
startActivity(Intent.createChooser(sharingIntent, getResources().getText(R.string.send_to)));
}
I declared in my manifest:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/comma_separated_values/csv" />
</intent-filter>
And I get the exception
03-12 12:19:23.430: E/ActivityThread(24011): Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1#412fc920 that was originally registered here. Are you missing a call to unregisterReceiver()?
I've read this Exception occurs when there is none or just 1 option in the chooser.
[EDIT]
I changed how I attach the data to the Intent. Instead of sharingIntent.setData(csv) I used:
sharingIntent.putExtra(Intent.EXTRA_STREAM, csv);
And now the chooser works fine, but if I try to send the file via e-mail I get an error: File couldn't be shown.
[/EDIT]
The correct MIME type would be text/csv. If that doesn't work, you can use text/plain which will allow the user to potentially choose from a lot of apps, including Evernote etc.
Update After the update, it seems that you don't want to "share" the file with arbitrary other apps but only send it by e-mail? Please clarify.
In my case, the following works in Goo:
intent.setType("text/*");
<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>
In my application, I want to make a picker that offers the user the choice to pick a music. I want to use the native android picker. I used the following code to open the native android music picker:
final Intent intent2 = new Intent(Intent.ACTION_PICK);
intent2.setType("audio/*");
startActivityForResult(intent2, 1);
But when I execute it, I get an ActivityNotFoundException and this error message:
"Your phone has no music gallery that can be used to select a file. Please try sending a different type of files"
Am I doing something wrong there ?
This worked well for me:
public static final int REQ_PICK_AUDIO = 10001;
//------
Intent audio_picker_intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
activity.startActivityForResult(audio_picker_intent, REQ_PICK_AUDIO);
The more general intent with Intent.ACTION_GET_CONTENT can present the user with a number of options for activities to pick an audio file (Astro file manager, etc.). However, the user could select any file, not necessarily an audio file. I wanted one that simply allowed the user to select an audio file from their media. This did the trick.
If you take a look at the AndroidManifest.xml file for the latest core Music app, it may shed some light on the options that you have. For example:
<activity android:name="com.android.music.MusicPicker"
android:label="#string/music_picker_title" android:exported="true" >
<!-- First way to invoke us: someone asks to get content of
any of the audio types we support. -->
<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/*"/>
<data android:mimeType="application/ogg"/>
<data android:mimeType="application/x-ogg"/>
</intent-filter>
<!-- Second way to invoke us: someone asks to pick an item from
some media Uri. -->
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="vnd.android.cursor.dir/audio"/>
</intent-filter>
</activity>
So based on this, you might first try
final Intent intent2 = new Intent(Intent.ACTION_GET_CONTENT);
intent2.setType("audio/*");
startActivityForResult(intent2, 1);
and see if it fits your needs. You may also look at adding the category flags noted in the above example to help narrow down the results (e.g. OPENABLE should filter to only content that can be opened as a stream.
Something along the lines of this may work
// some Intent that points to whatever you like to play
Intent play = new Intent(Intent.ACTION_VIEW);
play.setData(Uri.fromFile(new File("/path/to/file")));
// create chooser for that intent
try {
Intent i = Intent.createChooser(play, "Play Music");
c.startActivity(i);
} catch(ActivityNotFoundException ex) {
// if no app handles it, do nothing
}