Handle VIEW intent from File Managers.

This commit is contained in:
Brian Pellin
2009-08-26 22:15:53 -05:00
parent 22bfa30691
commit 6e325e1c3c
4 changed files with 72 additions and 5 deletions

View File

@@ -12,7 +12,16 @@
</intent-filter>
</activity>
<activity android:name="com.keepassdroid.fileselect.FileSelectActivity"></activity>
<activity android:name="com.keepassdroid.PasswordActivity" android:configChanges="orientation|keyboardHidden"></activity>
<activity android:name="com.keepassdroid.PasswordActivity" android:configChanges="orientation|keyboardHidden">
<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=".*\\.kdb" />
</intent-filter>
</activity>
<activity android:name="com.keepassdroid.GroupActivity">
<!-- This metadata entry causes .app.SearchQueryResults to be the default context -->
<!-- whenever the user invokes search while in this Activity. -->

View File

@@ -83,7 +83,8 @@
<string name="hint_pass">password</string>
<string name="hint_conf_pass">confirm password</string>
<string name="hint_comment">comment</string>
<string name="no_url_handler">No handler for this url.</string>
<string name="error_no_name">A name is required.</string>
<string name="no_url_handler">No handler for this url.</string>
<string name="error_no_name">A name is required.</string>
<string name="error_can_not_handle_uri">KeePassDroid cannot handle this uri.</string>
<string name="error_could_not_create_group">Error creating group.</string>
</resources>

View File

@@ -48,6 +48,7 @@ public class PasswordActivity extends Activity {
private static final int MENU_ABOUT = Menu.FIRST;
private static final String KEY_FILENAME = "fileName";
private static final String KEY_KEYFILE = "keyFile";
private static final String VIEW_INTENT = "android.intent.action.VIEW";
private String mFileName;
private String mKeyFile;
@@ -88,8 +89,40 @@ public class PasswordActivity extends Activity {
super.onCreate(savedInstanceState);
Intent i = getIntent();
mFileName = i.getStringExtra(KEY_FILENAME);
mKeyFile = i.getStringExtra(KEY_KEYFILE);
String action = i.getAction();
if ( action != null && action.equals(VIEW_INTENT) ) {
mFileName = i.getDataString();
if ( ! mFileName.substring(0, 7).equals("file://") ) {
Toast.makeText(this, R.string.error_can_not_handle_uri, Toast.LENGTH_LONG).show();
finish();
return;
}
mFileName = mFileName.substring(7, mFileName.length());
if ( mFileName.length() == 0 ) {
// No file name
Toast.makeText(this, R.string.FileNotFound, Toast.LENGTH_LONG).show();
finish();
return;
}
File dbFile = new File(mFileName);
if ( ! dbFile.exists() ) {
// File does not exist
Toast.makeText(this, R.string.FileNotFound, Toast.LENGTH_LONG).show();
finish();
return;
}
mKeyFile = getKeyFile(mFileName);
} else {
mFileName = i.getStringExtra(KEY_FILENAME);
mKeyFile = i.getStringExtra(KEY_KEYFILE);
}
setContentView(R.layout.password);
populateView();
@@ -98,6 +131,17 @@ public class PasswordActivity extends Activity {
confirmButton.setOnClickListener(new ClickHandler(this));
}
private String getKeyFile(String filename) {
FileDbHelper dbHelp = new FileDbHelper(this);
dbHelp.open();
String keyfile = dbHelp.getFileByName(filename);
dbHelp.close();
return keyfile;
}
private void populateView() {
setEditText(R.id.pass_filename, mFileName);
setEditText(R.id.pass_keyfile, mKeyFile);

View File

@@ -193,4 +193,17 @@ public class FileDbHelper {
return cursor;
}
public String getFileByName(String name) {
Cursor cursor = mDb.query(true, FILE_TABLE, new String[] {KEY_FILE_KEYFILE},
KEY_FILE_FILENAME + "= ?", new String[] {name}, null, null, null, null);
if ( cursor == null ) {
return "";
}
cursor.moveToFirst();
return cursor.getString(0);
}
}