FileNotFound - When trying to get asset file - android

I'm trying to get a file in the assetsbut when I run my code the FileNotFound exception throws. I've checked with getAssets().list(".") and really the android does not detect the file in the assets directory, but i put the file in the assets folder. I'm not a android expert and I count with the community help to help me to understand what am I doing wrong.
Follow bellow my code:
try {
Log.i("PEDRO", Arrays.toString(getResources().getAssets().list(".")));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Result: []
try {
Log.i("PEDRO", Arrays.toString(getApplicationContext().getAssets().list(".")));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Result: []
The file is in the assets directory.
try {
InputStream input =
Definitions.appContext.getAssets().open("iot.neo..........com.bks");
} catch (IOException e) {
e.printStackTrace();
}
I know that is too much important to use the Android Studio for the development of the applications, but I'm doing it on eclipse because it's a legacy code that will be changed to Android Studio before (and I'm not a responsible for that).
Thanks a lot!

Try remove ".":
try {
Log.d("PEDRO", Arrays.toString(getApplicationContext().getAssets().list("")));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

Related

Upload comments to particular post of facebook with object_id android

Hello friends I want to post comment to particular post in facebook with my android app, below is my code-
I Fetch All comments from URL which is below
http://retirementhomeslisting.com/home-detail/canterbury-place-83
Bundle mBundle=new Bundle();
mBundle.putString("message","testing...1234555");
#SuppressWarnings("deprecation")
Facebook fb=new Facebook(getResources().getString(R.string.fb_app_id));
try {
fb.request("478409145610921/comments",mBundle,"POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Here I provide one link which you can see all comment list with respective above object_id
Link for comment list for 478409145610921 object_id
When i run above code comment is not post with respective object_id so Any idea how can i solve it?
EDIT Answer
Bundle mBundle=new Bundle();
mBundle.putString("message","testing...1234555");
#SuppressWarnings("deprecation")
Facebook fb=new Facebook(getResources().getString(R.string.fb_app_id));
try {
fb.request("1309634065_478409145610921/comments",mBundle,"POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
To post a comment on a post, you need a post_id instead of object_id.
So your API call must be-
/{post_id}/comments
(post_id is also a field in the comments table)
Edit:
You must be using a comment plugin and trying to post a comment to that. Unfortunately, facebook don't allows you to do that! (Logical- since most of them are public, to avoid spamming, else anyone could flood comments to that post)
If you check the response here, you'll get:
{
"error": {
"message": "(#100) Comments may not be added to a comment plugin",
"type": "OAuthException",
"code": 100
}
}
You can test these API call on Graph API Explorer also.
Using Graph API:
...
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
[[[FBSDKGraphRequest alloc]
initWithGraphPath:#"post_id/likes"
parameters: #{ #"like" : #"true"}
HTTPMethod:#"POST"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(#"It was liked.");
}
}];
}
...

How to stream video in android device via .sdp file from android device

I had anapplication to stream video(without audio) from android device(Blaze board) to PC. For that, I'm using vlc player to view streamed video by using the following command in command line
vlc stream.sdp
This .sdp file would be generated from my application. By using the above command, I can stream from blaze board to PC with the delay of 1 sec.
Now, My problem is that, I have to stream from one blaze board to another blaze board. I have searched a lot. But, Nothing is worked.
I have an idea to write viewer application ( For client ). This application will use sdp file path as url. I refer this page. Here, he had used "setDataSource(http://localhost/file.sdp)" . I used like this in my application. But, it also, didn't work.
String videoSrc = "rtsp://192.168.13.77:8086/stream.sdp";
Here is my code
public void surfaceCreated(SurfaceHolder arg0) {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.setDataSource(videoSrc);
mediaPlayer.prepare();
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
How to use .sdp file to play streamed video lively?
Whether I am going is correct path or not? If you are having any other way, please suggest me.
Any help will be appreciated.

How to prevent android app from crashing when a file has not been found using openFileInput

I want to react to a situation that no file has been found using FileInputStream. When i ran an app that loads a file that doesn't exist it opens an android popup with force close. I would like to react to the situation by changing a text in a text view and saying that the file has not been found. i tried changing the exceptions to change a text view and show that a file has not been found and the app still crashes.
Here is the piece of code:
FileInputStream fis = null;
String collected = null;
try {
fis = openFileInput("test");
byte[] dataArray = new byte[fis.available()];
while (fis.read(dataArray) != -1){
collected = new String(dataArray);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
tv.setText(collected);
To ensure that an Android application does not force-close, your options are: a) do not do anything that will cause an exception, b) catch your exception with your own try/catch block, c) install an application level uncaught exception handler. Option a is not too feasible, c is not very helpful, and based on your code snippet you seem to be trying b -- however there appears to be another exception that you're not catching with this. The contents of logcat will tell you what exception, and the stack trace will lead to a point in your code which needs the try/catch.

How to delete a system file from an Android App?

I'm using Root Tools and I'm not getting too far with it...
I want to have access to delete files from /system/app and other directories that require root. I would love to do it programmatically through Java, but if I can do it through shell commands, that's OK. Too. My phone is rooted. Here's what I've tried so far.
RootTools.remount("/system", "rw");
try {
RootTools.sendShell("rm /system/app/Videos.apk", -1);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (RootToolsException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (TimeoutException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
I've also tried:
public static void sendShell(List<String> cmds) throws Exception {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
for (String tmpCmd : cmds) {
os.writeBytes(tmpCmd+"\n");
}
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();
}
I have no idea what to do from here...
Based on our conversations it looks like you need a different rom as there were issues remounting partitions on your device.
I would bet that flashing a new rom would alleviate this issue and allow RootTools to properly remount /system as rw and allow you to delete your file.

LogCatError "setDataSource: outside path in JNI is ?x#" when playing music with mediaplayer

I have a strange problem when playing music files with the mediaplayer.
The playback starts without any problems and everything works fine. The app doesn't crash. But everytime I select a song I get the following LogCatError:
11-18 16:26:19.800: E/MediaPlayer(11367): setDataSource JAVA path
11-18 16:26:19.800: E/MediaPlayer-JNI(11367): setDataSource: outside
path in JNI is ?x#
11-18 16:26:19.855: E/MediaPlayer(11367): In prepareAsync
11-18 16:26:20.005: W/MediaPlayer(11367): info/warning (1, 44)
I don't download the files from the internet, I just play the songs stored on the device.
If nobody could give me a solution, it would be nice if anybody could explain the error to me.
Use try catch around you mediaplayer datasource, like this:
try {
mp.setDataSource(getApplicationContext(), ringtoneUri);
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
You have to catch all Exceptions.
This worked for me.
try using ES File Explorer or something similar to check the properties/permissions of the file you want to play and try making it world readable
I had same problem, the file was in "*.wmv" format, then i converted file to mp3 and tried same code and it worked, please find code below
try {
MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource("http://Server.com/XXXX.mp3");
player.prepare();
player.start();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}

Categories

Resources