[Q] help on eclipse app - Android Software Development

Hi guys,
First of all i`m completly noob on this so don`t be much hard with me
ok. i`m trying to develop a simple app just to run 4 simple command to install another app but for now the only thing that i can get to work was asking for su permissions...
can someone help me with this?
Thks a lot
HTML:
try {
runtime.exec("su -c busybox mount -o rw,remount /system");
runtime.exec("cp /sdcard/gscript/xrecovery.sh /data/local/tmp/xrecovery.sh");
runtime.exec("chmod 777 /data/local/tmp/xrecovery.sh");
runtime.exec("/data/local/tmp/xrecovery.sh");
runtime.exec("reboot");
}
catch (IOException e) {
e.printStackTrace();

do not think anyone has the knowledge to help me: .- (
My intention is to create a simple program that installs a file which is in sh sdcard,
"sdcard / gscript / xrecovery.sh"
until now could only be granted access to the root but do not know where and what command should I put to run that sh file...
is that no one can / want help?
thks
HTML:
import java.io.DataOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class xRecovery extends Activity {
Button app_name;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app_name = (Button)findViewById(R.id.TextView01);
xRecovery.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {;
}
});
setContentView(R.layout.main);
try {
Runtime.getRuntime().exec("/sdcard/gscript/xrecovery.sh");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
{
os.writeBytes("mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system\n" +
"exit \n");
os.flush();
process.waitFor();
}
Runtime.getRuntime().exec("/sdcard/gscript/xrecovery.sh");
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
protected String[] getPackageResourcePath(String string) {
// TODO Auto-generated method stub
return null;
}
private static void setOnClickListener(OnClickListener onClickListener) {
// TODO Auto-generated method stub
}
}

You should be able to execute a .sh file by using:
Code:
sh xrecovery.sh

spolfliet said:
You should be able to execute a .sh file by using:
Code:
sh xrecovery.sh
Click to expand...
Click to collapse
Without sdcard path! ?
And where should i put?
Thks; )
Sent from my AOSP on Xperia (US) using XDA App

Of course you need to specify the path (it cannot guess where your script is, unless you add it to your PATH). So I guess the following should work for you:
Code:
Runtime.getRuntime().exec("sh /sdcard/gscript/xrecovery.sh");

Unfortunely i cant make this work UK sure that im putting the command Sony the wrong place. I've allready try put Sony a different pplaces but never work: (
Thks anyway; )
Sent from my AOSP on Xperia (US) using XDA App

really need help!
here is my complete code for what i want to do
HTML:
package com.rendeiro2005.xRecovery;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class xRecovery extends Activity {
Button INSTALL;
Button REMOVE;
AlertDialog.Builder builder;
AlertDialog Alert;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
Process process = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(process.getOutputStream());
DataInputStream inputStream = new DataInputStream(process.getInputStream());
outputStream.writeBytes("\n");
outputStream.flush();
outputStream.writeBytes("exit\n");
outputStream.flush();
process.waitFor();
process.waitFor();
if (process.exitValue() != 255) {
toastMessage("root");
}
else {
toastMessage("not root");
}
}
catch (IOException e)
{
try {
throw new Exception(e);
} catch (Exception e1) {
e1.printStackTrace();
}
}
catch (InterruptedException e)
{
try {
throw new Exception(e);
} catch (Exception e1) {
e1.printStackTrace();
}
}
INSTALL = (Button)findViewById(R.id.Button01);
REMOVE = (Button)findViewById(R.id.Button02);
builder = new AlertDialog.Builder(this);
builder.setMessage("Do you want to install xRecovery?");
builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
Runtime.getRuntime().exec("sh /sdcard/gscript/xrecovery.sh");
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(getApplicationContext(),
"Done",
Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
Alert = builder.create();
INSTALL.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Alert.show();
}
});
REMOVE.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
}
});
}
private void toastMessage(String string) {
}
}
i haven`t donne the uninstall part.
the problem here is everything work as it should exept the "sh" doesn`t do anything.
can anyone help me with this? i`m just trying to understand how the process works
thks a lot

