Rectangle 27 1

I just solved this very same problem 5 minutes ago. As you can see here debug: file not found in Android 1.0 my problem was the pathname. Before updating to 1.0 I was working with #Ing.Informatica and /Ingeniera/AdministradorContraseas now I must work with Ing.Informatica and /Ingenieria/AdministradorContrasennas because it seems like after the update Android Studio is never more able to read special characters.

android - "File not Found" exception in dexDebug task of build - Stack...

android android-studio
Rectangle 27 18

Required: Splitting the data file

Both solutions require splitting up the data file into several files categorized by a column. Therefore, I've created a short ruby script, which can be found in this gist:

This script is used like this: In order to split up the data file data.csv into data.Category1.csv and data.Category2.csv, call:

# bash
ruby categorize_csv.rb --column 2 data.csv

# data.csv
# year   category   num_of_events_for_A   num_of_events_for_B
"2011";"Category1";"213";"30"
"2011";"Category2";"240";"28"
"2012";"Category1";"222";"13"
"2012";"Category2";"238";"42"
...

# data.Category1.csv
# year   category   num_of_events_for_A   num_of_events_for_B
"2011";"Category1";"213";"30"
"2012";"Category1";"222";"13"
...

# data.Category2.csv
# year   category   num_of_events_for_A   num_of_events_for_B
"2011";"Category2";"240";"28"
"2012";"Category2";"238";"42"
...

Strategy: One data file per category. One column per stack. The bars of the histogram are plotted "manually" by using the "with boxes" argument of gnuplot.

Downside: Bars have to be placed manually.

# solution1.gnuplot
reset
set terminal postscript eps enhanced 14

set datafile separator ";"

set output 'stacked_boxes.eps'

set auto x
set yrange [0:300]
set xtics 1

set style fill solid border -1

num_of_categories=2
set boxwidth 0.3/num_of_categories
dx=0.5/num_of_categories
offset=-0.1

plot 'data.Category1.csv' using ($1+offset):($3+$4) title "Category 1 A" linecolor rgb "#cc0000" with boxes, \
     ''                   using ($1+offset):3 title "Category 2 B" linecolor rgb "#ff0000" with boxes, \
     'data.Category2.csv' using ($1+offset+dx):($3+$4) title "Category 2 A" linecolor rgb "#00cc00" with boxes, \
     ''                   using ($1+offset+dx):3 title "Category 2 B" linecolor rgb "#00ff00" with boxes

Strategy: One data file per year. One column per stack. The histogram is produced using the regular histogram mechanism of gnuplot.

Downside: Since all categories are in one file, each category has the same color.

# solution2.gnuplot
reset
set terminal postscript eps enhanced 14

set datafile separator ";"

set output 'histo.eps'
set yrange [0:300]

set style data histogram
set style histogram rowstack gap 1
set style fill solid border -1
set boxwidth 0.5 relative

plot newhistogram "2011", \
       'data.2011.csv' using 3:xticlabels(2) title "A" linecolor rgb "red", \
       ''              using 4:xticlabels(2) title "B" linecolor rgb "green", \
     newhistogram "2012", \
       'data.2012.csv' using 3:xticlabels(2) title "" linecolor rgb "red", \
       ''              using 4:xticlabels(2) title "" linecolor rgb "green", \
     newhistogram "2013", \
       'data.2013.csv' using 3:xticlabels(2) title "" linecolor rgb "red", \
       ''              using 4:xticlabels(2) title "" linecolor rgb "green"

+1 nice work providing ups and downs for both approaches!

I also think, that splitting the data files is the only viable way to created those histograms. BTW: You can also accept your own answer :).

Thanks @Christoph, I thought I'd just wait a couple of days for maybe somebody adding a better way to do it.

Gnuplot Histogram Cluster (Bar Chart) with One Line per Category - Sta...

gnuplot histogram bar-chart
Rectangle 27 5

Try locating your projects in a path that doesn't have non-ASCII characters in it; your username is in Unicode, and the build system can't handle pathnames that have non-ASCII Unicode.

This is actually a bug in Java and is quite difficult to fix; see https://code.google.com/p/android/issues/detail?id=56102 for details. The crux of it is that Java's launcher uses the wrong Windows API call to fetch its command line from the OS.

