snapshot of code and intent filter that gets an attachment into an

email and launches Crosswords when the attachment is opened.
Shouldn't, or at least shouldn't launch ONLY Crosswords, as the mime
type's not in the filter, but it does.
This commit is contained in:
Eric House 2012-11-29 08:19:07 -08:00
parent 9f5a64ee50
commit f4dc8a6b41
3 changed files with 56 additions and 3 deletions

View file

@ -133,6 +133,15 @@
android:pathPrefix="@string/invite_prefix"
/>
</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:mimeType="*/*"
android:scheme="content"
/>
</intent-filter>
</activity>
<!-- downloading dicts -->

View file

@ -104,6 +104,9 @@
<string name="invite_host">eehouse.org</string>
<string name="invite_prefix">/and/</string>
<string name="invite_mime">application/x-xwordsinvite</string>
<!--string name="invite_mime">text/plain</string-->
<string name="dict_url">http://eehouse.org/and_wordlists</string>
<string name="expl_update_url">Update checks URL</string>
<string name="default_update_url">http://eehouse.org/xw4/info.py</string>

View file

@ -24,12 +24,15 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.Html;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.concurrent.locks.Lock;
import java.util.HashMap;
import java.util.HashSet;
import android.text.Html;
import java.util.concurrent.locks.Lock;
import org.json.JSONArray;
import org.json.JSONObject;
import junit.framework.Assert;
@ -539,11 +542,25 @@ public class GameUtils {
Intent intent = new Intent();
if ( choseEmail ) {
intent.setAction( Intent.ACTION_SEND );
intent.setType( "message/rfc822");
String subject =
Utils.format( context, R.string.invite_subjectf, room );
intent.putExtra( Intent.EXTRA_SUBJECT, subject );
intent.putExtra( Intent.EXTRA_TEXT, Html.fromHtml(message) );
File tmpdir = DictUtils.getDownloadDir( context );
if ( null == tmpdir ) { // no attachment
intent.setType( "message/rfc822");
} else {
intent.setType( context.getString( R.string.invite_mime ) );
File attach = makeJsonFor( tmpdir, room, inviteID, lang,
dict, nPlayers );
Uri uri = Uri.fromFile( attach );
DbgUtils.logf( "using file uri for attachment: %s",
uri.toString() );
intent.putExtra( Intent.EXTRA_STREAM, uri );
}
choiceID = R.string.invite_chooser_email;
} else {
intent.setAction( Intent.ACTION_VIEW );
@ -901,5 +918,29 @@ public class GameUtils {
}
}
private static File makeJsonFor( File dir, String room, String inviteID,
int lang, String dict, int nPlayers )
{
File result = null;
JSONObject json = new JSONObject();
try {
json.put( MultiService.ROOM, room );
json.put( MultiService.INVITEID, inviteID );
json.put( MultiService.LANG, lang );
json.put( MultiService.DICT, dict );
json.put( MultiService.NPLAYERST, nPlayers );
byte[] data = json.toString().getBytes();
File file = new File( dir,
String.format("invite_%s.json", room ) );
FileOutputStream fos = new FileOutputStream( file );
fos.write( data, 0, data.length );
fos.close();
result = file;
} catch ( Exception ex ) {
DbgUtils.loge( ex );
}
return result;
}
}