Android: share CSV file - android

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>

Related

Unable to see the values set in EXTRA_TITLE

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.

Problems passing a file to another Android app

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"));

when launching application through link from SMS, the URIs keep getting cut

I'm doing a project, and I'm trying to launch our application through link from a received message.
But the URIS keep getting cut... I don't know the reason why.
Here is the SMS I got - I can't upload pictures, so i'll make the link part bold.
test *com.wekimi.and*roid
I defined the URI in EmergencyActivity.java like this :
Uri uri = Uri.parse("com.wekimi.android");
And I added intent-filter in manifest file like this :
<activity android:name="EmergencyActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="com.wekimi.android" />
</intent-filter>
What would be the problem? I don't even know if the Uri is recognizing the scheme data or not, because it's too short so it can't be directed to a right destination.

Android MIME type for MMS (SMS) messages?

The answer to How to open Email program via Intents (but only an Email program) shows how to open a chooser with ONLY email programs displayed by calling intent.setType("message/rfc822").
I would like to do the exact same thing, but choose MMS capable (or even just SMS) instead of email programs.
The end goal is to create a "share with" chooser that sends different content depending upon the form the message will take. (Since an email can be a LOT longer than a text or a tweet, and can contain an video attachment.)
I believe that this is the MIME Type for MMS messages: "application/vnd.wap.mms-message"
This is the MIME Type for SMS messages: "vnd.android-dir/mms-sm"
Example:
Manifest.xml file:
<receiver android:name=".SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<data android:mimeType="vnd.android-dir/mms-sms" />
</intent-filter>
</receiver>
<service android:name=".SMSReceiverService"/>
<receiver android:name=".MMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />
<data android:mimeType="application/vnd.wap.mms-message" />
</intent-filter>
</receiver>
This is how I have used the MIME Types so far in my Android development.
I found this link to jTribe's blog. Seems to have a functioning example of how to accomplish this, but frankly I can't find any documentation that corroborates that this is correct. It does some weird things like setting the action to ACTION_VIEW (instead of ACTION_SEND) and then uses a String param, instead of a static variable in the Intent class... but here's the code:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "The SMS text");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);

Creating a default viewer / receiver for Android email attachments

I'm trying to create a default handler for .p7s/.p7b files in Android.
I figured the best start would be to create a BroadcastReceiver that will capture the intent from the Android email application (or K-9 if that's a need) for opening of certain attachments (filtered by mime type). Specifically I'm trying to handle s/mime email so looking for the "application/x-pkcs7-certificates" and "application/x-pkcs7-certificates" mime types.
Just as a basic test I've been trying something like this:
Manifest.xml
<receiver android:name=".IntentReceiver" android:enabled="true">
<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:mimeType="application/x-pki-signature"/>
</intent-filter>
</receiver>
Class file.
public class IntentReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("TEST", "Intent was caught");
//Do something here
}
}
I've tried using the following mimeType filters as well (testing signatures first):
application/pkcs7-signature
application/x-pkcs7-signature
application/keychain_access
I can't seem to get the IntentReceiver class to capture the intent no matter what filtering I use though. Am I going about this the wrong way?
FIXED: I tried to simply use a regular activity and add the mimeType filtering into that and BAM! it worked. Seems there must be a discrepancies with the BroadcastReceiver not supporting this type of VIEW intent.
New manifest:
<activity android:name=".PkixReceiver"
android:label="#string/app_name">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="application/x-pkcs7-signature" />
<data android:mimeType="application/pkcs7-signature" />
<data android:mimeType="application/keychain_access" />
</intent-filter>
</activity>
And now the activity gets fired when the "open" attachment is clicked, success!
I would include all of those MIME types (just use multiple <data> elements).
It may be that the MIME type is not being included in the email, though. I don't know how you are sending the emails, but try sending them to some account where you can examine the full source of the email message. If the MIME types are not included in the message, you are out of luck.
You might also test a link to one of these files in a Web page (where the Web server serves up the MIME type header), to confirm that your basic handling is OK.

Categories

Resources