android - "File not Found" exception in dexDebug task of build - Stack...

android android-studio
Rectangle 27 28

I had difficulties reading files line by line in some circumstances. The method below is the best I found, so far, and I recommend it.

String yourData = LoadData("YourDataFile.txt");
public String LoadData(String inFile) {
        String tContents = "";

    try {
        InputStream stream = getAssets().open(inFile);

        int size = stream.available();
        byte[] buffer = new byte[size];
        stream.read(buffer);
        stream.close();
        tContents = new String(buffer);
    } catch (IOException e) {
        // Handle exceptions here
    }

    return tContents;

 }

EDIT. Apparent issue: this function might return this string:

instead of the file contents. I am unable yet to reproduce the problem. Until I update my answer when I get what the problem is, consider the code above 'probably unreliable'.

same here, res.AssetManager$AssetInputStream@.... any particular reason why it is returning this?

You double-allocate memory - first for the buffer and then for the String. Does not work for bigger files.

android - read file from assets - Stack Overflow

android
Rectangle 27 155

You can do this with Activity.overridePendingTransition(). You can define simple transition animations in an XML resource file. A good tutorial on this can be found here.

Thanks iandisme. overridePengingTransition is API level 5. Is it not possible to do this for level 3 (Android 1.5)?

Ah, you're right. CaseyB's answer is probably more along the lines of what you're looking for.

Haven't found yet how to do a proper fade in with CaseyB's answer.

You can do this in your Activity's onCreate function.

Activity transition in Android - Stack Overflow

android android-activity transition
Rectangle 27 39

this is the only solution that i found that works!

WebView webview;

private ValueCallback<Uri> mUploadMessage;
private final static int FILECHOOSER_RESULTCODE = 1;

@Override
protected void onActivityResult(int requestCode, int resultCode,
        Intent intent) {
    if (requestCode == FILECHOOSER_RESULTCODE) {
        if (null == mUploadMessage)
            return;
        Uri result = intent == null || resultCode != RESULT_OK ? null
                : intent.getData();
        mUploadMessage.onReceiveValue(result);
        mUploadMessage = null;

    }
}

// Next part 

class MyWebChromeClient extends WebChromeClient {
    // The undocumented magic method override
    // Eclipse will swear at you if you try to put @Override here
    public void openFileChooser(ValueCallback<Uri> uploadMsg) {

        mUploadMessage = uploadMsg;
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.addCategory(Intent.CATEGORY_OPENABLE);
        i.setType("image/*");
        Cv5appActivity.this.startActivityForResult(
                Intent.createChooser(i, "Image Browser"),
                FILECHOOSER_RESULTCODE);
    }
}

Can you clarify please where should I place this code? and How should I use it?

As of 4.4 (KitKat), openFileChooser is no longer available, hence approaches that make use of it do not work.

@SteveN what is the work arround of this for 4.4(KitKat) ?

@nadeemgc In my case, I control the web server too, so I am detecting Android 4.4+, using a different URL scheme (aka "my-app://some/other/arguments") for the upload link, intercepting these URLs in shouldOverrideUrlLoading(), and then showing a picker & doing the upload in native code for that case. It's not exactly a lightweight workaround.

Can I upload an image in android 4.4.2 using webview?

android - File Upload in WebView - Stack Overflow

android android-emulator webview
Rectangle 27 128

I found the solution. In the manifest file of the application I found the package name: com.package.address and the name of the main activity which I want to launch: MainActivity The following code starts this application:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);

i got exception ' dose you declare activity in your Manifest.xml'

This way returns an exception which says I need to declare the activity in my manifest.. but its an external app!

How to run it in background? Means second called applications doesn't show on screen, but run its onCreated() method.

Works like a charm!

Launch an application from another application on Android - Stack Over...

android android-intent
Rectangle 27 127

I found the solution. In the manifest file of the application I found the package name: com.package.address and the name of the main activity which I want to launch: MainActivity The following code starts this application:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);

i got exception ' dose you declare activity in your Manifest.xml'

This way returns an exception which says I need to declare the activity in my manifest.. but its an external app!

How to run it in background? Means second called applications doesn't show on screen, but run its onCreated() method.

Works like a charm!

Launch an application from another application on Android - Stack Over...

android android-intent
Rectangle 27 4

