新增 app.intent()支持flags

This commit is contained in:
hyb1996
2018-11-11 21:58:59 +08:00
parent 0464e3e49b
commit 76fa44960c
4 changed files with 90 additions and 62 deletions

View File

@@ -4,6 +4,7 @@
<w>autojs</w> <w>autojs</w>
<w>capturer</w> <w>capturer</w>
<w>dismissable</w> <w>dismissable</w>
<w>fileprovider</w>
<w>flowable</w> <w>flowable</w>
<w>imgproc</w> <w>imgproc</w>
<w>interruptible</w> <w>interruptible</w>

View File

@@ -29,6 +29,17 @@ module.exports = function(runtime, global){
} }
intent.setAction(i.action); intent.setAction(i.action);
} }
if (i.flags) {
let flags = 0;
if (Array.isArray(i.flags)) {
for (let j = 0; j < i.flags.length; j++) {
flags |= parseIntentFlag(i.flags[j]);
}
} else {
flags = parseIntentFlag(i.flags);
}
intent.setFlags(flags);
}
if (i.type) { if (i.type) {
if (i.data) { if (i.data) {
intent.setDataAndType(android.net.Uri.parse(i.data), i.type); intent.setDataAndType(android.net.Uri.parse(i.data), i.type);
@@ -110,8 +121,12 @@ module.exports = function(runtime, global){
if (path.startsWith("file://")) { if (path.startsWith("file://")) {
path = path.substring(7); path = path.substring(7);
} }
let file = new java.io.File(files.path(path));
if (app.fileProviderAuthority == null) {
return android.net.Uri.fromFile(file);
}
return android.support.v4.content.FileProvider.getUriForFile(context, return android.support.v4.content.FileProvider.getUriForFile(context,
"org.autojs.autojs.fileprovider", new java.io.File(files.path(path))); app.fileProviderAuthority, file);
}; };
app.launch = app.launchPackage; app.launch = app.launchPackage;
@@ -126,6 +141,13 @@ module.exports = function(runtime, global){
global.__asGlobal__(app, ['launchPackage', 'launch', 'launchApp', 'getPackageName', 'getAppName', 'openAppSetting']); global.__asGlobal__(app, ['launchPackage', 'launch', 'launchApp', 'getPackageName', 'getAppName', 'openAppSetting']);
function parseIntentFlag(flag) {
if (typeof (flag) == 'string') {
return android.content.Intent["FLAG_" + flag.toUpperCase()];
}
return flag;
}
return app; return app;
} }

View File

@@ -7,6 +7,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.FileProvider;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.util.Log; import android.util.Log;
@@ -14,6 +15,7 @@ import com.stardust.autojs.annotation.ScriptInterface;
import com.stardust.util.IntentUtil; import com.stardust.util.IntentUtil;
import com.stardust.util.MimeTypes; import com.stardust.util.MimeTypes;
import java.io.File;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.List; import java.util.List;
@@ -92,6 +94,10 @@ public class AppUtils {
return IntentUtil.goToAppDetailSettings(mContext, packageName); return IntentUtil.goToAppDetailSettings(mContext, packageName);
} }
public String getFileProviderAuthority() {
return mFileProviderAuthority;
}
@Nullable @Nullable
public Activity getCurrentActivity() { public Activity getCurrentActivity() {
Log.d("App", "getCurrentActivity: " + mCurrentActivity.get()); Log.d("App", "getCurrentActivity: " + mCurrentActivity.get());

View File

@@ -150,7 +150,6 @@ public class IntentUtil {
return false; return false;
} }
} }
} }
public static boolean viewFile(Context context, String path, String mimeType, String fileProviderAuthority) { public static boolean viewFile(Context context, String path, String mimeType, String fileProviderAuthority) {