MessageBox.Show() fails to show !?!? - Windows Mobile Development and Hacking General

Hello,
I write a WindowsMobile C# application (details below).
I added a try...catch statement, wrapping the Main Form, trying to show a message to my users to report of any issues. something like...
Code:
try {
Application.Run(new MainViewForm());
}
catch (Exception e) {
String msg = "Failed to execute properly :(\n" +
"Please report error to [email protected]\n" +
"I'll do my best to fix this!";
MessageBox.Show(msg, "Application Error");
}
Sadly, The exception is being called, but the dialog is not showed (a quick flickering appears and disappears.
I even tried to show another Form with my error but same thing happens.
I was wondering
1. how can I handle an error message that would succeed?
2. is there a BKM to handle app crash reporting?
I'd really appreciate help on this.
Thanks
My ReliRescue app for free at http://www.logelog.com/utils
- I'm using HTC Blackstone reflashed with Miri_WM65_21885_V33.0_Premium

Related

[Q] ACTION_CALL Error to ACTION_DIAL

Hi,
I'm about to develop a little App and wanted to have a little Call-Button to call a fixed phonenumber(not in contactlist)
So I used this code:
Code:
public void onClick(View src) {
switch(src.getId()){
case R.id.ButtonCall:
Intent phonecall = new Intent(Intent.ACTION_CALL, Uri.parse("tel:11112222"));
startActivity(phonecall);
break;}
}
But wehen i run the App in AVD or also on my HTC Desire Stock Rom it always throws an Error : "The Application XYZ (process com.yyy.zzz.) has stoppen unexpectly. Please try again."
But when i use ACTION_DIAL it works, well it don't dials the number but the dial button shows up with the specified number...
So 1. what is my failer in the code (android.permission.CALL_PHONE is set) and 2. is there a possibility to prefent the app from crashing with ACTION_CALL and than use ACTION_DIAL instead? (Kind of Errorhandling...)
Thanks Spazzt
Ok, sry the error was that the permission was not set correctly...
But what when the user dont grants the permission, how do i do such an "error" handling? Or how can I test if the user has grated the permission or not and then if not use DIAL instead?
Idear?

[app][root]SecHoleUtils.apk 1.1 Control GPS and PIN from your app. KitKat ready.

Google has always limited the access to several features like GPS on/off management, PIN control and more to third party applications. Sometimes the developers have taken advantage of certain security bugs to circonvent those limitations, but Google has fixed those bugs on the latest OS version.
There are certain functions that in my opinion should be allowed because the security risk is minimun, like GPS control and SIM PIN entering , so I've wr1tten a small app to open this possibility. It does nothing by itself and is not normally loaded but registers for specific intents and when received does those forbidden functions.
Any thir party application can take advantage of it, no need to ask for permisions. Simply broadcast and intent and voila!
Sample usage code:
Code:
public static final String TOOGLE_GPS = "com.beemer.secholeutils.TOOGLE_GPS";
public static final String ENTER_PIN = "com.beemer.secholeutils.ENTER_PIN";
public static final String EXTRA_PIN = "com.beemer.secholeutils.EXTRA_PIN";
public void toogleGPS() {
Intent intent = new Intent(TOOGLE_GPS);
sendBroadcast(intent);
}
public void enterPIN(String PIN) {
Intent intent = new Intent(ENTER_PIN);
intent.putExtra(EXTRA_PIN, PIN);
sendBroadcast(intent);
}
Disclaimer
I'm nor responsible of what happens to your device if you install this apk or while you install it.
Installing this app could allow any third party app to use it to turn on/off the GPS or enter your SIM PIN (if known) even try an brute force atack without asking for permission.
The app must be installed as a system app. You can do it manually but from kitkat on it has became somewhat difficult. I recomend installing busybox and systemappmover from Play store:
https://play.google.com/store/apps/details?id=stericson.busybox
https://play.google.com/store/apps/details?id=de.j4velin.systemappmover
Install secHoleUtils.apk as a normal app and use SystemAppMover to make it a system app.
DEBUG
In order to debug your app, SecHoleUtils will log the calls and errors if they happens:
Code:
pre-KitKat
Log.i("SecHoleUtils", "Received " + TOOGLE_GPS + " intent");
Kitkat:
Log.d("SecHoleUtils", "ToogleGPS. Current mode: " + currentMode + " newMode: " + newMode);
Log.e("SecHoleUtils", "Error toogling GPS");
Log.i("SecHoleUtils", "Received " + ENTER_PIN + " intent");
Log.e("SecHoleUtils", "Error inserting PIN");
Detection of the APK
In order to detect in your app if SecHoleUtils is installed and you can use it, there is a sample code:
Code:
//Test if SecHoleUtils.apk is installed
boolean bSecHoleUtils = false;
try {
getPackageManager().getPackageInfo("com.beemer.secholeutils",PackageManager.GET_META_DATA);
bSecHoleUtils = true;
}
catch (NameNotFoundException e1){}//Not installed. No need to do anything.
If I see interest in the app, I'll add more APIs to it.

[GUIDE] Debugging apps

Debugging apps
This is my multi-post guide on debugging apps.
Android provides its own ways of debugging:
Logcat
The most important aspect when we talk about debugging. Whenever your app crashes, you can find the reason for that in the logs (as long as you install it from your IDE).
However, we can also use it for other ways of debugging. It can help to understand how the app acts and why it does so.
Toasts
Toasts are these small pop-ups you can see in many apps. You can use them for debugging as well.
Debugger in Eclipse or Android Studio
Eclipse and Android Studio have their own debuggers. You can execute the source code step by step and see all variable values during that.
AVDs
If a user reports that the layout does not look great on his device, you can check it using an AVD, often refered to as an emulator. It can help to understand how the app will look on other devices.
Using Google and posting on XDA
Google can help you very much with your problem. If you still cannot figure out what the reasons for your problem are, you can profit by the XDA community power. However, we need some information in order to help you.
This was featured on the XDA portal on June 29, 2013.
Logcat
As I have already stated, logcats are the most important aspect of debugging on Android.
You can use them to get error messages when your app crashed or to print your own debugging information.
Understand error messages
This is one example of an error message you can get:
Code:
06-15 12:45:02.205 805-805/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.nikwen.myapplication/de.nikwen.myapplication.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at de.nikwen.myapplication.MainActivity.doSomething(MainActivity.java:21)
at de.nikwen.myapplication.MainActivity.onCreate(MainActivity.java:17)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more
The code producing the error:
Code:
package de.nikwen.myapplication;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
public class MainActivity extends Activity {
Button myButton;
@[B][/B]Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
doSomething();
}
private void doSomething() {
myButton.setText("Crashing here");
}
}
Now we are going to analyse the error.
The second line is the most important one. It tells you which kind of error ocurred. In this case it is a NullPointerException (NPE).
Code:
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.nikwen.myapplication/de.nikwen.myapplication.MainActivity}: java.lang.[COLOR="Red"]NullPointerException[/COLOR]
The first thing to do now is searching for this type of error. When does it occur?
You come up with something like this:
Thrown when an application attempts to use null in a case where an object is required. These include:
Calling the instance method of a null object.
Click to expand...
Click to collapse
(Source: http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/NullPointerException.html)
Now you know what kind of Exception was thrown. You can get a lot of other useful information from the logcat:
Usually, you get some more information about the error. There should be an explanation why the Exception was thrown:
Code:
java.lang.RuntimeException: [COLOR="Red"]Unable to start activity[/COLOR] ComponentInfo{de.nikwen.myapplication/de.nikwen.myapplication.MainActivity}: java.lang.NullPointerException
It also prints the stacktrace. The stacktrace contains all methods which have been invoked, the last one on the top.
In this case one exception caused another one. In most cases, the one which caused the other one is the one which is interesting for you.
Code:
Caused by: java.lang.NullPointerException
In this case the one which was thrown first is a NPE as well.
Let us have a closer look at the stacktrace:
Code:
[COLOR="Red"]at de.nikwen.myapplication.MainActivity.doSomething(MainActivity.java:21)
at de.nikwen.myapplication.MainActivity.onCreate(MainActivity.java:17)[/COLOR]
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
The ones which are important for you usually are the ones with your package name (the red ones).
At the end of the line it tells you in which file and in which line the error occured.
Code:
at de.nikwen.myapplication.MainActivity.onCreate[COLOR="Red"](MainActivity.java:17)[/COLOR]
Here it is just the part of the code where the other method is called. So we look at the other one. (This most often happens when there are two of your methods. For that reason have a look at the upper one first.)
Code:
at de.nikwen.myapplication.MainActivity.doSomething[COLOR="Red"](MainActivity.java:21)[/COLOR]
It tells us MainActivity.java, line 21.
That is the line:
Code:
myButton.setText("Crashing here");
Remember, we got a NullPointerException. The only variable that can get null in that line is myButton. In fact we initialise it nowhere.
So this is our new onCreate method:
Code:
@[B][/B]Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myButton = (Button) findViewById(R.id.my_button);
doSomething();
}
We solved the error. :victory:
Logcat - part II
Your own debug messages
We can also output our own debugging information that way:
Code:
Log.d("myTag", "myMessage");
or
Code:
Log.e("myTag", "myErrorMessage");
Error messages (produced with Log.e) are shown in red.
The tag can be used for filtering.
It can help us to check specific values when it does not return the right output:
Code:
Log.d("start", "hey");
String[] myStringArray = new String[] {"Hello world", "Debugging is fun (normally not ;))", "XDA is great!!!"};
String all = "Words: ";
for (String s: myStringArray) {
Log.d("String s", s);
all = all + s + ", ";
Log.d("new all", all);
}
Log.d("status", "done");
The output:
Code:
06-15 13:15:03.014 1347-1347/de.nikwen.myapplication D/start: hey
06-15 13:15:03.014 1347-1347/de.nikwen.myapplication D/String s: Hello world
06-15 13:15:03.014 1347-1347/de.nikwen.myapplication D/new all: Words: Hello world,
06-15 13:15:03.014 1347-1347/de.nikwen.myapplication D/String s: Debugging is fun (normally not ;))
06-15 13:15:03.014 1347-1347/de.nikwen.myapplication D/new all: Words: Hello world, Debugging is fun (normally not ;)),
06-15 13:15:03.014 1347-1347/de.nikwen.myapplication D/String s: XDA is great!!!
06-15 13:15:03.014 1347-1347/de.nikwen.myapplication D/new all: Words: Hello world, Debugging is fun (normally not ;)), XDA is great!!!,
06-15 13:15:03.014 1347-1347/de.nikwen.myapplication D/status: done
You can also use the log if one of your methods does not finish:
Code:
for (int i = 0; i < 20; i--) {
//do something
Log.d("i", String.valueOf(i));
}
Log.d("status", "1");
myButton.setText("New text");
Log.d("status", "2");
Log.d("status", "done");
You can figure out the reason for logical errors by printing the required information to the logs.
If there are Exceptions you want to handle but you still want the error standard Java error message discussed in the previous post, use the printStackTrace() method of the class Exception:
Code:
try {
Thread.sleep(5000);
} catch(Exception e) {
e.printStackTrace();
//do something here
}
Toasts
Toasts are these little windows you can see in many apps.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
(Source: http://developer.android.com/images/toast.png)
You can also use them for debugging. You can output your values using Toasts instead of logcat messages.
Using Toasts for debugging is a great option, if you want to actually see the values when you test on a real device with no computer around, e.g. on the train.
It is also helpful if you want a customer to test your app. Using toasts, you can show him that something went wrong.
Do it that way:
Code:
Toast.makeText(getApplicationContext(), "My message", Toast.LENGTH_LONG).show();
(Do not forget the .show()!)
If you invoke this in an Activity, you can also do this:
Code:
Toast.makeText(this, "My message", Toast.LENGTH_LONG).show();
The disadvantage is that they are just shown for a short period of time.
Debugger in Eclipse
The debugger of Eclipse is a very productive tool. It allows you to see the values of the variables in real time. Additionally, you will be able to see and control exactly what your app is doing while it is running.
If we want to start our app in debug mode, we have to run it using the debug button.
To set or delete breakpoints we can right-click on the space left to the source code and select "Toggle Breakpoint". You will notice a blue dot next to the line. When the app is running, it will stop executing the code at the position of the breakpoint. The line with the breakpoint will not be executed.
When you run the app now, it will show a dialog which says that it is waiting for the debugger to attach.
You will also see a pop-up asking you to launch the debug perspective. Hit "Yes".
The code of your app will be executed, but it will stop before executing the line with your breakpoint. The current line which is not executed yet will be marked green.
Now you can decide what should be done next. The proper controls can be found in the debug perspective we opened before.
The one on the left will run the code until the next breakpoint will be reached. This will be the next thing we see if we define another breakpoint and press the "Resume" button:
The red button will disconnect the debugger. If you do this, your app will go on running as if no debugger had ever been attached.
Let us talk about the other buttons. The left one will make your program execute the current line and if it is a method, it will step into this method and you will be able to debug the other method step by step, too. It is called "Step into". The debugger will not be able to step into methods which are not defined by you or any library you added to your project.
If you want the debugger to execute the next line but (if the line is a method) not to step into the method, use the second button called "Step over". It will directly go to the next line.
If you are in a method and want to step out of it, use the third button. That means that it will leave the current method. Note that it will still run all code of the current method. Its name is "Step return".
In the picture above the buttons would cause this:
The "Step into" button will continue with the first line of the doSomething() method.
The "Step over" button will run the doSomething() and pause afterwards.
The "Step return" method will run the onCreate() method until its end and will pause then.
Now let us see how we can get the value of variables.
All variables used in the current method will be shown in the debugger view.
If there is an array, you can view its childs by clicking on the arrow next to it.
You can also view the fields of an object by clicking on the arrow.
If you hover of a variable in the code view, you will see its value, too.
I think that now you see why I call the debugger a productive tool.
And if I had shown you everything you can do with it, it would have been to long to post it on XDA. The ones I showed you are just the basic functions of the debugger.
Debugger in Android Studio
The debugger of Android Studio is a very powerful tool which allows you to see the values of the variables while your app is running on the emulator or a real device. Additionally, you will be able to see and control exactly what it is doing in real time.
In order to debug an app we need to start it using the debug button.
Then we can define or delete breakpoints by clicking on the space left to the source code. A red dot will appear there. When running the app, it will stop executing the code at the position of the breakpoint. The line with the breakpoint will not be executed.
When you run the app now, it will show a dialog which says that it is waiting for the debugger to attach.
The debug view will be opened automatically.
The code of your app will be executed, but it will stop before executing the line with your breakpoint. The current line which is not executed yet will be marked blue.
Now you can control how your app should continue. The proper controls can be found in the debug view.
The one on the left will run the code until the next brekpoint will be reached. It is called "Resume program execution". The other four buttons are for smaller steps. This will be the next thing we see if we define another breakpoint and press the "Resume program execution" button:
Let us talk about the other four buttons. The left one will make your program execute the current line and go to the next line. It is called "Step over". If you do this, it will not step into other methods and debug them.
If you want the debugger to step into the method, use the second button called "Step into". The debugger will not be able to step into methods which are not defined by you or any library you added to your project.
If you are in a method and want to step out of it, use the fourth button. That means that it will leave the current method. Note that it will still run all code of the current method. Its name is "Step out" (Surprise :laugh.
In the picture above the buttons would cause this:
The "Step over" button will run the doSomething() and pause afterwards.
The "Step into" button will continue with the first line of the doSomething() method.
The "Step out" method will run the onCreate() method until its end and will pause then.
Now we talk about getting variable values.
All variables available in the current method will be shown in the debugger view.
If there is an array, you can view its childs by clicking on the plus next to it.
You can also view the fields of an object by clicking on the plus.
To see a certain value you can also hover above the variable in your code.
After that you see that the debugger is a very powerful tool.
And this is just the beginning. You can do even more complex actions with it.
AVDs
I guess that nearly every developer for Android knows them and uses them: AVDs or emulators
They are great for testing your apps on other screen sizes or platform versions.
Before releasing your app, test them on different screen sizes and (most important) on different versions of Android. Some methods are just available on new API versions and crash on old versions. Another thing to mention: If your layout is designed for large screens, it might look bad on small ones. In the same manner phone layout often look ugly on a tablet.
Creating AVDs: Official documentation
ROOTING an AVD: Guide by Androguide.fr
Using Google
Google or any other search engine is great help when you debug your app. Nearly every error which occurs for you has already been experienced by others.
If you want to find out why your app crashes, search for this:
Android <the name of the Exception> <the method which causes the Exception>
Click to expand...
Click to collapse
If it is no Android specific Exception (e.g. a NumberFormatException when using Integer.parseInt("27")), replace "Android" by "Java".
If no method which is written by you is causing the crash, use keywords like these:
Android <the name of the Exception> <the name of the superclass> <when the crash occurs>
Click to expand...
Click to collapse
Example for these could be:
Android TextView setText CalledFromWrongThreadException
Android IllegalStateException Fragment orientation change
Java NumberFormatException Integer.parseInt
Click to expand...
Click to collapse
Often it is the best way to search for the message you find in the logs, e.g.
java.lang.RuntimeException: Unable to start activity ComponentInfo{}:
android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment:
make sure class name exists, is public, and has an empty constructor that is public
Click to expand...
Click to collapse
Posting on XDA
This should be your last option. Try everything you can before posting here. Though posting your problem on XDA is nothing you should be ashamed of.
However, please follow these steps to ensure that we are able to help you properly:
Give us your code.
Do not worry. You do not have to publish all of your code but the relevant parts. That means the class which causes the Exception. If you can exclude some methods to be the reason for the Exception, you do not need to post them. But do this only if you are sure that they are not important for us.
Post a logcat.
As you can see in post #2, logcats are the most important information on the bug and the reasons why it crashes.
Describe the problem.
Tell us when the code crashes. That might be that it crashes when you change the screen orientation, press the menu or back key or when a particular method is invoked. Many of us do not execute your code but just look at it in the browser. Hence we need to know when the code crashes.
Liked this tutorial?
Check out my interactive tutorial on how to use the command line.
very very useful thanks
matt95 said:
very very useful thanks
Click to expand...
Click to collapse
You are welcome.
I am glad that you like it.
Btw, I will update it soon.
Updated the guide:
Post #8
Post #9
This is very helpful! When I was reading this in my book it was a little confusing but now I get it.
FlyLikeAGS3 said:
This is very helpful! When I was reading this in my book it was a little confusing but now I get it.
Click to expand...
Click to collapse
Great. :good:
Posted the guide for the debugger of Android Studio.
Post #6
Added the Eclipse debugging tutorial.
Now I am done.
Post #5
I vote for another sticky by Nikwen!
Zatta said:
I vote for another sticky by Nikwen!
Click to expand...
Click to collapse
Thanks.
If it is a sticky, people will see it. If not, nobody will see it due to the number of new posts every day.
(@mark manning)
I'll look at it later on when I get a sec
Great guide!

How to search StorageFiles

I need a way to search in StorageFiles with dynamically pattern, which comes from a TextBox. The directive "Windows.Storage.Search" doesnt exist in windows phone 8.1 runtime, as i saw. Now my question is, how can i do this in alternative way?
The only way to do it with WP 8.1 since Microsoft ALWAYS fails to implement the important things are to query using LINQ.
Ex:
Code:
var result = (await Windows.Storage.ApplicationData.Current.LocalFolder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName)).
Where(x => x.Name.
Contains(x => txtBox.Text));
That's about all you can do pretty much. (Thanks Microsoft).
Thank you for the example. But it wont work for me, it shows me the following error(s):
Code:
A local variable named 'x' cannot be declared in this scope because it would give a different meaning to 'x', which is already used in a 'parent or current' scope to denote something else
and
Code:
Cannot convert lambda expression to type 'string' because it is not a delegate type
Thats really odd from Microsoft, that they havent implementet the search function like in WinRT (Windows Store App).
The first error is pretty simple. You already have the variable named "x" and it would be very bad if compiler didn't give you that error.
Change the name of the variable to something else that you don't use in that scope and it will work.
And for second problem, try this one:
Code:
private List<string> Result()
{
var result = ((List<Windows.Storage.Search.CommonFileQuery>)Windows.Storage.ApplicationData.Current.LocalFolder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName)).Where(x => x.ToString().Contains(txtBox.Text));
return result as List<string>;
}
private async Task<List<string>> ResultAsync()
{
return await Task.Run(() => Result()).ConfigureAwait(continueOnCapturedContext: false);
}
You should call ResultAsync method and get the result in this way:
Code:
List<string> myList = ResultAsync().Result;
That's not going to work. You can't cast a StorageFile as a string.
To fix my code (simple lambda typo)
Code:
var result = (await Windows.Storage.ApplicationData.Current.LocalFolder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName)).
Where(x => x.Name.
Contains(txtBox.Text));
if(result.Any())
{
// Do shtuff
}
Also, you should never access the .Result of an async task because you never know if it completed yet.
Ok, first error is done, but the second error is still here
Code:
Cannot convert lambda expression to type 'string' because it is not a delegate type
You are missing the point of the TAP (Task Async Pattern).
Both main thread and async method will be in execution in the same time. When the async method finish his work, main thread will stop and catch the result trough the Result property.
TAP is the recommended way of asynchronous programming in C#. The only thing with TAP is to use ConfigureAwait method in non-console type of apps to avoid deadlock.
Sooner or later you will get the result from TAP method. Nothing will get in the conflict with the main thread.
Oh wait, @andy123456 I updated my response. I forgot String.Contains ISNT a lambda .
@Tonchi91, I know all about the TAP. I've been using it since it was CTP. I've seen the awkward situations with threading in WP .
Now... if he did
Code:
List<string> myList;
ResultAsync().ContinueWith(t=> { myList = t.Result; });
I wouldn't be worried .
Ok the errors are gone, but the debugger show me the following exception:
Code:
Value does not fall within the expected range
Is this search method case-sensitive? I tried with an exact input in the TextBox.
Hmmm. Let's see your full code.
its actually only for testing, so i added your code to a button (asnyc) and will show the output in a textBlock.
Code:
private async void buttonTest_Click(object sender, RoutedEventArgs e)
{
//Result();
var result = (await Windows.Storage.KnownFolders.CameraRoll.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName)).
Where(x => x.Name.
Contains(textBox_test.Text));
if (result.Any())
{
// Do shtuff
textBlock_test.Text = result.ToString();
}
}
The error is coming from here
Code:
var result = (await Windows.Storage.KnownFolders.CameraRoll.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName))
andy123456 said:
its actually only for testing, so i added your code to a button (asnyc) and will show the output in a textBlock.
Code:
private async void buttonTest_Click(object sender, RoutedEventArgs e)
{
//Result();
var result = (await Windows.Storage.KnownFolders.CameraRoll.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName)).
Where(x => x.Name.
Contains(textBox_test.Text));
if (result.Any())
{
// Do shtuff
textBlock_test.Text = result.ToString();
}
}
The error is coming from here
Code:
var result = (await Windows.Storage.KnownFolders.CameraRoll.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName))
Click to expand...
Click to collapse
Oh Camera Roll.. You MIGHT need to have the capability to view the camera roll enabled. I forget what it's called, but you need a specific cap in order to view from there. Also, I would try to see if you can use a generic folder instead.
I would try Windows.Storage.ApplicationData.Current.LocalFolder.GetFilesAsync() as your method after the await just to test whether you can read correctly.
Yes but in wp8.1 runtime app, there arent caps anymore. The capability for access to the pictures is simply calles pictures library and is enabled. I have tested it as you said, but it gives me the same exception.
A quick tip: another way to do this is to use the Win32 C runtime API. You can, for example, use the FindFirst/NextFile functions (http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418(v=vs.85).aspx) which support searches using wildcards (* and ? characters in the first parameter). These functions are wrapped in my NativeLibraries classes, but are also just publicly available for third0party developers to call from their own C++ DLLs.
Alternatively, you can use the .NET System.IO.Directory class, which has functions like EnumerateFiles(String path, String searchPattern). This is probably the better way to do it, actually.
Of course, if you want these operations to not block the current thread, you'll need to explicitly put them in their own thread or async function.
EDIT: This also assumes you have read access to the relevant directories. You application data directory works fine, for example (you can get its path from the relevant StorageFolder object). Other directories that can be accessed via WinRT functions may go through a broker function instead of being directly readable.
The point is, that i have an array with filenames. Now i need the StorageFile files which contains these filenames. My idea was to search for these files and return the files as StorageFile, so i can work with these. Or is there a simpler / another way?
http://msicc.net/?p=4182 <-- try this
Thank you, i have already done this and its working. But how can i compare the Files to read, with already read files and take only the not yet read files?

