navigator add openUrl

This commit is contained in:
pengfei.zhou
2020-04-01 15:19:37 +08:00
committed by osborn
parent 9c520e1dc5
commit 78d4f51314
12 changed files with 78 additions and 13 deletions

View File

@@ -15,6 +15,9 @@
*/
package pub.doric.plugin;
import android.content.Intent;
import android.net.Uri;
import com.github.pengfeizhou.jscore.ArchiveException;
import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JSObject;
@@ -84,4 +87,17 @@ public class NavigatorPlugin extends DoricJavaPlugin {
promise.reject(new JavaValue("Navigator not implemented"));
}
}
@DoricMethod(thread = ThreadMode.UI)
public void openUrl(String url, DoricPromise promise) {
try {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
getDoricContext().getContext().startActivity(intent);
promise.resolve();
} catch (Exception e) {
promise.reject(new JavaValue(e.getLocalizedMessage()));
}
}
}