I searched in the web but i couldn find a single article dealing in a straight forward way on how to find the vibrate on/off logs in logcat. If anybody who is aware of the procedure, please enlighten me. Once again i need it specifically to check if my app triggers vibrator or not...
Vibration data is not logged by default. Fortunately, there is some code in HardwareServices.java that can be enabled to provide exactly what you want. Keep in mind that since this is part of the framework, changing it will require you to rebuild and reflash your device. If you are running on an ADP or the emulator this should be easy. It might be a bit more challenging if you are doing this on another device.
Locate the following code and replace false with true and you should be all set.
if (false) {
String s = "";
int N = pattern.length;
for (int i=0; i<N; i++) {
s += " " + pattern[i];
}
Log.i(TAG, "vibrating with pattern: " + s);
}
Related
I am trying to check whether an external application (i.e. not the one I am writing, but another one running on the debug device) has draw-over permissions. However, regardless of the method I use, I always get "false" as answer, whence I know for certain that said application can draw over other apps. In fact, not only I explicitly gave it permissions through the Settings interface, but I actually witnessed it performing a view overlay.
This is the first method I used:
pm.checkPermission(Manifest.permission.SYSTEM_ALERT_WINDOW, "target.package")
This is the second method I used (packageInfo being the PackageInfo object associated with "target.package"):
boolean requestedPermissionGranted = false;
for (int i = 0; i < packageInfo.requestedPermissions.length; ++i) {
if (packageInfo.requestedPermissions[i].equals(Manifest.permission.SYSTEM_ALERT_WINDOW)) {
requestedPermissionGranted =
(packageInfo.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0;
break;
}
}
hasPermission = requestedPermissionGranted;
Both expressions return false. By the way, I verified that packageInfo.requestedPermissions actually contains SYSTEM_ALERT_WINDOW.
I searched far and wide, but I could not find any topic that would answer my doubts. I only managed to find threads about how to check an app's own permissions, which I am not interested in.
P.S: I cannot use the shell through getRuntime().exec() and list active windows, as I get permission denied.
I created an app. I want my one app only per mobile but i can create clone of my app using Parallel Space-Multi Accounts. So my question is how to stop to making clone of my app. Is android have any unique identifier, which is not alterable even if user reset the phone?
I think there is not a way to prevent "Parallel Space" to clone your app, that is something related with android system.
A simple workaround I use is to check whether the Parallel Space app is installed(ps package name: com.lbe.parallel.intl).
public boolean isAppInstalled(String packageName) {
try {
getPackageManager().getApplicationInfo(packageName, 0);
return true;
}
catch (PackageManager.NameNotFoundException e) {
return false;
}
}
As you can guess it is not reliable since many different apps can be used for this purpose. I didn't go further for my case but one thing that comes to my mind; if you have file write permission you can create a global file and put something there to check while opening your app.
Someone who knows how such apps work can provide better answers. If they are changing something in your apk while copying, then you can check those changes or hashcode of the apk, but it seems that they run your app in a virtual os, so this may not lead to a solution.
And there is not a successful unique id on android unfortunately. That is something I hate about android. I check different identifiers like deviceid, imei, mac address etc.. but parallel space creates new values for all of them.
After I searched a lot for a solution to stop the app cloning, I came across this idea, which is to check the path in which the app data is installed on the phone.
The following code explains the idea further:
int APP_PACKAGE_COUNT = 2; //----> my app package name is com.test.app the number is count of dots in package name
private void checkClonner() {
String path = this.getFilesDir().getAbsolutePath();
int count = getDotCount(path);
if (count > APP_PACKAGE_COUNT) {
throw new RuntimeException("This app does not work in a cloning environment");
}
}
private int getDotCount(String path) {
int count = 0;
for (int i = 0; i < path.length(); i++) {
if (count > APP_PACKAGE_COUNT) {
break;
}
if (path.charAt(i) == '.') {
count++;
}
}
return count;
}
Hi there I am making my app and I am worried that I might have left some permissions out and can really never be sure I have used the right permissions can you put in any sort of code to see what my app is actually using? or something like that as it is always a guessing game for me when selecting my permissions as I can never be sure.
Heres an example I make a "Check for Updates" Button. From that I launch an Intent to go to my app in the market is that using the internet connection ? or am I just using an Intent because some people will not have a working data connection so would I have to write access full network or something like that? Its just really confusing me
I think u have to check it during testing phase of apps.if there is not proper permissions given by u then the apps give error and u can add proper permission according to error.
Here is an example to walk through permissions:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PackageManager pm = getPackageManager();
try {
PackageInfo pi = pm.getPackageInfo("<INTERESTING PACKAGE NAME>", PackageManager.GET_PERMISSIONS);
if ((null == pi.requestedPermissions) ||
(pi.requestedPermissions.length == 0)) {
Log.d("NOTE", "Package has NO permissions!");
return;
}
for (int i = 0; i < pi.requestedPermissions.length; ++i) {
Log.d("NOTE", pi.requestedPermissions[i] + " " + checkCallingOrSelfPermission(pi.requestedPermissions[i]));
}
} catch (NameNotFoundException e) {
Log.d("ERR", "Package name is wrong!");
}
}
Edit: your question seems to ask what permissions your app is using; this code tells your app what permissions you've requested. If you want to know what is being used, you need to strip all permissions from your app (which will cause runtime errors if you actually need any of them), and then through reading error logs and/or incrementally adding permissions until things work correctly, determine by hand what is actually needed.
I would like to detect the unknown phone number in my call logs list.
An unknown number on the phone is either -1 or -2.
My question is how to detect this type of call?.
I try to detect with :
number = Integer.parseInt(number);
if(number < 0){
}
but it is not working.
Try the following:
1) Log everything.
Put
Log.debug("ClassName", "number = " +number);
2) number = Integer.parseInt(number);
does not look quite right.
try
assuming incomingPhoneNumber is defined as a String.
String incomingPhoneNumber;
try{
int phoneNumber = Integer.parseInt(incomingPhoneNumber);
}catch (Exception e) {
Log.debug("ClassName", "error = "+e.getMessage());
}
in eclipse you need to goto window -->Show View --> Logcat to and examine the log message but you should also just set breakpoints and run in debug mode. Step one line at a time.
Tell us if you get a negative number for the incoming call.
3) Place breakpoints at the very beginning and run in debug mode. Tell us what you get.
4) Communicate with the user questions. People are trying to help but you need to answer our questions for us to help you. For example we do need to see the definition for number to know if
the code is going to work.
I'm a complete newb. I'm trying to port this simple program I made in class to an Android app. It's just suppose to print out " I love Computer Science!!" a certain amount. But I'm suspecting the while loop is causing my program to automatically force close. I've searched and found that I need to make a thread, but I can't find a similar situation.
Here's my onCreate method:
public void onClick(View v)
{
int number = 1;
int printed = 0;
int limit = 0;
int count = 0;
String countString;
second.setText("How much do you love Computer Science?");
countString = howMuchEditText.getText().toString();
count = Integer.valueOf(countString);
printed = count;
while ((count -1) >= limit)
{
third.setText(+number + " I love Computer Science!!");
count -= 1;
number ++;
}
fourth.setText("This printed " +printed + " times.");
}
});
}
}
Could anyone help me fix my force close?
Android only allows your application's handlers five seconds to execute before you'll get an "App not responding" message. Depending on the loop count, your onClick method could easily exceed that limit.
If you want to display an automatically updating counter, you will need to launch an asynchronous task that executes in the background.
Here is a quick tutorial on AsyncTask, but you will need to learn more about the fundamentals of the Android platform before it will make sense. Good luck!
To add to the previous answer, AsyncTask is not quite the answer either. This is because your modifications of the TextView cannot be done on a background thread—UI calls are only allowed on the main thread. To schedule periodic tasks on the UI thread, create yourself a Handler object, which has various post methods you can call to run tasks after a specified interval, or as soon as possible.