Commit 35c00d04 authored by kenan's avatar kenan

Fix 分享的uri

parent f723e29c
......@@ -107,6 +107,7 @@
android:name="cn.garymb.ygomobile.ui.activities.ShareFileActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:launchMode="singleTop"
android:excludeFromRecents="true"
android:theme="@style/TranslucentTheme"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
<intent-filter>
......@@ -208,14 +209,10 @@
android:name="cn.garymb.ygomobile.ui.preference.YGOPreferencesProvider"
android:authorities="cn.garymb.ygomobile.ui.preference.YGOPreferencesProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
android:grantUriPermissions="true" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:authorities="${applicationId}.gamefiles"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
......
......@@ -25,6 +25,7 @@ import cn.garymb.ygomobile.utils.IOUtils;
import static cn.garymb.ygomobile.Constants.CORE_DECK_PATH;
import static cn.garymb.ygomobile.Constants.CORE_EXPANSIONS;
import static cn.garymb.ygomobile.Constants.CORE_PACK_PATH;
import static cn.garymb.ygomobile.Constants.CORE_REPLAY_PATH;
import static cn.garymb.ygomobile.Constants.CORE_SYSTEM_PATH;
import static cn.garymb.ygomobile.Constants.DEF_PREF_FONT_SIZE;
import static cn.garymb.ygomobile.Constants.DEF_PREF_KEEP_SCALE;
......@@ -471,6 +472,13 @@ public class AppsSettings {
mSharedPreferences.putString(Constants.PREF_GAME_PATH, path);
}
/**
* @return 录像文件夹
*/
public String getReplayDir() {
return new File(getResourcePath(), CORE_REPLAY_PATH).getAbsolutePath();
}
//获取卡组文件夹
public String getDeckDir() {
return new File(getResourcePath(), CORE_DECK_PATH).getAbsolutePath();
......
......@@ -2,14 +2,27 @@ package cn.garymb.ygomobile.ui.activities;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;
import java.io.File;
import java.util.List;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.utils.FileUtils;
import static cn.garymb.ygomobile.Constants.CORE_REPLAY_PATH;
public class ShareFileActivity extends Activity {
@Override
......@@ -28,8 +41,43 @@ public class ShareFileActivity extends Activity {
private void doIntent(Intent intent) {
String type = intent.getStringExtra(IrrlichtBridge.EXTRA_SHARE_TYPE);
String path = intent.getStringExtra(IrrlichtBridge.EXTRA_SHARE_FILE);
//TODO
Toast.makeText(this, "type=" + type + ",path=" + path, Toast.LENGTH_SHORT).show();
File file;
String title;
if("yrp".equals(type)){
file = new File(AppsSettings.get().getReplayDir(), path);
title= "分享录像";
} else if("ydk".equals(type)){
file = new File(AppsSettings.get().getDeckDir(), path);
title= "分享卡组";
} else {
finish();
return;
}
Uri uri = FileUtils.toUri(this, file);
// Log.d("kk-test", "file="+file+", canRead="+(file.exists() && file.canRead()));
// Log.d("kk-test", "uri="+uri);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("text/plain");
try{
// Log.d("kk-test", "uri="+uri);
// ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "r");
// if(pfd != null){
// pfd.close();
// Log.d("kk-test", "open ok");
// }
// List<ResolveInfo> resInfoList = this.getPackageManager()
// .queryIntentActivities(shareIntent, 0);
// for (ResolveInfo resolveInfo : resInfoList) {
// String packageName = resolveInfo.activityInfo.packageName;
// this.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
// }
startActivity(Intent.createChooser(shareIntent, title));
}catch (Throwable e){
Log.w("kk-test", "open uri error:"+uri, e);
Toast.makeText(this, "没有可以分享的应用", Toast.LENGTH_SHORT).show();
}
finish();
}
......
......@@ -4,6 +4,7 @@ import android.content.Context;
import android.net.Uri;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.content.FileProvider;
import java.io.BufferedReader;
......@@ -22,7 +23,7 @@ import java.util.List;
public class FileUtils {
public static Uri toUri(Context context, File file){
return FileProvider.getUriForFile(context, context.getPackageName()+".fileprovider", file);
return FileProvider.getUriForFile(context, context.getPackageName()+".gamefiles", file);
}
public static boolean deleteFile(File file) {
......
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<!-- /storage/emulated/0/Download/${applicationId}/.beta/apk-->
<paths>
<external-path
name="external_files"
path="." />
<root-path
name="external_files"
path="/storage/" />
<!-- /storage/emulated/0/Download/com.bugly.upgrade.demo/.beta/apk-->
<external-path name="beta_external_path" path="Download/"/>
<!--/storage/emulated/0/Android/data/${applicationId}/files/apk/-->
<!--/storage/emulated/0/Android/data/com.bugly.upgrade.demo/files/apk/-->
<external-path name="beta_external_files_path" path="Android/data/"/>
</paths>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment