[Q] How can I get this dialog programmatically - Android Software Development

How can I ask user to activate wifi or mobile connection, with a dialog like this (programmatically)?
see the attachments

frx08 said:
How can I ask user to activate wifi or mobile connection, with a dialog like this (programmatically)?
see the attachments
Click to expand...
Click to collapse
Them some AlertDialog...
The data at http://developer.android.com/reference/android/app/AlertDialog.html should get you started building it.
They are just using Positive, Negative, and Neutral to preform different actions then their name would otherwise imply.

I'm looking for the way to ask something like "enable wifi"..
however I reached a solution searching in the android reference:
Code:
Intent wirelessOpts = new Intent(
"android.provider.Settings.ACTION_WIRELESS_SETTINGS");
startActivity(wirelessOpts);
this do the job.. but in the debug emulator I get an error..maybe because I need to add user permissions in the manifest xml.. but I don't know...

Related

[BETA] - Caesura Remote Administration and Lost Device Finder

*****************************
Please note: this is the OLD VERSION THAT IS ATTACHED TO THIS POST. THE NEW VERSION IS AVAILABLE AT:
www.gundersoft.com/pages/downloads/caesura
******************************
***********************************************************
* Agreement:
***********************************************************
Firstly, I want to start out by saying that I have put a lot of hard work into making this app and I am trying to make it free so I would appreciate it if we can keep all criticism on this forum strictly constructive. At the moment, it is a BETA and probably has LOTS of bugs (but I am not aware of them). That is where YOU come in. Anybody who is interested may come download this app in BETA and give me feedback and test it and tell me what I can add/remove/fix. I will hopefully be releasing a final release version this month. Its all up to u how successful it is
I had a lot of free time this month so I have started building an app for android. What is Caesura exactly? Hard question to answer. Its a tool box for those who want to remotely control every aspect of their precious phone, even when out of 3G, or its a way for parents to protect unruly children from danger. So far it can be used for all of the following:
Remote Control Phone Via Text Message
Remotely Block Phone Numbers (for your kids phones)
Get Phone status (battery life, wifi, unread messages)
Remotely send text messages
Forward Texts
Find lost phones by turning volume ALL the way up and ringing, vibrating, and flashing the flash.
In the future I also plan to give it these features:
Ability to track lost phones via GPS and Cell towers
Remote Wipe data capability
Remote Lockout
Remote Password Change
Remote Play Sound (Fun for the occasional prank )
And for those with unruly children:
Sms Alerts anytime the phone leaves its current location
Sms Alerts anytime the owner of the phone exceeds a certain speed limit
What I really need are BETA testers. Anyone interested is welcome to download the APK which is attached to this post. Tell me what u think.
Instructions:
Download the APK from www.gundersoft.com/pages/downloads/caesura and install. Next, the first thing that you DEFINITELY want to do is open the APP and press the menu button, and select Settings. In the settings screen, Press the Set Password button and set a password. Also, insure that the "Require password" checkbox is checked.
Then, on the main screen, check the Enable Service checkbox.
Now, to remote control the phone, either install the APP on another phone and use the "Login to Another Phone" button on the main screen, or send the following Sms to the phone WITH CAESURA that you wish to control:
!login
The phone will then prompt you for a password. At this point, you may reply with a password. If you enter a correct password, you will be granted access.
At this point you can send any of the following commands and the phone will treat them as instruction for what to do:
Please note: any texts send while logged in will be sent as commands and will not reach the remote phone's inbox. Do not forget to run the exit command every time you finish.:
!login - first command to be sent. Logs you in.
password [new password] -sets the password for logging into Caesura.
exit - logs out of the service. ALWAYS do this. you cannot log in from another phone while that phone is still logged in.
toast [text to display] - shows a tiny toast window with some text in it for about 4 seconds
sendsms [number] [message] - remote control the phone to send text message to the specified number
torch - toggle system flashlight
panic - sets volume to high and flashes light and displays custom message on screen (BUGGY, causes app to crash if done repeatedly. Work in progress!)
help [command] - gives specific help for the specified command - (Not available for most commands yet)
status - tells the number of unread msgs, remaining battery life, and whether wifi is on or off
unlock - if the lockscreen of the phone is showing, hides it and unlocks the keys
block [number] - blocks the phone from getting texts from the specified number (WORKS!!)
unblock [number] - unblocks number
blocked - sends a list of numbers that you have blocked
forwardto [number] - sets the number to which all forwarded texts will be sent to
forward [number] - forward texts from a number
unforward [number] - stop forwarding texts from this number
forwarded - sends a list of numbers that you are forwarding
Console:
To remote control the device from within another copy of the APP itself, press the "Login to Another Phone" button on the main screen. This open a window that will ask you for a phone number. Type in the number and the phone will attempt to send a login text message to the phone in question. If successful, you will receive a message in return. To select a command, choose it from the drop down list. Click send. Wait a few, (it can be up to a few minutes if your carrier is slow but took only about 3-10 sec. on AT&T) and you will get a response.
ALWAYS SEND EXIT WHEN YOU ARE DONE OR YOU WILL NOT BE ABLE TO SEND TEXTS TO THAT PHONE THAT IS BEING CONTROLLED!!
License:
In the process of compiling a license...at the moment, just think to yourself, if it seems dishonest or sneaky, its probably going to be against the EULA
No reverse engineering
No reposting on other forums or threads. You are welcome to post a link here, but I wish to insure that all users get the NEWEST possible copy since Im constantly updating it
I release myself from all liability involving this software since it is provided as a free software and I do not offer any guarantees of any sort regarding its soundness, or even that it is fit for a particular purpose.
All abuses of this software are the sole responsibility of the End User.
And with no further ado... good luck and tell me what you think
*****************************
Please note: this is the OLD VERSION THAT IS ATTACHED TO THIS POST. THE NEW VERSION IS AVAILABLE AT:
www.gundersoft.com/pages/downloads/caesura
******************************
**Also, this list does NOT contain all of the commands added since the update.
Reserved
always good to save space for expansion
Looks interesting. I'll try it out.
Edit: Kind of forgot my service is turned off.
Sent from my LG Optimus V using Tapatalk
Sounds good so far, I'd suggest to produce a version that can be installed to system partition (for rooted devices) and stores its settings somewhere in a safe place (possibly system partition as well) so it gets factory reset proof. Also it should have a simchecker option so the owner of the device gets a notification if a new sim is inserted. This way it would always be possible to find and remote your device, even if a thief performs a fr and formats the sdcard.
Hope this is not too much to request, but i think this would make it the ultimate anti theft tool.
--------------------------
tapatalked from vizio vtab1008
Will be trying this as soon as I have time(which might be long,but just sayin').Sounds reaaaaally good.
And because I see potential in this,lemme give you an idea.
There are far too many tools with which you can control (Parts of or the whole of) your PC from your phone,but for the opposite there is nearly nothing.The only app I found that allows for remote control of the phone from a PC is Webkey which,while good in its essence,isn't exactly useful.And it does everything over wi-fi only(Not bad for most but anyway).
So,an app that allows remote control of the phone from a PC in a proper manner is more than welcome and I'm willing to pay for it.
*I know Caesura allows for texting remotely etc,but I'm referring to real remote control,where you can use the phone as if you held it with your hand or something*
No matter if you do it or not in the end,I want to congratulate you for the effort.
tolis626 said:
Will be trying this as soon as I have time(which might be long,but just sayin').Sounds reaaaaally good.
And because I see potential in this,lemme give you an idea.
There are far too many tools with which you can control (Parts of or the whole of) your PC from your phone,but for the opposite there is nearly nothing.The only app I found that allows for remote control of the phone from a PC is Webkey which,while good in its essence,isn't exactly useful.And it does everything over wi-fi only(Not bad for most but anyway).
So,an app that allows remote control of the phone from a PC in a proper manner is more than welcome and I'm willing to pay for it.
*I know Caesura allows for texting remotely etc,but I'm referring to real remote control,where you can use the phone as if you held it with your hand or something*
No matter if you do it or not in the end,I want to congratulate you for the effort.
Click to expand...
Click to collapse
There is Droid Explorer, it has a screencast option to do this, but you need to be connected to USB.
--------------------------
tapatalked from vizio vtab1008
I came across this by using the search for a remote app on lost devices. Will get myself a copy of the apk, you still need testers? ^^
I think this was abandoned... j use 'android lost' instead, has the same functionality...
----------------------------------------
tapatalked from GalaxyS
This has not been abandoned. You can download it from www.gundersoft.com/pages/downloads/caesura
I still need testers. It's not the same as the other app...it has quite a few more features.
Sent from my MB860 using XDA App
if i undersand it right caesuara will send you my numbers and give you the capability to connect to my phone is that right?
If yes why should i use it?
If i missunderstand i am sorry for asking stupid questions *grin
Sent from my HTC Desire HD using XDA App
It sends phone number only (for usage tracking by area code...this is a beta thing only). Also, if you set a login password, no one but you can connect.
The only command that can be run without password is factory lockout. Let's say user abuses software and I am contacted by law enforcement: I can disable caesura remotely. That is all.
I've never released this app publicly and I was scared to death it would be misused and I'd be liable. See, all of my beta testers locally have been teens, and they have a way of using this stuff immaturely. This my way to cover my butt just in case
Sent from my MB860 using XDA App
And no worries, if I really had any malicious intentions, I wouldn't have told you about the phone number thing would I?
Sent from my MB860 using XDA App

[GUIDE] Using the Share Intent

Hello everyone,
While making an app, I wanted to let the user be able to share some content (shameless plug: from a clearable EditText). So, I looked up how to do this.
In this thread, I will share (pun not even intended) with you how to use the Share Intent yourself, so that your users can also quickly involve anyone they know in what they're doing.
There are some things that I am going to assume you've done:
- You have made your base app
- You have a Button done and set up, only needing a method to execute the Share Intent.
Now, let's get to it!
Step 1 - The method:
First, you have to set up the method. As always, give it a nice and descriptive name, so everyone (including you later, believe me that you'll need it) knows what it does.
Of course, this just follows standard syntax. I'm going to name it share, because simple!
So, you'll get this:
Code:
private void share() {
// This is the method where we share some content
}
Step 2 - The Intent:
You want to make sure that Android recognises your Intent as being a Share Intent. Of course, because of the flexibility of Intents, this is also easily done. Just declare another parameter, which isn't the usual set of Classes.
My Intent will be called shareIntent.
Like so:
Code:
Intent shareIntent = new Intent(android.content.intent.ACTION_SEND);
Step 3 - The type:
When sharing content in Android, you have to let the system know what you're sharing. Naturally, it has to react differently to different types of content. An image can be handled by certain apps, while others can only handle text. Apart from that, the apps have to process the items differently.
This is done by declaring the MIME type, which are unique identifiers for different data types.
Some possible types are text/plain, image/gif and video/mp4.
In this case, we are going to share some text. This is done by adding the following line under the Intent declaration:
Code:
shareIntent.setType("text/plain");
With the setType method, you could target specific apps. However, this is obviously not a good idea. If a user doesn't have that app on their phone, it'll cause trouble. Therefore, just use the right type and let the user select the relevant application.
Step 4 - The Content:
Now for the real work. What are you sharing? Of course, text! But you have to give the Intent that text, because it won't just snuff it out by itself.
How do we do this? Simple, again.
Just create a String and use that. Of course, you can hard code a String in the Intent, but it's best to use a variable. After all, you're probably going to be sharing dynamic content.
This is done as follows, though you should really know this by now:
Code:
String sharedString = "Hey, we are sharing!";
Step 5 - The extras:
You have to also give the Intent its extra information. For this example, we'll be setting two types of extras: a subject and the body.
This way, there is flexibility. If the user chooses to share the text using an email application, the subject will also be used. If they don't, it won't be used.
This is done by adding the following lines to your sharing method:
Code:
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "This is the subject");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, sharedString);
Step 5 - The Chooser:
Whenever you share something, you see the Dialog pop up for you to select the app you want to use in your sharing the content. This is the next and last step in this guide, and is basically just starting the Intent with a special parameter.
Not every type of media can be shared to every app. When you share certain content, Android looks at what apps have declared themselves candidates for that MIME type.
So, if you are not seeing certain apps appear, check whether the app can work with that MIME type!
Start the Intent like this:
Code:
startActivity(Intent.createChooser(shareIntent, "Share via"));
Of course, the title to the chooser doesn't have to be "Share via". It can be any other text or variable (keep this in mind for apps that have translations!).
Facebook doesn't do this right! The facebook app doesn't do sharing right, so it will probably not show up in the list of apps that you might see when following the tutorial. To counteract this, target the app using the specific API.
Have fun sharing, and thanks for reading!
P.S.: Images can be added, should anyone want me to do so.
I also found this for the ActionBar very interesting: http://developer.android.com/reference/android/support/v7/widget/ShareActionProvider.html
nikwen said:
I also found this for the ActionBar very interesting: http://developer.android.com/reference/android/support/v7/widget/ShareActionProvider.html
Click to expand...
Click to collapse
True, the ShareActionProvider is quite nice but has one really big downside: You have to update it with the Intent BEFORE the user clicks the item, and there is no workaround. So if you want to generate an image when the user clicks share, you cannot use the ShareActionProvider.
And thanks for the guide OP!
SimplicityApks said:
True, the ShareActionProvider is quite nice but has one really big downside: You have to update it with the Intent BEFORE the user clicks the item, and there is no workaround. So if you want to generate an image when the user clicks share, you cannot use the ShareActionProvider.
And thanks for the guide OP!
Click to expand...
Click to collapse
Wouldn't it be possible to extend the class? Maybe it could be achieved that way.
nikwen said:
Wouldn't it be possible to extend the class? Maybe it could be achieved that way.
Click to expand...
Click to collapse
Could work, but I have no idea what methods to override... I need to have a closer look at this.

SQLite - Connection Pool Error

Hey there,
I have an issue here and I am not really sure on how to solve it.
The Logcat says:
The connection pool for database 'my Database' has been unable to grant a connection to thread 1 with flags 0x2 for 240.0000 seconds
Click to expand...
Click to collapse
After this, my app freezes and I can do nothing more, than uninstall the app and create the database new. A restart with the taskmanager does not repair it.
In my app, I have an intent, which downloads every hour some data per Bluetooth. This data is the stored in my database. If I try to access the database in this time, the issue apears.
For now, I made sure, that only one instance of the SQLiteHelper is opened, so I have this static method:
PHP:
static BatteryManager getInstance(Context c)
{
if(bm==null)
bm = new BatteryManager(c);
return bm;
}
Right now, I am inserting the data with a simple sql command and :
PHP:
this.getReadableDatabase().execSQL(sqlCommand);
I know, that there are cleaner ways, but this would not solve a problem like this, right?
After some googling I found out, that a content provider would help me, is this correct?
What would you suggest?
Thank you for your help!

[AOSP] App Op for internet access

Hi everybody,
one main reason I am staying on Kitkat and not switching to Lollipop is that it runs on Art and thus Xposed is not working (yet). I want it mainly because of XPrivacy to block internet access for certain applications.
Because that's the main reason to have XPrivacy I searched for an easier way (and maybe built-in) way to block internet access.
I finally found some time to dig into the AOSP source code and investigate how the app ops are implemented. I will first describe my development process and then give the code. If you're only interested in code go to the end of this post.
I noticed that it is rather simple to add a new toggleable permission to the AppOpManager (additionally I discovered this commit).
Well, adding a new operation does nothing by itself. The framework has to check somewhere if it is allowed to perform a specific operation.
In my investigations I discovered that nearly* all requests for a network socket pass the class java.net.InetAddress, namely methods lookupHostByName(String, int) and getByAddress(String, byte[], int).
* I say here nearly because I was not able to intercept the internet connection of the stock AOSP browser (XPrivacy has the same problem btw).
java.net.InetAddress is part of the standard Java implementation (platform_libcore) and thus cannot access framework classes and methods. I solved the problem by creating an interface and a static field holding an instance of the interface. Now this field has to be initialized so the method of the interface can be called.
The next step was to find the proper place where that initialization should take place. I chose a static initializer of the android.content.Context class.
Reasoning: every application runs in its own context. So when creating the context for an app the static field will be initialized. Otherwise I sometimes run into NPEs.
I also wanted to have consistent behavior between getting the connectivity state and the actual ability for accessing the internet. So I also changed the com.android.server.ConnectivityService.getNetworkInfoForType(int) method to fake no connection available.
Overall these changes included modifications in three projects which you can find in my Github. As a base I took the stock AOSP code at android-5.0.0_r7 so it is as developed and generic as possible.
platform_packages_apps_settings:
add op for internet access
platform_frameworks_base:
add op for internet access
block internet access if not allowed
fake no connection if internet access is not permitted
platform_libcore:
add an hook into methods that correspond to internet connections
All code is tested and working fine for me.
I hope some rom developers will read this post and apply these changes to their roms .
If anyone has suggestions on improvements or how to block apps like the AOSP browser please comment.
how can i block any specific app from access internet in aosp and where i can find API for Requesting internet
I want to customize os, there How can i restrict specific applicaion from accessing internet .
Actually i want to know where i can set network policy rule so that i can restrict internet.
please let me know if anone having any suggestion.
NetworkPolicyManager
ConnectivityManager
Inetd
It is neccessary to implement in all these or in any one to restrict internet ?
anu10121998 said:
I want to customize os, there How can i restrict specific applicaion from accessing internet .
Actually i want to know where i can set network policy rule so that i can restrict internet.
please let me know if anone having any suggestion.
NetworkPolicyManager
ConnectivityManager
Inetd
It is neccessary to implement in all these or in any one to restrict internet ?
Click to expand...
Click to collapse
I am running A11, Bliss (And I think its also in A8 Oreo). If you go into Settings>Apps & Notification>"see all apps">"App Name">Mobile Data & WiFi>Allow network Access ==>OFF This has worked a treat for me. The only caveat is that for the first week, internet content was sometimes being displayed, from what I can only assume was a cache. After a week, its as I expect.
ie No coding required. Interesting that android explicitly blocks removing the internet permission (but not other permissions) via a root shell, but works fine using the even easier GUI

Intent filters

Ok so i used to be a very experienced actionscript user. But i recently wanted to get back into programming so im learning java now or rather trying to.
So im trying to understand the xml side of this so far and have some questions im hoping u guys can answer.
activities
So as i understand it an activity is a screen in an app. So for example the standard launcher on my phone has pages of apps on my main screens. Each one of those would be an activity? And then another activity for when i press the button to display all installed apps?
Have i understood that properly?
intent filters
This is where im getting confused. Ive googled it and read as much as i can find. As i read it, feel like someones explaining rocket science to a 5 year old.
The words component and instances is being thrown around enough that i got no clue whats even being said. What i have understood is it gives data to the activity.
So a best guess from my partwould be its telling it how the screens going to work or maybe like if theres going to be a button on it maybe. Or perhaps it means something different like just the properties sort of stuff like screen size or stuff of that nature.
As u guys can probably tell im confused beyond comprehension. I got no idea how good my grasp is of any of this. But if theres someone out there kind enough to dumb it down a bit so normal people can understand it. Id be very gratefull.
Bump
Bump
Hey,
unfortunately i cant answer your question. This is a part of android I don't understand too.
I think you should post your question again in the Question and Answer forum of XDA. http://forum.xda-developers.com/android/help maybe there is an developer who can help you.
Greetings
Thanks ill post there and see if it makes any difference
Android apps run in sandboxes. Consider a huge box partitioned into 'n' number of sections. Each partitions represent a place in android environment where app can reside. By sandboxing, app are given unique ID(UID) when they start a process. Only apps having same (UID) can access the app's resources so no malicious app can peek into the resources of other app.
If apps cannot see other resources, how could they communicate within apps? Thats where intent comes in. Intents are like post letters and android is the postman. You can either give:
1. Recipient address, here, the package name of the app for which the intent is to be sent and may include your data in the intent if there is any and the postman (android) delivers it to the right person (target app). This is also known as explicit intent because you know the target class to call
2. Intent filter - This is not as specific as the first one. Here, your app has to perform something using an external app but your app doesnt know of the other apps which could perform the action. So, this time it will go for a broadcast and say "Hey! I need to take a picture! All camera apps please come in" and the broadcast is sent by android which displays list of apps which respond to this broadcast. When the user chooses the app to perform the action, the app fires, performs the task for your app, return the data to your app in form of intent result.
To register an app to respond to this type of intent, the app specifies something called intent-filter in their manifest which says the android, in our example context "I can perform camera action". So next time intent for camera action is sent, the app is in the list of apps to perform action with. This type of intent in implicit intent as you let the android and user decide the app. You can also specify your own custom intent-filters apart from standard android ones.
vijai2011 said:
Android apps run in sandboxes. Consider a huge box partitioned into 'n' number of sections. Each partitions represent a place in android environment where app can reside. By sandboxing, app are given unique ID(UID) when they start a process. Only apps having same (UID) can access the app's resources so no malicious app can peek into the resources of other app.
If apps cannot see other resources, how could they communicate within apps? Thats where intent comes in. Intents are like post letters and android is the postman. You can either give:
1. Recipient address, here, the package name of the app for which the intent is to be sent and may include your data in the intent if there is any and the postman (android) delivers it to the right person (target app). This is also known as explicit intent because you know the target class to call
2. Intent filter - This is not as specific as the first one. Here, your app has to perform something using an external app but your app doesnt know of the other apps which could perform the action. So, this time it will go for a broadcast and say "Hey! I need to take a picture! All camera apps please come in" and the broadcast is sent by android which displays list of apps which respond to this broadcast. When the user chooses the app to perform the action, the app fires, performs the task for your app, return the data to your app in form of intent result.
To register an app to respond to this type of intent, the app specifies something called intent-filter in their manifest which says the android, in our example context "I can perform camera action". So next time intent for camera action is sent, the app is in the list of apps to perform action with. This type of intent in implicit intent as you let the android and user decide the app. You can also specify your own custom intent-filters apart from standard android ones.
Click to expand...
Click to collapse
Gave u a thanks fkr that very useful responce. Thank you. So if ive understood this right. If i want to take a picture for example the intent filter part basically calls out for an external app to perform the action. With intent filter so basically when an app asks u with that menu what app youd like to choose thats an intent filter? And implicent thats the same menu or android just chooses it for you? Im trying to picture it from the user-side
Recipient address seems straight forward. You know u need an app and what its called. So u dont even need the user to select anything.
scorpafied said:
Gave u a thanks fkr that very useful responce. Thank you. So if ive understood this right. If i want to take a picture for example the intent filter part basically calls out for an external app to perform the action. With intent filter so basically when an app asks u with that menu what app youd like to choose thats an intent filter? And implicent thats the same menu or android just chooses it for you? Im trying to picture it from the user-side
Recipient address seems straight forward. You know u need an app and what its called. So u dont even need the user to select anything.
Click to expand...
Click to collapse
Your understanding on implicit intent is correct. To make it even more short an precise,
An intent is an abstract definition of the operation to be performed by the app
Click to expand...
Click to collapse
When the target action is known, say you invoke a second activity of you app. You know the target action (the class name), that is your implicit intent. You decide what action to perform without user intervention here. Explicit usually needs user input for inter-app communication to take place.
Examples of few implicit intents:
Starting an activity
Starting a service
vijai2011 said:
Your understanding on implicit intent is correct. To make it even more short an precise,
When the target action is known, say you invoke a second activity of you app. You know the target action (the class name), that is your implicit intent. You decide what action to perform without user intervention here. Explicit usually needs user input for inter-app communication to take place.
Examples of few implicit intents:
Starting an activity
Starting a service
Click to expand...
Click to collapse
Ok cool. So recipient is when we choose the app. Intent is whwn they get a menu to choose it. And implicent is is when android chooses it for them.
Sounds simple enough. Thanks for all the help buddy
And would i be right in assuming that the actions we put in intent filters and the others in form it of stuff like when its triggered, how often and so forth?

Categories

Resources