You cannot update the assets folder after the application has been packaged and installed. You can, however, store to the device's memory and read in your file from there. More on this subject can be found at http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

Couldn't update a file in android app assets folder - Stack Overflow

android android-file
Rectangle 27 15

If you do not want to use the jar file

public static boolean findBinary(String binaryName) {
        boolean found = false;
        if (!found) {
            String[] places = { "/sbin/", "/system/bin/", "/system/xbin/",
                    "/data/local/xbin/", "/data/local/bin/",
                    "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/" };
            for (String where : places) {
                if (new File(where + binaryName).exists()) {
                    found = true;

                    break;
                }
            }
        }
        return found;
    }
private static boolean isRooted() {
        return findBinary("su");
    }
if (isRooted() == true ){
textView.setText("Device Rooted");

}
else{
textView.setText("Device Unrooted");
}
checkRootMethod4()
== true

@smoothBlue Why would it? It's not spawning any Processes as DevrimTuncer's solution is.

A better idea would be to iterate over PATH, instead of hard coding typical PATH directories

android - Determine if running on a rooted device - Stack Overflow

android root
Rectangle 27 155

I haven't found any way to do that in Android Studio, but I access the db with a remote shell instead of pulling the file each time.

1- Go to your platform-tools folder in a command prompt

2- Enter the command adb devices to get the list of your devices

C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb devices
List of devices attached
emulator-xxxx   device

3- Connect a shell to your device:

C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb -s emulator-xxxx shell
cd data/data/<your-package-name>/databases/
sqlite3 <your-db-name>.db

6- run sqlite3 commands that you like eg:

Select * from table1 where ...;

There are a few steps to see the tables in an SQLite database:

List the tables in your database:

.tables

List how the table looks:

.schema tablename
SELECT * FROM tablename;

List all of the available SQLite prompt commands:

.help

You don't need the .db extension. I used it and it ended up creating another (blank) file. So I had both some_database and some_database.db

step 5: sqlite3 not found. Why?

Because you need to install in in order to use

View contents of database file in Android Studio - Stack Overflow

android android-studio android-sqlite ddms
Rectangle 27 17

I found that I needed 3 interface definitions in order to handle various version of android.

public void openFileChooser(ValueCallback < Uri > uploadMsg) {
  mUploadMessage = uploadMsg;
  Intent i = new Intent(Intent.ACTION_GET_CONTENT);
  i.addCategory(Intent.CATEGORY_OPENABLE);
  i.setType("image/*");
  FreeHealthTrack.this.startActivityForResult(Intent.createChooser(i, "Image Chooser"), FILECHOOSER_RESULTCODE);
}

public void openFileChooser(ValueCallback < Uri > uploadMsg, String acceptType) {
  openFileChooser(uploadMsg);
}

public void openFileChooser(ValueCallback < Uri > uploadMsg, String acceptType, String capture) {
  openFileChooser(uploadMsg);
}

Thanks, the last one is required for Jelly Bean, which was the one not working for me.

How to handle this method after obfuscation ? I am using same method without obfuscation it works fine but when my app is deployed with obfuscation this methods is never called. I have keeps this method in proguard anyone seen this issue?

It would be better to do it the other way round, i.e. put the code in the last one one which has the richest signature, and make use of its parameters to choose which kind of intent to launch. Then have the other two call the last one with default values for those parameters.

android - File Upload in WebView - Stack Overflow

android android-emulator webview
Rectangle 27 4

None of this works for me. I found this to be the working solution:

