I have a problem with intents in Android. In my project, I'd like to open file using one of the installed file managers. I'm creating my intent and it invokes option to choose which file manager to start and starts this file manager, but I don't see any changes in logs , like it wouldn't really start this activity. I'm new to Android, so any help would be welcome.
My code is here, and my logs from logcat are here.
For testing I'm using Genymotion 2.5.0, with Google Nexus 4 - 4.1.1 Android - API 16.
Thanks in advance
EDIT
Code:
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import static android.content.Intent.*;
public class MainActivity extends AppCompatActivity {
static final int PICK_FILE = -1;
String sciezka = "cos na poczatek";
private static final String TAG1 = "TAG1_INTENT";
private static final String TAG2 = "TAG2_ON_ACTIVITY_RESULT";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pickFile();
TextView tv = new TextView(this);
tv.setText(sciezka);
setContentView(tv);
}
private void pickFile(){
//Toast.makeText(this, sciezka, Toast.LENGTH_SHORT).show();
Log.d(TAG1, "Tworzenie nowego intenta");
Intent intent = new Intent();
Log.d(TAG1, "ustawianie typow");
intent.setType("*/*");
Log.d(TAG1, "ustawienie akcji na get_content");
intent.setAction(ACTION_GET_CONTENT);
Log.d(TAG1, "Odpalanie intenta");
try{
startActivityForResult(Intent.createChooser(intent, "Wybierz plik"), PICK_FILE);
} catch (android.content.ActivityNotFoundException anfe){
Toast.makeText(this, "Zainstaluj przeglądarke plików", Toast.LENGTH_SHORT);
Log.d(TAG1, "Brak przeglądarki plików");
} catch (Exception e){
Log.d(TAG1, "No odpalenie intenta nie zadziałało");
}
Toast.makeText(this, "nanana batman", Toast.LENGTH_SHORT);
}
@Override
protected void onActivityResult(int reqCode, int resCode, Intent data){
Log.d(TAG2, "Pierwszy if - reqCode == PICK_FILE");
if(reqCode == PICK_FILE){
Log.d(TAG2, "Drugi if - resCode == RESULT_CANCELED");
if(resCode == RESULT_CANCELED){
Log.d(TAG2, "wywolanie RESULT_CANCELED - na pewno ok?");
}
if(resCode == RESULT_OK){
Log.d(TAG2, "No to jestesmy w resCode == RESULT_OK, pobieranie danych o selectedFile, tworzenie uri selectedFile");
Uri selectedFile = null;
Log.d(TAG2, "proba pobrania danych do selectedFile");
try{
selectedFile = data.getData();
} catch (Exception e){
Log.d(TAG2, "Cos nie zabanglalo i nie pobralo info");
}
Log.d(TAG2, "dane pobralo poprawnie, ustawianie path na sciezeczka");
String path = "sciezeczka";
Log.d(TAG2, "proba pobrania sciezeczki do pliczku");
try{
path = getFilePath(getApplicationContext(), selectedFile);
} catch (Exception e){
Log.d(TAG2, "nope, nie pobralo sciezki");
path = "No i kiszka";
}
Log.d(TAG2, "wypisanie patha");
System.out.println(path);
}
} else {
Log.d(TAG2, "No i pierwszy if nie byl true");
}
Log.d(TAG2, "wyswietlenie toasta - tylko z czym?");
Toast.makeText(this, sciezka, Toast.LENGTH_SHORT).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public String getFilePath(Context context, Uri uri){
return "cos";
}
}
Logs
07-17 07:01:58.966 1838-1838/? D/dalvikvm﹕ Late-enabling CheckJNI
07-17 07:01:59.030 1838-1838/? D/TAG1_INTENT﹕ Tworzenie nowego intenta
07-17 07:01:59.030 1838-1838/? D/TAG1_INTENT﹕ ustawianie typow
07-17 07:01:59.030 1838-1838/? D/TAG1_INTENT﹕ ustawienie akcji na get_content
07-17 07:01:59.030 1838-1838/? D/TAG1_INTENT﹕ Odpalanie intenta
07-17 07:01:59.038 1838-1838/? I/dalvikvm﹕ Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
07-17 07:01:59.038 1838-1838/? W/dalvikvm﹕ VFY: unable to resolve virtual method 13330: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
07-17 07:01:59.038 1838-1838/? D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0007
07-17 07:01:59.038 1838-1838/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
07-17 07:01:59.038 1838-1838/? W/dalvikvm﹕ VFY: unable to resolve virtual method 408: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
07-17 07:01:59.038 1838-1838/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
07-17 07:01:59.038 1838-1838/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
07-17 07:01:59.038 1838-1838/? W/dalvikvm﹕ VFY: unable to resolve virtual method 430: Landroid/content/res/TypedArray;.getType (I)I
07-17 07:01:59.038 1838-1838/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
07-17 07:01:59.094 1838-1838/? D/libEGL﹕ loaded /system/lib/egl/libEGL_genymotion.so
07-17 07:01:59.102 1838-1838/? D/﹕ HostConnection::get() New Host Connection established 0xb8475aa8, tid 1838
07-17 07:01:59.118 1838-1838/? D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_genymotion.so
07-17 07:01:59.118 1838-1838/? D/libEGL﹕ loaded /system/lib/egl/libGLESv2_genymotion.so
07-17 07:01:59.314 1838-1838/? W/EGL_genymotion﹕ eglSurfaceAttrib not implemented
07-17 07:01:59.334 1838-1838/? D/OpenGLRenderer﹕ Enabling debug mode 0
07-17 07:01:59.366 1838-1842/? D/dalvikvm﹕ GC_CONCURRENT freed 184K, 3% free 10943K/11207K, paused 27ms+0ms, total 30ms
07-17 07:02:00.054 1838-1838/pl.filemanagerinvoker D/OpenGLRenderer﹕ TextureCache::get: create texture(0xb842a868): name, size, mSize = 2, 4096, 4096
07-17 07:02:00.122 1838-1838/pl.filemanagerinvoker D/OpenGLRenderer﹕ TextureCache::get: create texture(0xb837c798): name, size, mSize = 4, 9216, 13312
07-17 07:02:00.274 1838-1838/pl.filemanagerinvoker W/EGL_genymotion﹕ eglSurfaceAttrib not implemented
07-17 07:02:00.290 1838-1838/pl.filemanagerinvoker D/OpenGLRenderer﹕ TextureCache::get: create texture(0xb8405fd8): name, size, mSize = 6, 33792, 47104
07-17 07:02:00.298 1838-1838/pl.filemanagerinvoker D/OpenGLRenderer﹕ TextureCache::get: create texture(0xb8432268): name, size, mSize = 8, 33792, 80896
07-17 07:02:00.298 1838-1838/pl.filemanagerinvoker D/OpenGLRenderer﹕ TextureCache::get: create texture(0xb83fd9a8): name, size, mSize = 9, 36864, 117760
07-17 07:02:00.298 1838-1838/pl.filemanagerinvoker D/OpenGLRenderer﹕ TextureCache::get: create texture(0xb84ff110): name, size, mSize = 10, 36864, 154624
07-17 07:02:00.302 1838-1838/pl.filemanagerinvoker D/OpenGLRenderer﹕ TextureCache::get: create texture(0xb84ffca0): name, size, mSize = 11, 33856, 188480
07-17 07:02:00.306 1838-1838/pl.filemanagerinvoker D/OpenGLRenderer﹕ TextureCache::get: create texture(0xb8500658): name, size, mSize = 12, 36864, 225344
07-17 07:03:50.262 1838-1838/pl.filemanagerinvoker D/OpenGLRenderer﹕ TextureCache::get: create texture(0xb8414f18): name, size, mSize = 32, 576, 225920
07-17 07:06:58.990 1838-1842/pl.filemanagerinvoker D/dalvikvm﹕ GC_CONCURRENT freed 155K, 3% free 11232K/11527K, paused 1ms+1ms, total 4ms