In a program I am developing using jcef, I want to allow the camera to be used inside. I am trying to give --enable-media-stream switch for the program that I am building using jcef. I am tried to turn on switch with the following cases:
settings.windowless_rendering_enabled = useOSR;
settings.command_line_args_disabled = false;
String[] args = new String[]{
"--enable-media-stream=true"
// "--enable-media-steam",
// "enable-media-stream", "1"
};
cefApp = CefApp.getInstance(args, settings);
Program gives
[1031/094701.279:INFO:CONSOLE(0)] "Uncaught (in promise) NotAllowedError: Permission denied", source: theUrl
error in every cases.
However, the camera is allowed if I run *.jar app from command line with: "java -jar appName.jar --enable-media-stream" command.
What might be the issue here?
Thanks in advance.
I solved it with next code:
CefApp.addAppHandler(new CefAppHandlerAdapter(null) {
#Override
public void onBeforeCommandLineProcessing(String process_type, CefCommandLine command_line) {
super.onBeforeCommandLineProcessing(process_type, command_line);
if (process_type.isEmpty()) {
command_line.appendSwitchWithValue("enable-media-stream","true");
}
}
});
Related
I have written a piece of software that requires me to open and close an executable jar file.
At the moment I have the code able to open the jar with specific arguments
(I have used notepad in the code example as I do not have the Jar file or my original code on me, and needed to test what I had written for this example worked)
The issue I have is when I open and close notepad I get the correct behaviour, however when I try to close my JAR file I am not getting a response.
I have tried killing by the process name under task manager - go to details, the app name, and variants of java, java.exe, javaw etc.
Is it something to do with having launched the jar through CMD?
in which case I have another issue because I have several processes with the exact same name and am not sure how to get the ID when the name is the same.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
// Click on the link below to continue learning how to build a desktop app using WinForms!
System.Diagnostics.Process.Start("http://aka.ms/dotnet-get-started-desktop");
}
//string jarFile = "/JarLocation";
//string jsonlocation = "/jsonlocation";
//string command = $"java - jar {jarfile} -qsArgs {jsonLocation}";
string command = "Notepad";
string processName = "Notepad";
List<int> processIDs = new List<int>();
int[] processID;
Thread testThread;
ThreadStart ts;
private void RunButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Running!");
// METHOD 1 // Launch through CMD directly (in a new thread and try to terminate by process name)
/*
new Thread(() =>
{
LaunchClient();
}).Start();
*/
// METHOD 2 // Generate
/*
foreach (int ID in processIDs)
{
Console.WriteLine($"Process {ID} Created");
}
*/
//Method 3
/*
testThread = new Thread(new ThreadStart(LaunchClient()));
//testThread.Start();
*/
// Method 4
ts = delegate { LaunchClient(); };
}
private void KillButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Killing!");
try
{
// Method 1
Process[] ProcList = Process.GetProcessesByName(processName);
foreach (Process targetProc in ProcList)
{
targetProc.CloseMainWindow();
}
// Method 2
/*
foreach (int ID in processIDs)
{
Process killMe = Process.GetProcessById(ID);
killMe.CloseMainWindow();
}
*/
// Method 3
//testThread.Abort();
//Method 4
//ts.EndInvoke();
}
catch (Exception f)
{
Console.WriteLine("f.StackTrace");
}
}
public void LaunchClient()
{
Thread.CurrentThread.IsBackground = false;
Process proc = new Process();
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardInput = true;
//proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.StandardInput.WriteLine(command);
proc.StandardInput.Flush();
Console.WriteLine($"PROCESS ID: {proc.Id}");
processIDs.Add(proc.Id);
//proc.StandardInput.Close();
proc.WaitForExit();
}
}
Sorry to dump a large swathe of code but I thought seeing my implementation of the opening as well as the close would help.
EDIT:
Updated the code sample given to show the 4 different ways I have tried to handle this.
Method 1:
Closing process by name (works for notepad, but not my jar)
2: Trying to pass the process ID back and use that to close the process
(Cant see the ID outside of the thread running the cmd window)
3: using new threadstart (launchclient says 'method name expected')
4: Doesn't open Notepad at all.
If your JAR file is opened with your code, an useful technique is to listen for windowClosing, which happens when the user clicks the X button on Windows (and the equivalent on other systems):
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
I made spark+hadoop yarn enviroment and spark-submit command works well. So I made SparkLauncher java code to do this in my application jar, BUT somehow it doesn't work (actually computer fan is spinning at first but not as long as i did with spark-submit.)
It seems not work well (no application log in hadoop web ui, unlike spark-submit). I cannot see any error log when I do with 'SparkLauncher'. without log message, I can do nothing with it.
Here is how I made it so far.
public class Main {
public static void main(String[] args) {
Process spark = null;
try
{
spark = new SparkLauncher()
.setAppResource("/usr/local/spark/examples/jars/spark-examples*.jar")
.setMainClass("org.apache.spark.examples.SparkPi")
.setMaster("yarn")
.setDeployMode( "cluster")
.launch();
}
catch( IOException e)
{
e.printStackTrace();
}
}
}
executed it with ( java -jar example.jar)
I had the same problem at first. I think the main issue is that you forgot about the waitFor().
Also, it's really helpfull to extract your errorMessage and deal with it (e.g. log it or checking it while debuging ) within your java code. To allow this, you should create a streamReader thread as follows:
InputStreamReaderRunnable errorStreamReaderRunnable = new InputStreamReaderRunnable(spark.getErrorStream(), "error");
Thread errorThread = new Thread(errorStreamReaderRunnable, "LogStreamReader error");
errorThread.start();
int result= spark.waitFor();
if(result!=0) {
String errorMessage = extractExceptionMessage(errorStreamReaderRunnable.getMessage());
LOGGER.error(errorMessage);
}
This should be after your launch() command and inside your try block. Hope it helps
I am attempting to integrate the Dropbox chooser drop-in api into my application. I am running into an abnormal issue. In my app when I launch the dbx chooser, anytime that I select a file the application fails with the following error code:
Sorry, an error has occurred. Please try again later.
Here is the portion of my code that implements the Dropbox API. This portion of the code is where the dropbox api is initially invoked.
public void StartDropboxApplication() {
// create the chooser
DbxChooser chooser = new DbxChooser(APP_KEY);
DbxChooser.ResultType result;
// determine which mode to be in // TODO REMOVE ALL BUT FILE CONTENT TODO SIMPLIFY by making this a setting
switch(( (RadioGroup) ParentActivity.findViewById(R.id.link_type)).getCheckedRadioButtonId() ) {
case R.id.link_type_content:
result = DbxChooser.ResultType.DIRECT_LINK;
break;
default:
throw new RuntimeException("Radio Group Related error.");
}
// launch the new activity
chooser.forResultType(result).launch(ParentActivity, 0);
}
Here is the position where the code should then pick it up although it never does.
protected void onActivityResult( int request, int result, Intent data ) {
Log.i(fileName, "result: " + result);
// check to see if the camera took a picture
if (request == 1) {
// check to see if the picture was successfully taken
if (result == Activity.RESULT_OK) {
onPicture();
} else {
Log.i(fileName, "Camera App cancelled.");
}
} else if (request == 0) {
if ( result == Activity.RESULT_OK ) {
onDropbox(data);
} else {
Log.i(fileName, "dropbox related issue.");
}
}
}
Thank you for any help or suggestions that you are able to provide.
I was able to solve my own issues and get this working. On the off chance that someone else has a similar problem I will detail the solution. The first issue was I was that my APP_KEY was incorrect.
The next issue was that I was attempting to read from a direct link instead of a content link. The direct link provides the application with a link to the file on the Dropbox server whereas the content link provides the application with a cached version of the file. If the file is not present on the device, the SDK downloads a copy for you.
I'm developing a simple app that injects lines on build.prop by executing a shell command. My main problem is that every time I check a toggle that create the function a toast displaying the shell string appear. Is there any way to avoid this? also, if you have any suggestion to clean a bit the code would be appreciated! (First app for me).
Code:
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
// fragment not when container null
if (container == null) {
return null;
}
// inflate view from layout
View v = (LinearLayout)inflater.inflate(R.layout.performance,container,false);
final CheckBox hwdebug = (CheckBox) v.findViewById(R.id.hwDebug);
final String[] mountrw = {"su","-c","mount -o remount,rw /system"};
final String[] enhwdebug1 = {"su","-c","sed -i '/debug.sf.hw=*/d' /system/build.prop"};
final String[] enhwdebug2 = {"su","-c","echo '## Rendering GPU Enabled ##' >> /system/build.prop"};
final String[] enhwdebug3 = {"su","-c","echo debug.sf.hw=1 >> /system/build.prop"};
final String[] dishwdebug1 = {"su","-c","sed -i '/debug.sf.hw=1/d' /system/build.prop"};
final String[] dishwdebug2 = {"su","-c","sed -i '/## Rendering GPU Enabled ##/d' /system/build.prop"};
final SharedPreferences hwdebugpref = this.getActivity().getSharedPreferences("hwdebugck",0);
// GPU Rendering Checkbox
boolean hwdebugck = hwdebugpref.getBoolean("hwdebugck", false);
if (hwdebugck) {
hwdebug.setChecked(true);
} else {
hwdebug.setChecked(false);
}
hwdebug.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if((hwdebug.isChecked())) {
SharedPreferences.Editor editor = hwdebugpref.edit();
editor.putBoolean("hwdebugck", true); // value to store
editor.commit();
ArrayList<String[]> enhwdebug = new ArrayList<String[]>();
enhwdebug.add(mountrw);
enhwdebug.add(enhwdebug1);
enhwdebug.add(enhwdebug2);
enhwdebug.add(enhwdebug3);
for(String[] cmd:enhwdebug){
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.fillInStackTrace();
}
}
} else {
SharedPreferences.Editor editor = hwdebugpref.edit();
editor.putBoolean("hwdebugck", false); // value to store
editor.commit();
ArrayList<String[]> diswdebug = new ArrayList<String[]>();
diswdebug.add(mountrw);
diswdebug.add(dishwdebug1);
diswdebug.add(dishwdebug2);
for(String[] cmd:diswdebug){
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.fillInStackTrace();
}
}
}
}
});
So, my main problem is that su -c show that annoying toast. I tried to pass it to busybox or toolbox but without success since they need to be ran with su.
Thank you!
It is possible , by having the same thread that makes the call to root commands stay and let it always be the only one that handles them.
This way, the toast will only appear the first time you use root operations.
Also, on the end user side, some apps (like super-su) allow to avoid the toast, even per app.
Ok first to answer your question the answer is yes and no.
Easy Answer:
No its not possible using one of the current SU managers like SuperUser or SuperSU you cant. The toast is a safety mechanism. Both apps features to remove the toast for specific apps, but you as a dev can not control this.
Hard Answer:
Yes it is possible, but it would require you compiling your own su binary and using it in place of the su binary already installed. You would need to remove the code that references the current manager (Which ever source you compiled from). Would be recommend to add checks so that ONLY your app can run that binary. This can lead to security risks though and is probably is not a good idea.
I did not look through your code very much but i would say one thing do NOT under any circumstance run SU commands on the UI thread. This is only asking for problems.
Ok I'm learning how shell commands work, so I decided to develop a app to send the commands. This is what I got.
moveDirectory.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
try{
Process send = Runtime.getRunetime().exec(new String[] {"cd /sdcard/music/", "cp pic1 /sdcard/pic1"});
send.waitFor();
} catch (Exception ex){
String toast = null;
Log.i(toast, "Couldn't copy file", ex);
}
}
});
But it isn't working, the first command is working, but not the second one. What should I add to it?
Thanks
EDIT: forgot to add the send.waitFor(); line
Use normal command delimeter ;
moveDirectory.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
try{
Process send = Runtime.getRunetime().exec(new String[] {"cd /sdcard/music/ ; cp pic1 /sdcard/pic1"});
} catch (Exception ex){
String toast = null;
Log.i(toast, "Couldn't copy file", ex);
}
}
});
In this code you
1) go to the /sdcard/music
2) copy from /sdcard/music pic1 to /sdcard/pic1
I'm speculating, but you may have misunderstood what the parameter to exec really is. It's not a list of commands to be executed (effectivly a batch/shell script), but a single command WITH it's arguments to be executed by a shell. Making it a one-liner like Pepelac suggests or putting the series of commands into a single file that you execute with exec later may be what you are looking for. For the command you are trying to execute there is absolute no reason why you can not make it a one-liner with the full source path included (instead of changing to it), but there may be other reasons why you need to do this that you have not mentioned.