I'm sure you all know that if you run the below code under any android.
It will enable your Bluetooth. But first, it will show you an alert showing a dialog Yes/No.
Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnOn, 0);
My question is quite simple.
How to force Yes selection on that dialog?
My purpose is to programatically force enabling the bluetooth, and any other alert Yes/No.
So the user no need to see Yes/No. They will use Yes only. no dialog.
Please share a bit of guide. Thanks.
You can try to enable BluetoothAdapter (more info) like this:
BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
mAdapter.enable()
It requires the BLUETOOTH_ADMIN permission
Related
I am developing a video player app and I want my app to Prompt for the permission to be the default Video Player to be the default handler of video play.
I know it has to be something like the default handler:
Intent setSmsAppIntent =
new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
setSmsAppIntent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
getPackageName());
startActivityForResult(setSmsAppIntent, your-result-code);`
source: Android Docs
But I don't know the Action I have to give to the Intent as action. Can someone please help me?
Thanks in advance.
It's not possible, developers can't call intent to change default Video player only users can do that on their device. Its only possible for SMS service.
However, for video player you can register app for video player in AndroidManifest.xml and call the function which opens settings to change default apps using the following code:
Intent intent = new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
I have an app that does a check if data services is turned on and if it is not turned let display and alert dialog demanding the user to turn the app on clicking ok. This is my code that is supposed to show the settings of the android phone
final Intent intent=new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final ComponentName cn = new ComponentName("com.android.phone","com.android.phone.Settings");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
The above code does not display the option to turn on the wifi of the user
Please why the wifi data not turned on, on clicking the button
To enable the option to allow the user to turn on data services such wifi and others.
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
Just call the generic Settings screen (ACTION_SETTINGS)
Reference link http://developer.android.com/reference/android/provider/Settings.html
That will do the trick
How can we start the bluetooth adapter in background without the validation popup ?
normal way :
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
context.startActivityForResult(enableBtIntent, 1);
context.sendBroadcast(enableBtIntent);
If you want to enable bluetooth without using an Intent, you can try this:
BluetoothAdapter.getDefaultAdapter.enable();
you also need to add the BLUETOOTH and BLUETOOTH_ADMIN permission to your manifest file.
I can't find anything on this on google, nor here? But I am trying to create a notification and retrieve the value of an EditText field that has been set as a custom view for the notification
Is there anyway to retrieve this value? As notification's (as far as I'm aware) can just be set and/or updated.. but there must be some way!
That's not possible. The actual EditText view inside your notification is not even owned by your process - it's instantiated by the system using the RemoteViews object you are providing. The only way of communicating with it is by sending back predefined intents, for example via setOnClickPendingIntent. You cannot retrieve a content of EditText that way, though.
As a solution I'd recommend to display a dialog or activity with your EditText when user taps the notification, and handle their input there.
In your notification Intent
Intent notificationIntent = new Intent(this, FlightActivity.class);
Bundle bundle = new Bundle();
bundle.putString("whatever",YOUR_STRING_VALUE);
notificationIntent.putExtras(bundle);
When the application starts, you can get it using the intent
Is this what you want?
This not work:
try {
Context mmsContext = context.createPackageContext("com.android.mms", Context.CONTEXT_IGNORE_SECURITY);
mmsContext.grantUriPermission(context.getPackageName(),
Uri.parse("file:///data/data/com.android.mms/shared_prefs/com.android.mms_preferences.xml"),
Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mmsContext);
Editor editor = settings.edit();
editor.putBoolean("pref_key_enable_notifications", false);
editor.commit();
} catch (NameNotFoundException e1) {
e1.printStackTrace();
}
Error: "Attempt to read preferences file /data/data/com.android.mms/shared_prefs/com.android.mms_preferences.xml without permission"
Help, please!
You cannot disable SMS notifications programmatically. Please allow the user to decide whether or not SMS notifications should be enabled and allow them to control it through the appropriate settings screen.
By "you cannot", do you mean you should not, or there is no clean way of doing it/there's no API for that? Or do you really mean there is no way?
In most cases, I fully agree with you that the user should be able to control it through the appropriate settings screen. However, unfortunately, there are cases where there is no settings screen to toggle message notifications. An example I know of is the Samsung Behold II (which replaces the default messaging app, and removes the option to set/unset message notifications). I'm trying to develop a way around this, as there have been several requests by Behold II owners who've installed alternative MMS/SMS apps, and do not want the double notification.
I've tried to access the preference activity directly using the following code, but it forced closed
final Intent messagesettings = new Intent();
messagesettings.setClassName("com.android.mms", "com.android.mms.ui.MessagingPreferenceActivity");
...
public void onClick(View view){
startActivity(messagesettings);
}
Any ideas?