How can I make ChiralCode - Android-Color-Picker appear in a dialog window?

I found the following link 'https://github.com/chiralcode/Android-Color-Picker'. I copied `ColorPicker.java' and `ColorPickerDialog.java' . I've been trying to make that dialog box appear somehow .. but I still can't figure it out. If you run the initial app you can see that it has a color picker dialog button (when you press it that window appears). How can I make something like that?
I tried using this(as he says on that website) :
ColorPickerDialog colorPickerDialog = new ColorPickerDialog(this, initialColor, new OnColorSelectedListener() {
@override
public void onColorSelected(int color) {
// do action
}
});
colorPickerDialog.show();
but I get a lot of errors. I only copied those 2 java files, nothing else. Not even the layout or something like that. What else should I copy in order to make it work ? I'm using Android Studio
I've been trying to solve this for a long time .. but however I try I won't get it done. Thank you
iDaniel19 said:
I found the following link 'https://github.com/chiralcode/Android-Color-Picker'. I copied `ColorPicker.java' and `ColorPickerDialog.java' . I've been trying to make that dialog box appear somehow .. but I still can't figure it out. If you run the initial app you can see that it has a color picker dialog button (when you press it that window appears). How can I make something like that?
I tried using this(as he says on that website) :
ColorPickerDialog colorPickerDialog = new ColorPickerDialog(this, initialColor, new OnColorSelectedListener() {
@override
public void onColorSelected(int color) {
// do action
}
});
colorPickerDialog.show();
but I get a lot of errors. I only copied those 2 java files, nothing else. Not even the layout or something like that. What else should I copy in order to make it work ? I'm using Android Studio
I've been trying to solve this for a long time .. but however I try I won't get it done. Thank you
Click to expand...
Click to collapse
You should probably copy all the files there... if any aren't needed Android Studio will tell you as they won't be used.
Edit: Also you're doing it wrong, have a look at the demo code here & here.
Thank you for that. I will try it now. How should I add the color picker to my layout ?
Edit: I added it to my layout . Using the first demo I get the same values by clicking the button. I tried the second one, but it's a lot more complicated, and I'm getting nowhere. Thank you .
Edit2 : Thank you.I did it. I couldn't have done it without your help.

Categories

Resources