String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getActivity().getContentResolver().query(uri, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();

Convert file: Uri to File in Android - Stack Overflow

android file uri file-uri
Rectangle 27 8

adb command can be under the new path below- C:\Users\USERNAME\AppData\Local\Android\sdk\platform-tools for new versions of Android studio. I found in this location for me.

android - 'adb' is not recognized as an internal or external command, ...

android batch-file adb
Rectangle 27 62

I was looking for the same thing and I found this in the ApiDemos, ExternalStorage. Solved all my problems as it scans a single file.

MediaScannerConnection.scanFile(this,
          new String[] { file.toString() }, null,
          new MediaScannerConnection.OnScanCompletedListener() {
      public void onScanCompleted(String path, Uri uri) {
          Log.i("ExternalStorage", "Scanned " + path + ":");
          Log.i("ExternalStorage", "-> uri=" + uri);
      }
 });

Best solution to add a single file.

Works like a charm, for multiple files manually add file paths to the string array

this works like a charm, does this work for KitKat and above? I don't have a Kitkat device so I couldn't test it myself.

Bashing my head to wall for 2 days to get this work on kitkat and it didn't. You can try this out on an emulator running kitkat. let me know if it worked.

Android How to use MediaScannerConnection scanFile - Stack Overflow

android
Rectangle 27 10

I have found a solution. I am pasting it here so it may help other users.

Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    File file = new File(path);

    MimeTypeMap mime = MimeTypeMap.getSingleton();
    String ext = file.getName().substring(file.getName().indexOf(".") + 1);
    String type = mime.getMimeTypeFromExtension(ext);

    intent.setDataAndType(Uri.fromFile(file), type);

    context.startActivity(intent);
context.startActivity(intent);
Toast
PackageManager manager = mActivity.getPackageManager();         List<ResolveInfo> info = manager.queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY); 		if(info.isEmpty()) 			Toast.makeText(mActivity, "No app found to open this file", Toast.LENGTH_SHORT).show(); 		else 			context.startActivity(intent);

Automatically open Intent Chooser for the file Android - Stack Overflo...

android file android-intent mime-types
Rectangle 27 10

I have found a solution. I am pasting it here so it may help other users.

Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    File file = new File(path);

    MimeTypeMap mime = MimeTypeMap.getSingleton();
    String ext = file.getName().substring(file.getName().indexOf(".") + 1);
    String type = mime.getMimeTypeFromExtension(ext);

    intent.setDataAndType(Uri.fromFile(file), type);

    context.startActivity(intent);
context.startActivity(intent);
Toast
PackageManager manager = mActivity.getPackageManager();         List<ResolveInfo> info = manager.queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY); 		if(info.isEmpty()) 			Toast.makeText(mActivity, "No app found to open this file", Toast.LENGTH_SHORT).show(); 		else 			context.startActivity(intent);

Automatically open Intent Chooser for the file Android - Stack Overflo...

android file android-intent mime-types
Rectangle 27 8

I had same problem. Fortunately, I had access to the device and it helped me to find problem. First of all, I have studied log file and found error:

W/SharedPreferencesImpl(31354): org.xmlpull.v1.XmlPullParserException: Map value without name attribute: string

So, preferences file was corrupted in some way. I have made preferences file world-accessible in my application:

SharedPreferences prefs = context.getSharedPreferences("main", Context.MODE_WORLD_READABLE);

Then I pull the file from device to computer

adb pull data/data/my.package.name/shared_prefs/main.xml c:\main.xml

and check preferences file content:

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<string>Paris,France</string>
<string name="HideStatusBar">1</string>

First parameter has no "name" attribute. I have checked a code and found that in some circumstances first parameters was written in follow way:

SharedPreferences.Editor e = _Prefs.edit();
 e.putString(null, paramValue);
 e.commit()

Name was null. I have fixed the error and problem has disappeared. So, trivial error can completely corrupt preferences file.

android - User settings saved in SharedPreferences removed or lost bet...

android sharedpreferences
Rectangle 27 30

Actually, I've found a property called android:zAdjustment in the animation files.

android:zAdjustment="bottom"
hold.xml
android:zAdjustment="top"
push_down_out.xml

This gets around the z order issue (I assumed it was an issue with animation timings so I was barking up the wrong tree).

This turned out to be why my transition animation wasn't playing, either. As an added bonus, I only had to add the android:zAdjustment="top" to the exitanimation (the one I wanted playing on top), so you don't even need the "bottom" one.

@johncc can you please include xml files and source code? Thanks!

android - Make new activity appear behind old one during transition - ...

android animation android-activity
Rectangle 27 233

This answer gave the view without the status bar - which is what I wanted. I was looking for the pixel width + height of the visible part of the activity. This one works, thanks!

Is there a way to include the ActionBar as well?

The key words here are "the root view as found in the XML file". Thank you.

This should be the correct marked answer. This will place the Snackbar inside your Activity (at the root), which is where it should be (I am pretty sure nobody wants to place their info behind the Nav Buttons)

android - Get root view from current activity - Stack Overflow

android android-activity view