fix flash when launch a shortcut
This commit is contained in:
@@ -7,7 +7,9 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.stardust.autojs.runtime.ScriptInterface;
|
||||
import com.stardust.util.IntentUtil;
|
||||
@@ -15,6 +17,8 @@ import com.stardust.util.IntentUtil;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
import static com.stardust.pio.PFile.getExtension;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/2.
|
||||
*/
|
||||
@@ -55,7 +59,7 @@ public class AppUtils {
|
||||
return applicationInfo.processName;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
@@ -75,6 +79,40 @@ public class AppUtils {
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public void viewFile(String path) {
|
||||
if (path == null)
|
||||
throw new NullPointerException("path == null");
|
||||
path = "file://" + path;
|
||||
String ext = getExtension(path);
|
||||
String mimeType = TextUtils.isEmpty(ext) ? "*/*" : MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
|
||||
mContext.startActivity(new Intent(Intent.ACTION_VIEW)
|
||||
.setDataAndType(Uri.parse(path), mimeType)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public void editFile(String path) {
|
||||
if (path == null)
|
||||
throw new NullPointerException("path == null");
|
||||
path = "file://" + path;
|
||||
String ext = getExtension(path);
|
||||
String mimeType = TextUtils.isEmpty(ext) ? "*/*" : MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
|
||||
mContext.startActivity(new Intent(Intent.ACTION_EDIT)
|
||||
.setDataAndType(Uri.parse(path), mimeType)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@ScriptInterface
|
||||
public void openUrl(String url) {
|
||||
if (!url.startsWith("http://") || !url.startsWith("https://")) {
|
||||
url = "http://" + url;
|
||||
}
|
||||
mContext.startActivity(new Intent(Intent.ACTION_VIEW)
|
||||
.setData(Uri.parse(url))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
public void setCurrentActivity(Activity currentActivity) {
|
||||
mCurrentActivity = new WeakReference<>(currentActivity);
|
||||
Log.d("App", "setCurrentActivity: " + currentActivity);
|
||||
|
||||
Reference in New Issue
Block a user