Has anyone else tried to mark their clipboard copied data as sensitive as per the following recommendation?
https://developer.android.com/about/versions/13/features/copy-paste
clipData.apply {
description.extras = PersistableBundle().apply {
putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true)
}
}
When I tried to do so, I don't find a clipData.apply method.
How can I set the sensitivity settings in an android app Java code?
apply() is a Kotlin scope function. You appear to be programming in Java, so the Kotlin syntax will not work for you.
By eyeball, the Java equivalent would be:
PersistableBundle extras = new PersistableBundle();
extras.putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true);
clipData.getDescription().setExtras(extras);
Related
I am trying to use the Activity Result APIs to handle the picking of a single photo for an app I am developing. I am trying to use one of the predefined contracts to keep things simple. So, I am attempting to use the ActivityResultContracts.PickVisualMedia() contract.
I am setting the Activity Result Launcher up as follows:
private ActivityResultLauncher<PickVisualMediaRequest> pickVisualMediaActivityResultLauncher;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
pickVisualMediaActivityResultLauncher = registerForActivityResult(
new ActivityResultContracts.PickVisualMedia(),
this::onPickVisualMediaActivityResult
);
}
And I am attempting to construct a PickVisualMediaRequest and launch the Activity Result Launcher here:
private void onSelectNewPhotoButtonClick() {
PickVisualMediaRequest request = new PickVisualMediaRequest.Builder()
.setMediaType(new ActivityResultContracts.PickVisualMedia.ImageOnly())
.build();
pickVisualMediaActivityResultLauncher.launch(request);
}
Issue is that Android Studio is complaining about ActivityResultContracts.PickVisualMedia.ImageOnly() not having proper visibility to be used, even though it is a valid VisualMediaType and the docs imply that it should be used this way:
I can't really find any code samples on this particular scenario. Am I missing something? Does the API have a visibility defect or am I just dumb today?
After some help from CommonsWare, I determined that setMediaType() accepts a Kotlin object instance. So, the above bad function I had should be:
private void onSelectNewPhotoButtonClick() {
ActivityResultContracts.PickVisualMedia.VisualMediaType mediaType = (ActivityResultContracts.PickVisualMedia.VisualMediaType) ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE;
PickVisualMediaRequest request = new PickVisualMediaRequest.Builder()
.setMediaType(mediaType)
.build();
pickVisualMediaActivityResultLauncher.launch(request);
}
Android Studio complains about the type casting, but the code does compile and work as expected. Very bizarre.
The guide mentions disabling User Interactions for Kotlin here.
mapView = findViewById(R.id.mapView)
mapboxMap = mapView.getMapboxMap()
mapboxMap.gestures(); //Method not found??
I don't know how to code in Kotlin. I can't work it around to work with Java. In Java, it says it cannot resolve symbol 'gestures'.
Same problem with other features.
You need to get a reference to the GesturesPlugin, try this:
final GesturesPlugin gesturesPlugin = GesturesUtils.getGestures((mapView));
gesturesPlugin.setPitchEnabled(false);
gesturesPlugin.setScrollEnabled(false);
}
Looking to handle a deep link from the Google Assistant. As I only have an emulator at the moment I am having trouble testing it (from what I have read it requires a real device). That said, I was wondering if I am handling it the correct way. I am unfamiliar with Kotlin and my code was turning into Spaghetti trying to integrate, so I put this together in my existing launcher activity just to try and get it bootstrapped for now. The manifest and actions.xml were set up like the fitness app tutorial.
Am I doing this correctly?
if (mAuth.getCurrentUser() != null) {
data = this.getIntent().getData();
if (data != null && data.isHierarchical()) {
uriData = data.toString();
containsStart = containsIgnoreCase(uriData,"start");
containsRun = containsIgnoreCase(uriData,"run");
if(containsStart && containsRun) {
Intent intent = new Intent(getApplication(), RunActivity.class);
intent.putExtra("runStart", true);
startActivity(intent);
}
}
else {
checkUserAccType();
}
//Else, if there is no current user, start the Authentication activity
}
A few observations and recommendation about your code:
Instead of using containsIgnoreCase uses getPath() and match the path. See example.
Also, for the activity parameter use URL query param instead of containsIgnoreCase. See example
Starting the activity or fragment. I assume startActivity and checkUserAccType will handle that part. See example.
// Else... section should go one line below.
Authentication. It looks fine. And it seems you're using Firebase by the getCurrent method signature. See example
I am working on Network based project in android, so, to prevent force close on Android ICS because of Can't do network operation on UI Thread , I must use the part of code such below or try to start my network operation on other thread, but I don't want to change the base code, so I should use the code as below on Android ICS. :
static {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
How can I make unique apk file to run in all android version ( >= 1.6 ) ? android.os.StrictMode is accessible for higher version of android, so, i can not try to use the above part of code in my Android Activity. So, which solution is better :
Using Reflections to run this part of code on higher versions of API (As oracle docs, reflective operations have slower performance than their non-reflective counterparts)
Change my android build target to Android 4.1.1 (API 16) and try to change the android:minSdkVersion on AndroidManifest.xml
Or if you know any better ones, please let me know.
Thanks in advance :)
You can use BUILD.VERSION and reflection to get over this compability problem (tested).
if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) >= 9) {
try {
// StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.LAX);
Class<?> strictModeClass = Class.forName("android.os.StrictMode", true, Thread.currentThread()
.getContextClassLoader());
Class<?> threadPolicyClass = Class.forName("android.os.StrictMode$ThreadPolicy", true, Thread.currentThread()
.getContextClassLoader());
Field laxField = threadPolicyClass.getField("LAX");
Method setThreadPolicyMethod = strictModeClass.getMethod("setThreadPolicy", threadPolicyClass);
setThreadPolicyMethod.invoke(strictModeClass, laxField.get(null));
} catch (Exception e) {
}
}
This question already has answers here:
Java equivalent to #region in C#
(24 answers)
Closed 6 years ago.
in .net you have Regions that you can collapse and remove lots of code down to one line.
is there something like this in Android / Java / Eclipse.
#Region "Initialize"
private void DisplayHome(){
Intent i = new Intent(this, SMSInternetActivity.class);
finish();
startActivity(i);
}
private void DisplaySettings(){
Intent i = new Intent(this, DisplaySettings.class);
finish();
startActivity(i);
}
This just being an example..
#End Region
Using Android Studio:
//region "Initialize"
private void DisplayHome(){
Intent i = new Intent(this, SMSInternetActivity.class);
finish();
startActivity(i);
}
private void DisplaySettings(){
Intent i = new Intent(this, DisplaySettings.class);
finish();
startActivity(i);
}
//endregion
There's a plug-in for that! It is called Coffee-Bytes. It is not in active development, but there are some programmers out there that are keeping the functionality going by updating it for new Eclipse releases.
There's two places where you can get the most latest install for Eclipse 3.7 (Indigo):
http://code.google.com/p/academic-cloud/downloads/detail?name=eclipse-folding-plugin.tar.gz&can=2&q=
http://kosiara87.blogspot.com/2011/12/how-to-install-coffee-bytes-plugin-in.html
Basically, you download the archive, then unpack it. Then you copy the feature from the features folder into your Eclipse installation in the Eclipse features folder. Do the same thing with the JAR found in the plugins folder, it goes into your Eclipse plugins folder. Then restart Eclipse.
There's a good SO answer that shows how to set it up:
How to use Coffee-Bytes code folding
Note that you may have to restart Eclipse for this new style of code folding to start working. Enjoy!
You can use Intellij's feature for code folding using //region and //endregion. Works great in Android Studio. However for Eclipse, you'll need a plugin to do that.
Source: Taken from Answer of Alexander Bezrodniy
I believe this is a feature of the IDE i.e. Visual Studio, not .NET in general. You, in theory, can write a plugin for Eclipse that can collapse region in Java code. Eclipse already have the ability to collapse imports and functions.
You need to perform the "surround with" operation (default key combination is CTRL+ALT+T), which allows you to use one of 2 ways to specify code as a region:
editor-fold:
//<editor-fold desc="Description">
code
//</editor-fold>
region & endregion :
//region Description
code
//endregion
As I remember, you must choose one of them to be used for the whole project. Maybe I'm wrong and it's only for a single file (and maybe there isn't a restriction at all).
yes, and the fastest way to do it in Android Studio
highlight the code you want to surround it
press ctrl + alt + t
press c ==> then enter the description
enjoy