Related

Problem of flashlight app code (Eclipse)

Hello everyone ..
I have problem on developing a flashlight app
I tried the solutions that provided by Eclipse but none solved the problem
or even make any sense to me :angel:
every "Void" statement on the code appeared as an error
and i don't know why .. also i'm sure that everything on the code is correct
Examples of the errors:
private void playSound() {
private void toggleButtonImage() {
private void turnOffFlash() {
and .. etc , i got an error on every "Void" !
so.. i'm waiting for your opinions
Thanks in advance )​
Hi,
It is impossible for us to tell you what you have done wrong if you do not post your source code.
It could be just one character missing somewhere or one to much.
We need your code to help you.
(If you do not want to release it completely, copy your project and remove those parts you do not want us to see. This could also help you with finding the error yourself. )
nikwen said:
Hi,
It is impossible for us to tell you what you have done wrong if you do not post your source code.
It could be just one character missing somewhere or one to much.
We need your code to help you.
(If you do not want to release it completely, copy your project and remove those parts you do not want us to see. This could also help you with finding the error yourself. )
Click to expand...
Click to collapse
Thanks 4 answering me nikwen
i tried to post a screenshot of the problem but i'm a new member in the forum so i couldn't post an external link
anyway .. here's the Code
package com.mohamedsherif.flashlighttorch;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ToggleButton;
public class MainActivity extends Activity {
ImageButton switchButton;
private Camera camera;
private boolean isFlashOn;
private boolean hasFlash;
Parameters params;
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.switchButton);
//Check if the Device has Flash
hasFlash = getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if(!hasFlash) {
AlertDialog alert = new AlertDialog.Builder(MainActivity.this).create();
alert.setTitle("Error! ");
alert.setMessage("Sorry! .. Your device doesn't have a flash!");
alert.setButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
finish();
}
});
alert.show();
return;
}
//Getting camera parameters
private void getCamera() {
if (camera == null) {
try {
camera = Camera.open();
params = camera.getParameters();
} catch (RuntimeException e) {
Log.e("Camera Error. Failed to open. Error", e.getMessage());
}
}
}
private void turnOnFlash() {
if (!hasFlash) {
if (camera == null || params == null) {
return;
}
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
isFlashOn = true;
toggleButtonImage();
}
}
//Turning off flash
private void turnOffFlash() {
if (isFlashOn) {
if (camera == null || params == null) {
return;
}
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
isFlashOn = false;
toggleButtonImage();
}
};
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isFlashOn) {
turnOffFlash();
} else {
turnOnFlash();
}
}
});
// Toggle buttons images
private void toggleButtonImage() {
if (isFlashOn) {
switchButton.setImageResource(R.drawable.switch_on);
} else {
switchButton.setImageResource(R.drawable.switch_off);
}
}
// Playing Sound
private void playSound() {
if (isFlashOn) {
mp = MediaPlayer.create(MainActivity.this, R.raw.light_switch_off);
} else {
mp = MediaPlayer.create(MainActivity.this, R.raw.light_switch_on);
}
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
mp.start();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Click to expand...
Click to collapse
the errors are in RED ​
little changes
private static Camera camera;
private boolean isFlashOn;
private boolean hasFlash;
Parameters params;
MediaPlayer mp;
ToggleButton switchButton;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flashlight);
getCamera();
switchButton = (ToggleButton) findViewById(R.id.tglOnOffFlashlight);
switchButton.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
if (isFlashOn) {
turnOffFlash();
} else {
turnOnFlash();
}
}
});
//Check if the Device has Flash
hasFlash = getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if(!hasFlash) {
AlertDialog alert = new AlertDialog.Builder(FlashlightActivity.this).create();
alert.setTitle("Error! ");
alert.setMessage("Sorry! .. Your device doesn't have a flash!");
alert.setButton("ok", new DialogInterface.OnClickListener() {
@override
public void onClick(final DialogInterface dialog, final int which) {
finish();
}
});
alert.show();
return;
}
}
//Getting camera parameters
private void getCamera() {
if (camera == null) {
try {
camera = Camera.open();
params = camera.getParameters();
} catch (RuntimeException e) {
Log.e("Camera Error. Failed to open. Error", e.getMessage());
}
}
}
private void turnOnFlash() {
if (hasFlash) {
if (camera == null || params == null) {
return;
}
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
isFlashOn = true;
toggleButtonImage();
}
}
//Turning off flash
private void turnOffFlash() {
if (isFlashOn) {
if (camera == null || params == null) {
return;
}
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
isFlashOn = false;
toggleButtonImage();
}
}
// Toggle buttons images
private void toggleButtonImage() {
if (isFlashOn) {
switchButton.setBackgroundResource(R.drawable.on_yellow );
} else {
switchButton.setBackgroundResource(R.drawable.off_white);
}
}
// Playing Sound
private void playSound() {
if (isFlashOn) {
mp = MediaPlayer.create(FlashlightActivity.this, R.raw.light_switch_off);
} else {
mp = MediaPlayer.create(FlashlightActivity.this, R.raw.light_switch_on);
}
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
mp.start();
}
these work
Does it work on other projects?
It is working for him, so I guess that the errors are not in the code but maybe your project setup or your installation of Eclipse and the Android SDK is the reason for that.
So to quote myself " Does it work on other projects?".
---------- Post added at 09:59 PM ---------- Previous post was at 09:55 PM ----------
Oh no, there are mistakes with the brackets.
For example you set a listener somewhere inside a methods. However, you forgot to close the bracket (I mean these ones {}). So it ends with a semicolon. It wants more lines of code.
So check your brackets.
Void methods should not return anything. So you can remove all 'return' words in the void methods.
Sent from my NexusHD2 using xda app-developers app
Eztys said:
Void methods should not return anything. So you can remove all 'return' words in the void methods.
Sent from my NexusHD2 using xda app-developers app
Click to expand...
Click to collapse
These returns ARE allowed. They are not necessary but allowed. You can stop the method by this.
It is really a problem with these brackets {}.
krsln said:
private static Camera camera;
private boolean isFlashOn;
private boolean hasFlash;
Parameters params;
MediaPlayer mp;
ToggleButton switchButton;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flashlight);
getCamera();
switchButton = (ToggleButton) findViewById(R.id.tglOnOffFlashlight);
switchButton.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
if (isFlashOn) {
turnOffFlash();
} else {
turnOnFlash();
}
}
these work
Click to expand...
Click to collapse
the same problem with the Void errors !! -.-
nikwen said:
Does it work on other projects?
It is working for him, so I guess that the errors are not in the code but maybe your project setup or your installation of Eclipse and the Android SDK is the reason for that.
So to quote myself " Does it work on other projects?".
---------- Post added at 09:59 PM ---------- Previous post was at 09:55 PM ----------
Oh no, there are mistakes with the brackets.
For example you set a listener somewhere inside a methods. However, you forgot to close the bracket (I mean these ones {}). So it ends with a semicolon. It wants more lines of code.
So check your brackets.
Click to expand...
Click to collapse
i tried the code on a new project but i got the same errors
also i don't think there's any problem with the brackets ?
Eztys said:
Void methods should not return anything. So you can remove all 'return' words in the void methods.
Sent from my NexusHD2 using xda app-developers app
Click to expand...
Click to collapse
the return is not the problem ​
i just solved the void errors but the app is not running on the virtual device !
"the app has stopped unexpectedly"
can anyone try the code ? or even tell me what's wrong ?
BTW the code doesn't contain any errors now .. not even the void errors
package com.mohamedsherif.flashlighttorch;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
public class MainActivity extends Activity {
ImageButton switchButton;
private Camera camera;
private boolean isFlashOn;
private boolean hasFlash;
Parameters params;
MediaPlayer mp;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.switchButton);
//Check if the Device has Flash
hasFlash = getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if(!hasFlash) {
AlertDialog alert = new AlertDialog.Builder(MainActivity.this).create();
alert.setTitle("Error! ");
alert.setMessage("Sorry! .. Your device doesn't have a flash!");
alert.setButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
finish();
}
});
alert.show();
return;
}
getCamera();
toggleButtonImage();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isFlashOn) {
turnOffFlash();
} else {
turnOnFlash();
}
}
});
}
//Getting camera parameters
private void getCamera() {
if (camera == null) {
try {
camera = Camera.open();
params = camera.getParameters();
} catch (RuntimeException e) {
Log.e("Camera Error. Failed to open. Error: ", e.getMessage());
}
}
}
private void turnOnFlash() {
if (!hasFlash) {
if (camera == null || params == null) {
return;
}
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
isFlashOn = true;
toggleButtonImage();
}
}
//Turning off flash
private void turnOffFlash() {
if (isFlashOn) {
if (camera == null || params == null) {
return;
}
playSound();
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
isFlashOn = false;
toggleButtonImage();
}
};
// Toggle buttons images
private void toggleButtonImage() {
if (isFlashOn) {
switchButton.setImageResource(R.drawable.switch_on);
} else {
switchButton.setImageResource(R.drawable.switch_off);
}
}
// Playing Sound
private void playSound() {
if (isFlashOn) {
mp = MediaPlayer.create(MainActivity.this, R.raw.light_switch_off);
} else {
mp = MediaPlayer.create(MainActivity.this, R.raw.light_switch_on);
}
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
mp.start();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
turnOffFlash();
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if (hasFlash)
turnOnFlash();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
getCamera();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
if (camera != null) {
camera.release();
camera = null;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Click to expand...
Click to collapse
M. Sherif said:
i just solved the void errors but the app is not running on the virtual device !
"the app has stopped unexpectedly"
can anyone try the code ? or even tell me what's wrong ?
BTW the code doesn't contain any errors now .. not even the void errors
​
Click to expand...
Click to collapse
There will be a logcat. Post it here.

[NEWBIE] App is crashing, Please Help....

Code:
package com.example.dolaog;
import android.location.GpsStatus.Listener;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.os.Handler;
public class MainActivity extends Activity implements OnClickListener {
Button b, b2, b3;
View a;
ProgressDialog d;
Handler handler;
Thread t = new Thread() {
public void run() {
// TODO Auto-generated method stub
try {
sleep(5000);
handler.post(new Runnable() {
public void run() {
d.dismiss();
}
});
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
protected void onCreate(Bundle savedInstanceState) {
handler = new Handler();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = (Button) findViewById(R.id.button1);
b3 = (Button) findViewById(R.id.button3);
b2 = (Button) findViewById(R.id.button2);
b.setOnClickListener(this);
b2.setOnClickListener(this);
b3.setOnClickListener(this);
}
public void onClick(View arg0) {
switch (arg0.getId()) {
case R.id.button1:
showDialog(0);
break;
case R.id.button2:
d = ProgressDialog.show(this, "Initialising", " Please wait...",
true);
t.start();
break;
case R.id.button3:
showDialog(1);
d.setProgress(0);
new Thread(new Runnable() {
public void run() {
for (int i = 1; i <= 15; i++) {
try {
// ---simulate doing something lengthy---
Thread.sleep(1000);
// ---update the dialog---
d.incrementProgressBy((int) (100 / 15));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
d.dismiss();
}
}).start();
break;
}
}
protected Dialog onCreateDialog(int g) {
Builder b = new AlertDialog.Builder(this);
switch (g) {
case 0:
b.setIcon(R.drawable.ic_launcher);
b.setTitle("From Crazyandroidgalaxy, please hit me !!");
b.setPositiveButton("asd", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(),
"I am Tanmay aka Crazyandroidgalaxy admin!",
Toast.LENGTH_LONG).show();
}
});
return b.create();
case 1:
d.setIcon(R.drawable.ic_launcher);
d.setTitle("Downloading");
d.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
d.setButton(DialogInterface.BUTTON_POSITIVE, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
Toast.makeText(getBaseContext(), "OK clicked",
Toast.LENGTH_SHORT).show();
}
});
d.setButton(DialogInterface.BUTTON_NEGATIVE, "cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
Toast.makeText(getBaseContext(), "cancel clicked",
Toast.LENGTH_SHORT).show();
}
});
return d;
}
return null;
}
}
________________
Obviously, the above code is not working. The app is crashing, when i click the b3 button...
Please help me out!
Thanks in advance...
Please read this to help yourself: [GUIDE] Debugging apps
At least read this for posting your problem on XDA: http://forum.xda-developers.com/showpost.php?p=42601921&postcount=9
---------- Post added at 01:24 PM ---------- Previous post was at 12:51 PM ----------
You cannot modify the UI/ dismiss a dialog from another thread.
Use a Handler and its post method.
However, please read the debugging thread. After reading that, you would have easily figured out what is wrong.
nikwen said:
Please read this to help yourself: [GUIDE] Debugging apps
At least read this for posting your problem on XDA: http://forum.xda-developers.com/showpost.php?p=42601921&postcount=9
---------- Post added at 01:24 PM ---------- Previous post was at 12:51 PM ----------
You cannot modify the UI/ dismiss a dialog from another thread.
Use a Handler and its post method.
However, please read the debugging thread. After reading that, you would have easily figured out what is wrong.
Click to expand...
Click to collapse
Oh! thanks. I completely forgot about the last correction you made, in my code

