Launch any application by command line - Android Software Development

Hello!
I would like to program a "task switcher". For that, i got all the running apps with this command:
Code:
List<ActivityManager.RunningTaskInfo> allTasks = activityManager.getRunningTasks(30);
So that's nice, i can kill every one of them i want with the ID, but i cannot understant how to launch one of the.
I tried the startactivity, but i need an intent, i am not able to figure how to create the intent...
Could you please help me?
Thank a lot.

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?

set sim pin

hi,
is there any way to set the sim pin by my applikation?
we don't want our customers to know the sim pin, so our applikation will know it (encrypted config file). if the device needs the sim pin, it shouldn't prompt the user for a sim pin. my application should set it for the user.
Maybe the following code would be helpful for you:
Code:
TelephonyManager tm =
(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
Class clazz = Class.forName(tm.getClass().getName());
Method m = clazz.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony it = (ITelephony) m.invoke(tm);
it.supplyPin("1111");
Please keep in mind that you also need ITelephony.aidl from Android sources.
rwxer said:
Maybe the following code would be helpful for you:
Code:
TelephonyManager tm =
(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
Class clazz = Class.forName(tm.getClass().getName());
Method m = clazz.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony it = (ITelephony) m.invoke(tm);
it.supplyPin("1111");
Please keep in mind that you also need ITelephony.aidl from Android sources.
Click to expand...
Click to collapse
thank you very much.
can you please tell me, where to get the right ITelephony.aidl? i tried searching in my sdk folder, but didn't found anything. google found a couple of different versions. what should i do exactly with the aidl file?
bassmaster said:
thank you very much.
can you please tell me, where to get the right ITelephony.aidl? i tried searching in my sdk folder, but didn't found anything. google found a couple of different versions.
Click to expand...
Click to collapse
I used aidl from source repository http://android.git.kernel.org/ , version 2.2. You can try the one you found.
bassmaster said:
what should i do exactly with the aidl file?
Click to expand...
Click to collapse
Did you try to google?
http://developer.android.com/guide/developing/tools/aidl.html
Place ITelephony.aidl in package com.android.internal.telephony in your source dir. After that java classes should be generated from .aidl files and compiled if you're using standard build script.
I added “ITelephony.aidl” and the code to my app. It all works fine. Thank you.
But now I have the following problem:
My App starts within the device. While booting, the sim pin dialog request appears. This screen is blocking everything - including the start of my app.
How can I avoid that?
The only workaround known to me is to do the following:
I enabled the flight mode before I shut down the device. After reboot my app starts, disables the flight mode and sets the pin.
But I don't know an efficient way that always starts the device in flight mode.
Can you help me please?
You can try to handle android.intent.action.BOOT_COMPLETED intent (see example http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/) and provide sim pin code just after boot. Don't forget to add permission android.permission.RECEIVE_BOOT_COMPLETED

[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