I use the following code to forward sms, but a system prompt message displayed, how can set system preference programmatically let prompt message don't display?
private static void ForwardSMS(MSms myMSms, MRule rule) {
SmsManager smsMgr = SmsManager.getDefault();
for (String toAddress : rule.receiverNumberList) {
smsMgr.sendTextMessage(toAddress, null, myMSms.body, null, null);
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(PublicPar.myContext);
if (prefs.getBoolean("SaveSentBox", true)) {
SaveToSentBox(toAddress, myMSms.body);
}
}
}
This kind of prompt is for the users' own protection, and the Android API does not allow developers to disable it. So in short: There is no way to do this legitimately.
See, The image you have pasted here is asking the user about giving the permission to the app for sending SMS which may cause him money. Wouldn't you like to be warned in such cases where you can loose your charge because of the App.? So the Android doesn't provide any authority to the developers by which they can harm users credits or charges without even telling them.
But yes, as you can see there are options provided to "Remember the Choice". That means if users is aware of this fact once, and allows the app by clicking "Always Allow", next time there will be no popup to the user before sending the SMS.
So no matter what the app is, the Android API will always be loyal to the user and tell him about the loss me may suffer because of any App.
Related
I recently started learning Android to port my iOS app to Android.
User registration in my app is optional, hence the user can decide to get started right away without any delay. However I still need a form of identification against fraud and if the user has passed the first week of free trial. Otherwise the user can just keep deleting and reinstalling the app to use it for free, forever.
On iOS I have solved the problem through the keychain. Any values stored in there remain there even after the app has been uninstalled.
import KeychainAccess
let keychain = Keychain(service: Constants.keychainServiceID).synchronizable(false).accessibility(.alwaysThisDeviceOnly).accessibility(.alwaysThisDeviceOnly)
let deviceId = UUID().uuidString.lowercased()
keychain["DEVICE_ID"] = deviceId
I don't seem to find anything like that on Android.
A unique Device ID doesn't seem to be available either based on this answer
Hence is there a way to achieve this or do I have to make user registration mandatory?
UPDATE:
In iOS when a keyChain value is set, the user can't ever update or delete it. Even after the app is uninstalled. During unit testing I can delete the keychain entry like this:
let keychain = Keychain(service: Constants.keychainServiceID).synchronizable(false).accessibility(.alwaysThisDeviceOnly)
do {
try keychain.remove("DEVICE_ID")
} catch let error {
print("error: \(error)")
}
Can I do that in Android?
More easily you can do like this, this is a wrapper on shared preference.
https://github.com/kishandonga/EasyPrefs
public static void setUniqueId(){
if(!Prefs.read().content("is_unique_id_set", false)){
String id = UUID.randomUUID().toString();
Prefs.write().content("unique_id", id)
.content("is_unique_id_set", true)
.commit();
}
}
public static String getUniqueId(){
return Prefs.read().content("unique_id", "");
}
Cases when unique id changed
App uninstalled and then reinstalled
Clear cache or reset
I am using Google Cloud Messaging and to manage the users devices server side im storing the GCM Registration ID and the Users Device ID in my Database. You can get the Device ID like that:
public static String getDeviceID(Context context) {
final String deviceId = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
if (deviceId != null) {
return deviceId;
} else {
return android.os.Build.SERIAL;
}
}
Since Android 6.0 i have a problem with that because to read the Devices ID you need to use the dangerous permission android.permission.READ_PHONE_STATE. So when the user uses my App and the automatic background process to register for the GCM Service he get's automatically asked to grant permission for make and manage phone calls which, in my opinion, is totally confusing for the user. He would not understand why the app needs to make and manage phone calls and i also dont want another dialog box to explain the user why the app needs this permission. It would make the app complicated and somehow frustrating for some users.
I want to get around this so i have to ask if there is any alternative way to uniquly identify a users device without needing any dangerous permission.
It has to fullfill following requirements:
It must be unique
It must be always the same id for a single device also after uninstalling and reinstalling the app
The reason for that is simple:
The user can have multiple devices
There can be multiple users on one device
Ofcourse i could just set my target SDK to < 23 but some day you have to update your system anyway when you need new features from the 6.0 or greater API.
I also dont want to give the user the freedom of decision for that purpose because if the user does not grant the READ_PHONE_STATE permission it would mess up the whole live update, messaging and synchronization system of the App.
I am making a Chrome/Android/iOS app using the cca toolchain. I am using the chrome.identity API to get an access_token to interact with Google APIs.
When I set interactive to false (immediate to true) the app is able to get the token without showing the permissions dialog again, but it still shows the account chooser every time on my Android device. This ruins the app experience because every time it is opened the user gets an annoying dialog. How can I make the app remember the chosen account after the first time, like it does with the permissions?
On Android, you can specify accountHint in the details argument of calls to getAuthToken. For example:
var details = { interactive: true, accountHint: 'email#address.com' };
var callback = function(token, account) { ... };
chrome.identity.getAuthToken(details, callback);
This will bypass the account chooser dialog. Note that the callback has account, which can be stored for this purpose.
Unfortunately, this is Android-only; Chrome on desktop doesn't like it when you add extra stuff to details. You'll need to use chrome.runtime.getPlatformInfo to determine what platform you're running on, so that you can create and pass the right details object. On Android, platformInfo.os will be cordova-android.
I had an idea for an android security app, but looking over the Device Administrator api documentation, I can't see if it's even possible. I want the app to be able to set the password used to unlock the phone. It would need to set the password without input or confirmation from the user.
Anyone know if it's even possible, and if so, is there any documentation for it?
Found what I was looking for, it can be done per
http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#resetPassword(java.lang.String, int)
public boolean resetPassword (String password, int flags)
Added in API level 8
Force a new device unlock password (the password needed to access the entire device, not for individual accounts) on the user. This takes effect immediately. The given password must be sufficient for the current password quality and length constraints as returned by getPasswordQuality(ComponentName) and getPasswordMinimumLength(ComponentName); if it does not meet these constraints, then it will be rejected and false returned. Note that the password may be a stronger quality (containing alphanumeric characters when the requested quality is only numeric), in which case the currently active quality will be increased to match.
The calling device admin must have requested USES_POLICY_RESET_PASSWORD to be able to call this method; if it has not, a security exception will be thrown.
Parameters
password The new password for the user.
flags May be 0 or RESET_PASSWORD_REQUIRE_ENTRY.
Returns
Returns true if the password was applied, or false if it is not acceptable for the current constraints.
I dont think it is possible at all, since every app runs in kind of a sandbox to forbid for example malware executing something like you mentioned.
Looking at this: http://developer.android.com/guide/topics/admin/device-admin.html
There seems to be a way for an app to ask for a password:
Set a password for the device
This code displays a user interface prompting the user to set a password:
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
startActivity(intent);
However, I'm not sure you can do this from within the app, silently without any user input. Also, Device Administration apps does not seem to be a normal apps and seem to be intended for corporations/institutions.
I have an app where I need to be able to send SMS messages. I have the code to send them directly, but I would like to give the option to use Google Voice to users who don't have messaging plans. Does anyone know how to do this? I can't seem to find the way. Here is the way I am doing it now:
StringBuffer buffer = new StringBuffer();
buffer.append("GEOC ");
buffer.append(mLogType.getSelectedItemPosition() == 0 ? "#" : "x");
buffer.append(mGeocache.getWaypoint()).append(" ");
if(mLogEdit.getText().length() > 0)
{
buffer.append(mLogEdit.getText().toString());
}
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("41411", null, buffer.toString(), null, null);
You want to use an SMS Intent.
That will give the user the option to select (or skip this step if he already have a default option) which SMS sending utility he want's to use.
several applications register themselves as such, such as skype, yahoo hub, google voice, etc.
So using a Intent, you tell android to use whatever the user wants to send the text message to a sms recipient.
It's my belief that the user must have a google voice account setup and have the voice app installed. Then when you fire an intent to send an sms it will be their preference to use google voice or not.
I've found a site where they've written their own google voice java library that you can import into your app and use. I just downloaded it yesterday so can't help with specific yet, but go ahead and take a look. It looks really promising.
http://code.google.com/p/google-voice-java/