open file directly with app

This commit is contained in:
Huang Yunkun 2020-10-21 19:23:51 +08:00
parent 082baad668
commit ff331ac724
2 changed files with 21 additions and 9 deletions

View file

@ -50,18 +50,18 @@
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"
android:resource="@xml/device_filter" />
<!-- TODO: fix, implement, etc.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="application/octet-stream"
android:host="*"
android:pathPattern=".*\\.nsp"
/>
<data android:host="*"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.nsp"/>
<data android:pathPattern=".*\\.nsz"/>
<data android:pathPattern=".*\\.xci"/>
<data android:pathPattern=".*\\.xcz"/>
<data android:scheme="content"/>
</intent-filter>
-->
</activity>
<receiver
@ -80,4 +80,4 @@
android:exported="false" />
</application>
</manifest>
</manifest>

View file

@ -256,6 +256,14 @@ public class MainActivity extends AppCompatActivity implements NsResultReciever.
});
// Upload to NS button
uploadToNsBtn = findViewById(R.id.buttonUpload);
//check if it's from file selected
Intent intent = getIntent();
Uri uri = intent.getData();
if (savedInstanceState == null && uri != null) {
readFile(intent);
}
}
private void updateUploadBtnState(){ // TODO: this function is bad. It multiplies entropy and sorrow.
@ -296,6 +304,10 @@ public class MainActivity extends AppCompatActivity implements NsResultReciever.
if (requestCode != ADD_NSP_INTENT_CODE || data == null)
return;
readFile(data);
}
private void readFile(Intent data) {
Uri uri = data.getData();
if (uri == null || uri.getScheme() == null || ! uri.getScheme().equals("content"))