[Q]Phone reboot after executing a script - Android Software/Hacking General [Developers Only]

Hi, i was developing a tasker and to kill the apps i was using this script
Code:
String command = "pidof -s " + intent.getComponent().getPackageName() + " | kill -9 .";
Process su = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(su.getOutputStream());
os.writeBytes(command + "\n");
os.flush();
I tested doing that in the terminal and works fine, but in my tasker, when this command executes the phone reboot... is very strange
Any tip??

Any ideas????

Could you please more code? What's the cycle of your app?

I have a Service listening events, when a event occurs the BroadcastReceiver whose respond to that event respond calling a extended procedure called openKill,that proc checks if must open or kill the intent of the app received, here is when check the kill option:
Code:
else if(action.equals(TaskerConstants.KILL))
{
String command = "pidof -s " + intent.getComponent().getPackageName() + " | kill -9 .";
Root.sudo(command);//Si es 0 entonces no está corriendo
}
When the user check the option kill, the app request su, and if accepts, then the kill option is saved in the task created(which contains the intent of the app to open/kill)
sudo is like this:
Code:
public static void sudo(String command)
{
Process su = null;
try
{
su = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(su.getOutputStream());
os.writeBytes(command + "\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
} catch (IOException e)
{
e.printStackTrace();
}
}

I suspect a false intent reference. It's too less code to be able to figure everything out but thats what I were going to looking for.
intent.getComponent().getPackageName()
Click to expand...
Click to collapse
Do you've printed this simply in your logcat? What does it return? I think it's the PID of your own process.

Hi again... i'm still trying to figure out why is rebooting..., I checked your suggestion but the PID obtained is correct... is the PID of the app i'm trying to kill,
I think i have not rights to do the kill, and for that the Kernel crashes, because when my app exec the script, the phone lags, hot reboot and i get the Boot animation,
Any tip of how debug it?, and the logcat persist after the reboot??

Thats a problem, however, the log-data is just buffered in the RAM, that means, it doesn't persist after a reboot. You should log data in text-files on your own (add this part in your script or your java application) so you can see when the error appears. You can also print the logcat data in a file.

Ok, i tried to save the output in a file, but the file is empty... i changed the openKill method like this:
Code:
protected static void openKill(Intent intent, Integer action)
{
if(action.equals(TaskerConstants.OPEN))
{
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(intent);
}
else if(action.equals(TaskerConstants.KILL))
{
if(Root.root())
{
String command = "pidof -s " + intent.getComponent().getPackageName() + " | kill . >> /mnt/sdcard/err.log";
Root.sudo(command);
}
}
and here is the Root class:
Code:
public class Root
{
public static boolean root()
{
Process su = null;
boolean ret = false,exit = false;
try
{
su = Runtime.getRuntime().exec("su"); //Obtengo un proceso asociado a root
DataOutputStream os = new DataOutputStream(su.getOutputStream());
DataInputStream is = new DataInputStream(su.getInputStream());
if (os != null && is != null)
{
os.writeBytes("id\n"); //Escribo en la consola y pido el id
os.flush();
String uid = is.readLine();
if(uid == null) //Si es null no pude pedir el comando con exito, por lo tanto no hay root!
{
ret = false;
exit = false;
}
else if(uid.contains("uid=0"))
{
ret = true;
exit = true;
}
else
{
ret = false;
exit = true;
}
if(exit)
{
os.writeBytes("exit\n");
os.flush();
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
return ret;
}
public static void sudo(String command)//Antes de llamar a este metodo LLAMAR SIEMPRE A ROOT para verificar los permisos
{
Process su = null;
try
{
su = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(su.getOutputStream());
DataInputStream is = new DataInputStream(su.getInputStream());
os.writeBytes(command + "\n");
os.flush();
Log.v("RET------------------------------------------------------------------>", is.readLine());
os.writeBytes("exit\n");
os.flush();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
So why the script fails like this??, i think the problem is the way i'm calling the script, but i don't really know, the only "weird way" of calling the script is that i'm calling it from a BroadcastReceiver instantiated in a Service, and register the IntentFilter dinamically for each BroadcastReceiver, like, headset plug, screen off and stuff like that, but i don't know how to proceed in this point...
Any help will be very appreciated, thanks!

Is working!
I did it!! , i just changed the script like this and is working
Code:
String command = "killall -9 " + intent.getComponent().getPackageName();
well i still don't know why was not working with kill, but whatever, thanks for the help!

Related

Rooting RC30 - need some questions answered about adbd and debuggerd

If someone has a stock RC30 installed, can you tell me what user id runs adbd and debuggerd?
To be able to debug processes and take screenshots, those processes must running be with some sort of privileged permissions and may be exploitable...
debuggerd runs as root, adbd runs as shell (that's on my official RC30 phone)
Hmm, in that case, it may actually be possible to take a screenshot without root by writing an ADB client in Java to connect to the adb daemon. And, shell also has access to the surface flinger, so it may be possible to do autorotation as well.
Anyways, I'll take a look at debuggerd and see if there anything interesting.
I did find some funny code in debuggerd.c a minute ago. Watch your phone's LED and type this into a root shell:
echo 255 > /sys/class/leds/red/brightness
Yup.
http://forum.xda-developers.com/showthread.php?p=2905504&highlight=backlight#post2905504
Holy ****!!! There may be a root hole in installd:
installd runs as root; it is the daemon that allows you to do the following commands related to installing and uninstalling APKs and managing their DEX files.
Code:
{ "ping", 0, do_ping },
{ "install", 3, do_install },
{ "dexopt", 3, do_dexopt },
{ "movedex", 2, do_move_dex },
{ "rmdex", 1, do_rm_dex },
{ "remove", 1, do_remove },
{ "freecache", 1, do_free_cache },
{ "rmcache", 1, do_rm_cache },
{ "protect", 2, do_protect },
{ "getsize", 3, do_get_size },
{ "rmuserdata", 1, do_rm_user_data },
The install daemon reads these commands from a socket and then executes them.
The interesting command is the "install" command, which maps to the following function:
Code:
static int do_install(char **arg, char reply[REPLY_MAX])
{
return install(arg[0], atoi(arg[1]), atoi(arg[2])); /* pkgname, uid, gid */
}
int install(const char *pkgname, uid_t uid, gid_t gid)
{
char pkgdir[PKG_PATH_MAX];
char libdir[PKG_PATH_MAX];
if ((uid < AID_SYSTEM) || (gid < AID_SYSTEM)) {
LOGE("invalid uid/gid: %d %d\n", uid, gid);
return -1;
}
if (create_pkg_path(pkgdir, PKG_DIR_PREFIX, pkgname, PKG_DIR_POSTFIX))
return -1;
if (create_pkg_path(libdir, PKG_LIB_PREFIX, pkgname, PKG_LIB_POSTFIX))
return -1;
if (mkdir(pkgdir, 0755) < 0) {
LOGE("cannot create dir '%s': %s\n", pkgdir, strerror(errno));
return -errno;
}
if (chown(pkgdir, uid, gid) < 0) {
LOGE("cannot chown dir '%s': %s\n", pkgdir, strerror(errno));
unlink(pkgdir);
return -errno;
}
if (mkdir(libdir, 0755) < 0) {
LOGE("cannot create dir '%s': %s\n", libdir, strerror(errno));
unlink(pkgdir);
return -errno;
}
if (chown(libdir, AID_SYSTEM, AID_SYSTEM) < 0) {
LOGE("cannot chown dir '%s': %s\n", libdir, strerror(errno));
unlink(libdir);
unlink(pkgdir);
return -errno;
}
return 0;
}
The 2nd and 3rd arguments let you specify an ARBITRARY uid that owns that package. I think we can either rebuild adb to always pass in uid 0 and gid 0 (this may not be possible; adb may not have anything to do with the uid/gid selected). Or maybe connect to the socket from an application on the phone, and then marshall the command manually. That would get an APK onto the phone running as root.
Gonna give this a shot right now.
Look at the beginning of the function.
Code:
if ((uid < AID_SYSTEM) || (gid < AID_SYSTEM)) {
LOGE("invalid uid/gid: %d %d\n", uid, gid);
return -1;
That will disallow installing something with root access. AID_SYSTEM is 1000, the root uid is 0 of course.
But if we could get an app installed as the system user.. that may open up some more possibilities.
Also, I believe the socket that installd listens on is protected. If I remember correctly, it is restricted to the system user.
JesusFreke said:
Look at the beginning of the function.
Code:
if ((uid < AID_SYSTEM) || (gid < AID_SYSTEM)) {
LOGE("invalid uid/gid: %d %d\n", uid, gid);
return -1;
That will disallow installing something with root access. AID_SYSTEM is 1000, the root uid is 0 of course.
But if we could get an app installed as the system user.. that may open up some more possibilities.
Also, I believe the socket that installd listens on is protected. If I remember correctly, it is restricted to the system user.
Click to expand...
Click to collapse
Ahh goddamnit.

Set the System Time

Hello!
I need to set the system time!
What i read up to now is, that it is not possible! because it needs sec. level 3 (only System and Signed)....
I tryed it with:
Runtime rt=Runtime.getRuntime();
rt.exec("su");
rt.exec("date -s 19991212"); //And other sytax..
on the Tablet with ConnectBot its working, because connectBot was installed on the ROM!
The App i am writing is for internal use in my company, and it needs to sync with a Server!
My Tablet (Flytouch 3, Android 2.2) is rooted, so it should be possible to set the time! The App ClockSync (http://forum.xda-developers.com/showthread.php?t=688177) can do it too!
Please help me!
Thanks
Does it have to do so using root, or would launching an Intent to the system settings app be sufficient?
Setting Intend would be not an option!
but for everyone who is looking for a soution found one! (here on XDA (where else? ) http://forum.xda-developers.com/showthread.php?p=4528387#post4528387
calling:runRootCommand("date -s <date&time>");
Code:
public static boolean runRootCommand(String command) {
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command+"\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception e) {
Log.d("*** DEBUG ***", "Unexpected error - Here is what I know: "+e.getMessage());
return false;
}
finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
// nothing
}
}
return true;
}
just for ur information because i was looking for the syntax to set the date and time for about 2hours now, could find it in the inet :/
and finally i found it by hacking a lot of possible combinations in the terminal! and it is:
date -s yyymmdd.hhmmss
Example: 20110717.175930

[?]How to read binary file in xna?

I need read 10 byte in fileName and save it into bitLevel
My code:
PHP:
test = 0;
byte[] bitLevel = new byte[10];
string fileName = "levels\\";
switch(iChap){
case 1: fileName += "beginner.dat";
break;
case 2: fileName += "normal.dat";
break;
case 3: fileName += "intermediate.dat";
break;
case 4: fileName += "expert.dat";
break;
}
using(FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
fileStream.Seek((iLevel - 1) * 10, SeekOrigin.Begin);
fileStream.Read(bitLevel, 0,10);
test = 1;
}
but bitLevel is empty
It seem it's not into codes under using, because I set test = 1; but it = 0;
can anybody help me?
//sorry my bad english
Use IsolatedStorageFile & IsolatedStorageFileStream instead of FileStream.
sensboston said:
Use IsolatedStorageFile & IsolatedStorageFileStream instead of FileStream.
Click to expand...
Click to collapse
is that ok?
can you show me demo code?
Code:
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
try
{
using (IsolatedStorageFileStream inStream = new IsolatedStorageFileStream(fileName, FileMode.Open, isf))
{
byte[] buffer = new byte[10];
int numRead = inStream.Read(buffer, 0, 10);
Debug.Assert (numRead == 10);
}
}
catch (Exception e)
{
Debug.WriteLine(e.Message + "\n" + e.StackTrace);
}
But this code for ISF only; I don't really know where are your files located (as resources or may be content). You should understand what are you trying to read first
If you added these files as a content to your project, you should read 'em from the TitleContainer
Code:
using (var inStream = TitleContainer.OpenStream(fileName))
using (StreamReader streamReader = new StreamReader(inStream))
... and so on...

[Help]Want To crack Android app To make Php

Hello Guys,Its My First Post In Forum I am Sorry If I made Any Mistake..
Actually i am tring to creat a php for android app before sometime i dont have any idea about how to view source code but thanks to xda-forum developer ...now i have knowledge to view source code of android app
Now Coming to point ..
Android App Contain Many java File In classes.dex Folder .... i have checked every file but i didnt get any web link
here is web links means ....
example-if we have any website like www . somesite . com
then if will view its soruce code then we will get like; -
action-register.php
something like this
i am searching the links in apk so please guys help me to find out it
Here is i am show off some codes of my apk file
Code:
import a.a.a.a.f;
import a.a.a.a.p;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.location.Location;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.aj;
import android.util.SparseArray;
import com.android.volley.toolbox.m;
import com.android.volley.u;
import com.appsflyer.AppsFlyerLib;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.am;
import com.google.android.gms.common.api.an;
import com.google.android.gms.common.api.aq;
import com.google.android.gms.common.api.ar;
import com.google.android.gms.common.api.i;
import com.google.android.gms.common.api.j;
import com.google.android.gms.common.api.l;
import free.bux.d.b;
import free.bux.e.g;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
public class FreeBuzzApp
extends Application
implements j, l
{
public static final String a = FreeBuzzApp.class.getSimpleName();
private static FreeBuzzApp c;
protected com.google.android.gms.common.api.h b;
private u d;
private m e;
private g f;
private Handler g;
private HashMap h = new HashMap();
public static FreeBuzzApp a()
{
return c;
}
public static boolean a(String paramString)
{
Iterator localIterator = c.getPackageManager().getInstalledApplications(0).iterator();
do
{
if (!localIterator.hasNext()) {
break;
}
} while (!((ApplicationInfo)localIterator.next()).packageName.equals(paramString));
for (boolean bool = true;; bool = false) {
return bool;
}
}
private void c()
{
Object localObject1 = null;
boolean bool1 = true;
for (;;)
{
i locali;
try
{
locali = new i(this);
locali.j.add(this);
locali.k.add(this);
com.google.android.gms.common.api.a locala = com.google.android.gms.location.h.a;
locali.c.put(locala, null);
locali.a.addAll(locala.c);
boolean bool2;
if (!locali.c.isEmpty())
{
bool2 = bool1;
com.google.android.gms.common.internal.ap.b(bool2, "must call addApi() to add at least one API");
if (locali.e < 0) {
continue;
}
am localam = am.a(locali.d);
localObject1 = new com.google.android.gms.common.api.y(locali.b.getApplicationContext(), locali.h, locali.a(), locali.i, locali.c, locali.j, locali.k, locali.e, -1);
int k = locali.e;
l locall2 = locali.g;
com.google.android.gms.common.internal.ap.a(localObject1, "GoogleApiClient instance cannot be null");
if (localam.c.indexOfKey(k) < 0)
{
com.google.android.gms.common.internal.ap.a(bool1, "Already managing a GoogleApiClient with id " + k);
an localan = new an(localam, k, (com.google.android.gms.common.api.h)localObject1, locall2);
localam.c.put(k, localan);
if ((localam.a) && (!localam.b)) {
((com.google.android.gms.common.api.h)localObject1).a();
}
this.b = ((com.google.android.gms.common.api.h)localObject1);
}
}
else
{
bool2 = false;
continue;
}
bool1 = false;
continue;
if (locali.f < 0) {
break label497;
}
com.google.android.gms.common.api.ap localap = com.google.android.gms.common.api.ap.a(locali.d);
int i = locali.f;
if (localap.D != null)
{
aq localaq = localap.b(i);
if (localaq != null) {
localObject1 = localaq.i;
}
}
if (localObject1 == null) {
localObject1 = new com.google.android.gms.common.api.y(locali.b.getApplicationContext(), locali.h, locali.a(), locali.i, locali.c, locali.j, locali.k, -1, locali.f);
}
int j = locali.f;
l locall1 = locali.g;
com.google.android.gms.common.internal.ap.a(localObject1, "GoogleApiClient instance cannot be null");
if (localap.a.indexOfKey(j) < 0)
{
bool3 = bool1;
com.google.android.gms.common.internal.ap.a(bool3, "Already managing a GoogleApiClient with id " + j);
ar localar = new ar((com.google.android.gms.common.api.h)localObject1, locall1, (byte)0);
localap.a.put(j, localar);
if (localap.D == null) {
continue;
}
android.support.v4.app.al.a = false;
localap.j().a(j, localap);
continue;
}
boolean bool3 = false;
}
finally {}
continue;
label497:
localObject1 = new com.google.android.gms.common.api.y(locali.b, locali.h, locali.a(), locali.i, locali.c, locali.j, locali.k, -1, -1);
}
}
/* Error */
public final com.google.android.gms.analytics.u a(h paramh)
{
// Byte code:
// 0: aload_0
// 1: monitorenter
// 2: aload_0
// 3: getfield 42 free/bux/FreeBuzzApp:h Ljava/util/HashMap;
// 6: aload_1
// 7: invokevirtual 262 java/util/HashMap:containsKey (Ljava/lang/Object;)Z
// 10: ifne +43 -> 53
// 13: aload_0
// 14: invokestatic 267 com/google/android/gms/analytics/l:a (Landroid/content/Context;)Lcom/google/android/gms/analytics/l;
// 17: astore 4
// 19: aload_1
// 20: getstatic 272 free/bux/h:a Lfree/bux/h;
// 23: if_acmpne +46 -> 69
// 26: aload 4
// 28: ldc_w 274
// 31: invokevirtual 277 com/google/android/gms/analytics/l:a (Ljava/lang/String;)Lcom/google/android/gms/analytics/u;
// 34: astore 7
// 36: aload 7
// 38: iconst_1
// 39: putfield 280 com/google/android/gms/analytics/u:a Z
// 42: aload_0
// 43: getfield 42 free/bux/FreeBuzzApp:h Ljava/util/HashMap;
// 46: aload_1
// 47: aload 7
// 49: invokevirtual 281 java/util/HashMap:put (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
// 52: pop
// 53: aload_0
// 54: getfield 42 free/bux/FreeBuzzApp:h Ljava/util/HashMap;
// 57: aload_1
// 58: invokevirtual 285 java/util/HashMap:get (Ljava/lang/Object;)Ljava/lang/Object;
// 61: checkcast 279 com/google/android/gms/analytics/u
// 64: astore_3
// 65: aload_0
// 66: monitorexit
// 67: aload_3
// 68: areturn
// 69: getstatic 287 free/bux/h:b Lfree/bux/h;
// 72: pop
// 73: aload 4
// 75: invokevirtual 290 com/google/android/gms/analytics/l:b ()Lcom/google/android/gms/analytics/u;
// 78: astore 6
// 80: aload 6
// 82: astore 7
// 84: goto -48 -> 36
// 87: astore_2
// 88: aload_0
// 89: monitorexit
// 90: aload_2
// 91: athrow
// Local variable table:
// start length slot name signature
// 0 92 0 this FreeBuzzApp
// 0 92 1 paramh h
// 87 4 2 localObject1 Object
// 64 4 3 localu1 com.google.android.gms.analytics.u
// 17 57 4 locall com.google.android.gms.analytics.l
// 78 3 6 localu2 com.google.android.gms.analytics.u
// 34 49 7 localObject2 Object
// Exception table:
// from to target type
// 2 65 87 finally
// 69 80 87 finally
}
public final void a(int paramInt)
{
this.b.a();
}
public final void a(Bundle paramBundle)
{
Location localLocation = com.google.android.gms.location.h.b.a(this.b);
if (localLocation != null)
{
free.bux.e.d.b(this, "latitude", String.valueOf(localLocation.getLatitude()));
free.bux.e.d.b(this, "longitude", String.valueOf(localLocation.getLongitude()));
new StringBuilder("startLocationUpdates--> User lat ").append(String.valueOf(localLocation.getLatitude()));
}
}
public final void a(ConnectionResult paramConnectionResult)
{
new StringBuilder("Connection failed: ConnectionResult.getErrorCode() = ").append(paramConnectionResult.c);
}
public final m b()
{
if (this.d == null) {
this.d = com.android.volley.toolbox.y.a(getApplicationContext());
}
if (this.e == null)
{
if (this.f == null) {
this.f = new g();
}
this.e = new m(this.d, this.f);
}
return this.e;
}
public void onCreate()
{
super.onCreate();
p[] arrayOfp = new p[1];
arrayOfp[0] = new com.a.a.a();
f.a(this, arrayOfp);
if (Build.VERSION.SDK_INT >= 9)
{
boolean bool = getSharedPreferences("free.bux_preferences", 0).getBoolean("APP_FLYER_TRACKING", true);
AppsFlyerLib.setAppsFlyerKey("4ffriSMaSjMyjrv5EDKJEB");
if (bool)
{
AppsFlyerLib.sendTracking(getApplicationContext());
SharedPreferences.Editor localEditor = getSharedPreferences("free.bux_preferences", 0).edit();
localEditor.putBoolean("APP_FLYER_TRACKING", false);
localEditor.commit();
}
}
try
{
PackageInfo localPackageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
b.a = "Freebuzz/" + localPackageInfo.versionCode + "(Android" + Build.VERSION.RELEASE + ";" + Build.MODEL + " Build /" + Build.FINGERPRINT + ";" + Locale.getDefault() + ";)";
new StringBuilder("http header is ").append(b.a);
c();
c = this;
this.g = new Handler();
a(h.b);
this.b.a();
return;
}
catch (PackageManager.NameNotFoundException localNameNotFoundException)
{
for (;;)
{
new StringBuilder("Cannot find package details with name ").append(getPackageName());
}
}
}
public void onLowMemory()
{
super.onLowMemory();
}
public void onTerminate()
{
super.onTerminate();
}
}

[Completed] Android Lollipop save image downloaded in background on SD-CARD

whit ANDROID previous kitkat I was able to store an image on sd-card without problem, now, instead, I've a lot of difficult.
I can't understand how use a new Access Store Framework of Android Lollipop and I don't know if it is useful to case of mine.
This code below is a part of my project and it's worked perfectly
Code:
private Bitmap getBitmap(String url, String image){
String root = Environment.getExternalStorageDirectory().toString();
root = "/mnt/extSdCard/";
Bitmap bitmap = null;
File f=fileCache.getFile(url);
//from SD cache
bitmap = decodeFile(f);
if(bitmap!=null)
return bitmap;
try{
bitmap = BitmapFactory.decodeFile(root + image);
if(bitmap!=null){
return bitmap;
}
}catch (Exception e) {
e.printStackTrace();
}
//from web
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
Foto foto = new Foto();
try {
try{
foto = new ObjectMapper().readValue(new URL("........."),
Foto.class);
if(foto!=null){
String[] values = image.split("/");
File dir = new File(root + values[0]);
if (!dir.exists()) {
dir.mkdir();
String fname = values[1];
File file = new File (dir, fname);
bitmap = BitmapFactory.decodeByteArray(foto.getFoto(), 0, foto.getFoto().length);
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}else{
String fname = values[1];
File file = new File (dir, fname);
bitmap = BitmapFactory.decodeByteArray(foto.getFoto(), 0, foto.getFoto().length);
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//bitmap = decodeFile(f);
return bitmap;
}else{
return bitmap;
}
}catch(Exception e){
e.printStackTrace();
return null;
}
} catch (Exception ex){
if (ex instanceof SQLiteConstraintException){
bitmap = BitmapFactory.decodeByteArray(foto.getFoto(), 0, foto.getFoto().length);
return bitmap;
}else{
ex.printStackTrace();
return null;
}
}
}else{
return bitmap;
}
}
If I use `Environment.getExternalStorageDirectory().getAbsolutePath();` I can't get path of sd-card.
Thanks
scne said:
whit ANDROID previous kitkat I was able to store an image on sd-card without problem, now, instead, I've a lot of difficult.
I can't understand how use a new Access Store Framework of Android Lollipop and I don't know if it is useful to case of mine.
This code below is a part of my project and it's worked perfectly
Code:
private Bitmap getBitmap(String url, String image){
String root = Environment.getExternalStorageDirectory().toString();
root = "/mnt/extSdCard/";
Bitmap bitmap = null;
File f=fileCache.getFile(url);
//from SD cache
bitmap = decodeFile(f);
if(bitmap!=null)
return bitmap;
try{
bitmap = BitmapFactory.decodeFile(root + image);
if(bitmap!=null){
return bitmap;
}
}catch (Exception e) {
e.printStackTrace();
}
//from web
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
Foto foto = new Foto();
try {
try{
foto = new ObjectMapper().readValue(new URL("........."),
Foto.class);
if(foto!=null){
String[] values = image.split("/");
File dir = new File(root + values[0]);
if (!dir.exists()) {
dir.mkdir();
String fname = values[1];
File file = new File (dir, fname);
bitmap = BitmapFactory.decodeByteArray(foto.getFoto(), 0, foto.getFoto().length);
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}else{
String fname = values[1];
File file = new File (dir, fname);
bitmap = BitmapFactory.decodeByteArray(foto.getFoto(), 0, foto.getFoto().length);
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//bitmap = decodeFile(f);
return bitmap;
}else{
return bitmap;
}
}catch(Exception e){
e.printStackTrace();
return null;
}
} catch (Exception ex){
if (ex instanceof SQLiteConstraintException){
bitmap = BitmapFactory.decodeByteArray(foto.getFoto(), 0, foto.getFoto().length);
return bitmap;
}else{
ex.printStackTrace();
return null;
}
}
}else{
return bitmap;
}
}
If I use `Environment.getExternalStorageDirectory().getAbsolutePath();` I can't get path of sd-card
.
Thanks
Click to expand...
Click to collapse
Hi and welcome to XDA!
Try posting your query here:
Android Q&A,Help and Troubleshooting
Experts there may be able to help you.
Good luck

Categories

Resources