I'm working with an Android app that generates a text file and stores it on the sdcard.
I would like to open the file in a text editor. The one I have installed is Office Suite Professional.
I have the following code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse
("file:///sdcard/report.txt"));
startActivity(intent);
When I run this snippet of code, I get the following error:
Sorry! The application XXXX () has stopped unexpectedly. Please try again.
How can I get my app to load OfficeSuite Pro with a specific file?
Thanks
Mike
First, you will want to use adb logcat, DDMS, or the DDMS perspective in Eclipse to examine LogCat and look at the stack trace associated with your error.
Had you done that, you would have seen an exception indicating that it could not find an activity to match your Intent.
In this case, you have one definite problem and one possible problem.
The definite problem is that you do not have a MIME type. Use setDataAndType() rather than setData(), with "text/plain" as the 2nd parameter.
The possible problem is that "OfficeSuite Pro" (whatever that is) may or may not know how to view text files.
Related
I am new in android and I have develop an application in android but the issue is when i install it on my device it shows me 2 icons one is working and other one says that receipt organizer has been stopped unexpectedly.Kindly let me know how i can get out of this rid ?Is it some kind of code error or problem in the manifest or properties ?Also one more question now my api level is set to 18 if i set it to previous version then the functionality will not get disturbed right ?So let me know if any one can help.
Look at your manifest file. Your manifest file should have only one activity that has the LAUNCHER in the intent filter.
Choose your main activity (which should have this intent filter), and delete the intent filters from the other activity. after that, you should see only one application icon.
On Android I am using the android.util.Log to log within my application and during development I am using the adb logcat or Eclipse to see the logs - I use it even more then debugging...
On device I can save the logfile from my code or use some application form Android Market to save the logs - e.g. aLogCat.
Now can I do the same on the iPhone? I can use the NSLog(#"message");, but can I easily save the log file from my application and access it? Are there any ways for that?
Regards,
STeN
This is from NSFoundation reference
NSLog:
Simply calls NSLogv, passing it a variable number of arguments.
NSLogv:
Logs an error message to the Apple System Log facility (see man 3 asl). If the STDERR_FILENO file descriptor has been redirected away from the default or is going to a tty, it will also be written there. If you want to direct output elsewhere, you need to use a custom logging facility.
Thus, it is only a matter of redirecting the file-descriptor "stderr" (2) to a custom file, and you will get everything that you print using NSLog in that file.
This seems to be exactly what you want.
Note that if you want to get logs on console when you are connected to the debugger, you can wrap your code around this to avoid redirection in this case:
if (!isatty(STDERR_FILENO)) { // Not connected to any terminal
// your redirection code
}
You can access the console log from Organizer->Device->Your device->console.
If that is not powerful enough, consider using utilities like NSLogger.
The previous answers are good; also see this if you're inclined to making system calls.
As illustrated by a number of questions here, it's sometimes difficult to get intent filters configured correctly. If a filter is not working like expected (e.g., app shows "permission denied"), what are some tricks to figure out why?
Update: To clarify, I'm not just talking about built-in intents. It's been a struggle getting a custom OAuth callback URL to resolve to the correct activity, but I can't tell if the issue is due to my intent filter or something else.
Option 1: Catch-all IntentFilter, then debug IntentFilter.match()
I wanted to ask exactly the same question. I know of no readily available tools for debugging failing intent filters but this is the approach I'm thinking of:
Make the intent filter as permissive as possible (i.e. put wildcards everywhere you can) so that you can grab and examine the Intent from within your application
Submit the Intent object thus obtained to your real intent filter's match method. You should be able to tell at which stage matching failed by looking which NO_MATCH_* constant is returned.
Once you captured the Intent you can also run the matching in a debugger so better understand what is wrong.
Option 2: Use the App Links Assistant
(This option only works if you want to debug http/https links)
Make sure the App Links Assistant plugin is enabled (File > Settings > Plugins > check "App Links Assistant" in the list). Restart Studio if prompted
Open the assistant (Tools > App Links Assistant)
Click "Open URL Mapping Editor" button in the side bar
Create/Edit your IntentFilter in the dialog
Type a test url in the "Check URL Mapping" box.
This will not tell you why a filter does not work, but allows much faster trial-and-error testing. That's what allowed me to understand why my filter wouldn't work (turns out we can't put wildcards in the "port". I set scheme to http, host filter to *, left port number empty (tried * as well) and set a pathPattern, but it would only matcĥ port 80 (on arbitrary hosts)
First - check if called component is declared in the parent manifest for the calling component.
If the called component is yours and not in the same app, check if it is declared in its own manifest.
Other possible problem - if the called component is correct by itself (broken layouts, forbidden elements in a widget)
Some intent-filters are protected by the system. And as such would require you to have a permission before you can use it. The trick is to know what you want. Once you know what you want, then you can look up intent filters that are available.
The preferred option would be to learn the traverse the android source code and find what you're looking for in the manifest.
I'm trying to write a launcher-like application (I'm not planning to release it, it's just for me to use) but I don't seem to find any way to launch the Market.
All of the answers I've found actually perform a search on the Market (using a uri "market://") or even worse they run the Market on a specific app page, while I'm trying to show the main page of the Market, i.e. the page shown when you run it from the launcher.
I tried using just "market://" as a Uri, without query strings, but it doesn't work; I also tried to get exactly the same "signature" of the "start activity command" that appears in the LogCat when I run the Market from the Launcher (by manually editing component, flags and categories), but it still doesn't work.
Is there any way to get it to show the main page?
Thanks in anticipation.
Intent intent = new Intent();
intent.setClassName("com.android.vending", "com.android.vending.AssetBrowserActivity");
startActivity(intent);
In windows text files are displayed with notepad icon. When we double click the particular file it open’s the notepad and displays the file.
Like that I need to open the file from the download folder in android. I have used the intent-filter for register my ics file’s mime type. When I select the file in the download folder it just opens my application only. At that time I need to open / read the selected file. How to do this? I am new to android Can anyone help me?
You can determine the Intent your activity was fired with by calling getIntent(), and you can access the data for that Intent (in this case, likely a URI), by calling getIntent().getData(). Also, the action is likely ACTION_VIEW, but you probably know this already if you've set up your <intent-filter> properly.
When your application is called, it is supplied an Intent.
You can get the file name from the intent that is supplied to your application and open the file using new FileInputStream(String filename).
You can now read the data from this stream as you normally would in Java.
P.S. Make sure your application has enough permissions to access the file. You may need to declare the required permissions in your manifest.