[Q] How to use xposed framework replace resource on nexus4?

I try this but not work something wrong?
Code:
package de.robv.android.xposed.mods.tutorial;
import de.robv.android.xposed.IXposedHookInitPackageResources;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.callbacks.XC_InitPackageResources.InitPackageResourcesParam;
public class tutorial implements IXposedHookZygoteInit, IXposedHookInitPackageResources {
[user=439709]@override[/user]
public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) throws Throwable {
}
[user=439709]@override[/user]
public void handleInitPackageResources(InitPackageResourcesParam resparam) throws Throwable {
// replacements only for SystemUI
if (!resparam.packageName.equals("com.pureexe.lol"))
return;
resparam.res.setReplacement("com.pureexe.lol", "string", "bundle", "Hello!");
}
}

[Q] rmtp / mms player

hi friends
i can't play rtmp or mss protocol in android project (just audio live stream )
my code :
Code:
package sample.media.player;
import java.io.IOException;
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
public class SampleMediaPlayerActivity extends Activity implements OnErrorListener, OnPreparedListener {
private MediaPlayer player;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
player.setDataSource("rtmp://199.103.63.202/live&file=irib3"); // rtmp link
player.setOnErrorListener(this);
player.setOnPreparedListener(this);
player.prepareAsync();
}
catch (IllegalArgumentException e) {
e.printStackTrace();
}
catch (IllegalStateException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
[user=439709]@override[/user]
public void onDestroy() {
super.onDestroy();
player.release();
player = null;
}
[user=439709]@override[/user]
public void onPrepared(MediaPlayer play) {
play.start();
}
[user=439709]@override[/user]
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
return false;
}
}
please help me / thanks:good:
Is it crashing or does it do nothing? Logcat?
LogCat:
Level : E
PID : 222
Application : Simple.Media.Player
Tag : MediaPlayer
Text : Error(1,-1)
help me plzzzzzzzzzzzz
nobodyyyyyy ????
takname said:
LogCat:
Level : E
PID : 222
Application : Simple.Media.Player
Tag : MediaPlayer
Text : Error(1,-1)
Click to expand...
Click to collapse
There should be more log code which is important. In every case there should be an Exception which is thrown.
I just found this library: http://www.aftek.com/afteklab/aftek-RTMP-library.shtml
Might be helpful.
(Both formats are not natively supported by the Android platform: http://developer.android.com/guide/appendix/media-formats.html)

[Q] Copy Image from Gallery Share (Send To) menu

Moderators... It says I am breaking the rules by asking a question and to ask in the Q&A... But the title of this is "Coding Discussion, Q&A, and Educational Resources" I am not breaking the rules intentionally, I just don't know where else to put this. This is a Coding Question, not a General Question that I would think would get buried and or lost in the General Q&A forum. Please move if you feel I am incorrect.
Hello All, I was hoping someone could help me.
I am trying to create an app that will hide pictures. I want to be able to Pick my App from the Share (Send To) menu from the Users Gallery and have it copy the file to a Directory I have created on my SDCard and then ultimately delete the file from the current location.
Here is what I have so far, but when I pick my app from the Share menu, it crashes the Gallery app. So... I can't even see any errors in my LogCat to even try and troubleshoot my issue.
Can someone point me to a working example of how to do this (I have searched the internet until I am blue in the face) or... I hate to say it... Fix my Code?
Any Help would be appreciated... Thanks!!
Code:
package com.company.privitegallery;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
public class SendToDo extends Activity {
File sdCardLoc = Environment.getExternalStorageDirectory();
File intImagesDir = new File(sdCardLoc,"/DCIM/privgal/.nomedia");
private static final int CAMERA_REQUEST = 1888;
private String selectedImagePath;
String fileName = "capturedImage.jpg";
private static Uri mCapturedImageURI;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
} else if (type.startsWith("image/")) {
handleSendImage(intent); // Handle single image being sent
try {
GetPhotoPath();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
if (type.startsWith("image/")) {
handleSendMultipleImages(intent); // Handle multiple images being sent
}
} else {
// Handle other intents, such as being started from the home screen
}
//...
}
void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// Update UI to reflect text being shared
}
}
void handleSendImage(Intent intent) {
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
// Update UI to reflect image being shared
}
}
void handleSendMultipleImages(Intent intent) {
ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (imageUris != null) {
// Update UI to reflect multiple images being shared
}
}
public void GetPhotoPath() throws IOException {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
copy(fileName, intImagesDir);
}
[user=439709]@override[/user]
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == CAMERA_REQUEST) {
selectedImagePath = getPath(mCapturedImageURI);
Log.v("selectedImagePath: ", ""+selectedImagePath);
//Save the path to pass between activities
try {
copy(selectedImagePath, intImagesDir);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
public void copy(String scr, File dst) throws IOException {
InputStream in = new FileInputStream(scr);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
private void deleteLatest() {
// TODO Auto-generated method stub
File f = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera" );
//Log.i("Log", "file name in delete folder : "+f.toString());
File [] files = f.listFiles();
//Log.i("Log", "List of files is: " +files.toString());
Arrays.sort( files, new Comparator<Object>()
{
public int compare(Object o1, Object o2) {
if (((File)o1).lastModified() > ((File)o2).lastModified()) {
// Log.i("Log", "Going -1");
return -1;
} else if (((File)o1).lastModified() < ((File)o2).lastModified()) {
// Log.i("Log", "Going +1");
return 1;
} else {
// Log.i("Log", "Going 0");
return 0;
}
}
});
//Log.i("Log", "Count of the FILES AFTER DELETING ::"+files[0].length());
files[0].delete();
}
}
What's the gallery log output?
Btw, you're not breaking the rules. This is the right forum for Java Q&A.
nikwen said:
What's the gallery log output?
Click to expand...
Click to collapse
How would I get the Logs for the Gallery? I am using and HTC ONE and it's the standard Gallery. Nothing shows up in LogCat so I'm stuck
nikwen said:
Btw, you're not breaking the rules. This is the right forum for Java Q&A.
Click to expand...
Click to collapse
Great, Thanks!!
StEVO_M said:
How would I get the Logs for the Gallery? I am using and HTC ONE and it's the standard Gallery. Nothing shows up in LogCat so I'm stuck
Great, Thanks!!
Click to expand...
Click to collapse
Do you view the logs on your computer?
There should be an error message in the logs.
nikwen said:
Do you view the logs on your computer?
There should be an error message in the logs.
Click to expand...
Click to collapse
Which Logs?? As I said before. LogCat does not give any errors.

Categories

Resources