Queries regarding 'backport-android-bluetooth' - android

I have started working on android just 1 month back (so please consider my question even if it looks simple). I have my Bluetooth code running on Android 2.2. So I am working on using backport-android-bluetooth to migrate it to Android 1.6 (as I have some old pads with 1.6).
I came across foll. link: http://code.google.com/p/backport-android-bluetooth/
I have queries regarding point no. 1 and 2 under 'Install' which are as follows:
1. download backport-android-bluetooth2.jar, and put into your projects's reference libraries. - Where is exactly 'projects' reference library'? How to put .jar file in that 'reference library
2. put backport_android_bluetooth.properties in to your src directory. -Is this file to be put in 'src' folder or '*Project_Name*' folder like project.properties file?
Thanks in advance.

Put a new file into your src dir,named backport_android_bluetooth.properties
and then put the code below in it:
#permission_name = ${your package name).PERMISSION_BLUETOOTH
permission_name = com.example.bluetooth.PERMISSION_BLUETOOTH
#request_enable = ${your package name}.action.REQUEST_ENABLE
request_enable = com.example.bluetooth.action.REQUEST_ENABLE
#request_discoverable = ${your package name}.action.REQUEST_DISCOVERABLE
request_discoverable = com.example.bluetooth.action.REQUEST_DISCOVERABLE

if u r using eclipse than right click on ur project New/Folder,
give folder name as libs and copy & paste android-bluetooth2.jar in libs folder.
than right click on libs folder go to Build Path/ Configure Build Path
Click on Add Jar, select your project/libs/android-bluetooth2.jar
press ok

Related

Use Sample data directory from a library

I created Sample data directory for my Android app using the process described in this article. I would like to share this set of sample data between my projects, so I created a library that only has sample data inside. But as far as I can see sampledata folder is not being compiled into the library. Is there a way to share sample data between multiple Android projects?
As already said, you can't do that with a library because sampledata simply can't be part of an Android library.
One thing you could though, host your names file somewhere and then fetch it with a gradle task, you could just add to an app's build.gradle
clean.doFirst {
println "cleanSamples"
def samplesDir = new File(projectDir.absolutePath, "sampledata")
if (samplesDir.exists()) {
samplesDir.deleteDir()
}
}
task fetchSamples {
println "fetchSamples"
def samplesDir = new File(projectDir.absolutePath, "sampledata")
if (samplesDir.exists()) {
println "samples dir already exists"
return
}
samplesDir.mkdir()
def names = new File(samplesDir, "names")
new URL('http://path/to/names').withInputStream { i ->
names.withOutputStream {
it << i
}
}
}
You can see 2 functions there, the first one is run before a clean task and it will just delete your sampledata folder. The second one is a task run on every build, it won't download the file every time but only if the directory is not there.
I understand you might as well copy paste names file, but, with this method you need to copy paste the tasks only once and you would be able to change names in any project just by uploading a new file and doing a clean build.
The short answer is no, you can't do that with sampledata folder. Basically, the format of the Android Libraries is AAR. If you reference the official documentation, it says that:
The file itself is a zip file containing the following mandatory entries:
/AndroidManifest.xml
/classes.jar
/res/
/R.txt
/public.txt
Additionally, an AAR file may include one or more of the following optional entries:
/assets/
/libs/name.jar
/jni/abi_name/name.so (where abi_name is one of the Android supported ABIs)
/proguard.txt
/lint.jar
So, sampledata can't be a part of AAR library.
UPDATE
Instead of your own data samples, you can use predefined sample resources. For example #tools:sample/first_names will randomly select from some common first names, eg., Sophia, Jacob, Ivan.
Example of usage:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="#tools:sample/first_names" />

Is it possible to allocate these folders in another place?

I am installing Android Studio and I have by default the path C:\Users\Administrator\AppData\Local\Android\sdk to set my SDK. If I choose this option, some folders appeared on the path C:\Users\Administrator.
These folders are:
.android
.AndroidStudio1.3
.oracle_jre_usage
.gradle
To be a little more cleaner I tried to wrap all these folders into another folder but each time I run Android Studio it gives to me the option to configure again the settings. If I configure them again, the folders re-appeared on the path C:\Users\Administrator.
What can I do to wrap these folders into another one or to set another location for them and that the settings will be saved?
EDIT: I prove the solutions on the blog of the answer provided by Rahul Tiwari but I only could get that the folder .android will be in the new folder. The rest folders are at the same location after the changes.
EDIT 2: According to the blog provided by Rahul Tiwari to move the folder .gradle I change the default settings of Android Studio:
File > Other Settings... > Default Settings... > Build, Execution, Deployment > Gradle
Here I have as Service directory path: C:/Users/Administrator/AndroidStudio/.gradle
But the folder .gradle still appears on the path C:/Users/Administrator.
EDIT 3: Trying to remove the folder .AndroidStudio1.3 I changed these lines:
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to user installed plugins folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
# idea.plugins.path=${idea.config.path}/plugins
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to IDE logs folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
# idea.log.path=${idea.system.path}/log
to these:
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to user installed plugins folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
idea.plugins.path=${C:/Users/Administrator/AndroidStudio/.AndroidStudio1.3/config}/plugins
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to IDE logs folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
idea.log.path=${C:/Users/Administrator/AndroidStudio/.AndroidStudio1.3/system}/log
but I also couldn't move the folder.
EDIT 4: This is the blog that I mention before (Thank you very much Rahul Tiwari). I post it here because his answer was deleted.
Thanks in advance!
Finally, I got the solution to move three of the folders that I put above. I think it could be interesting to put here the problems that I faced and the changes that I made to solve them.
I'm going to investigate about the last folder, .oracle_jre_usage, and I will complete this answer if I got a solution for it. Look that I complete the solution for .gradle folder.
To move .android folder
Really, following the steps of the blog that Rahul Tiwari provided, this folder could been moved. Nevertheless I'm going to put here all the process:
You have to move your .android folder, after closing Android Studio (if you have it running), to the folder in which you want that it will be stored, in my case, C:\Users\Administrator\AndroidStudio.
BEWARE WITH THE SPACES IN THE NAME OF THE NEW FOLDER, IT COULD GIVE TO YOU PROBLEMS (AS ME). I mean, Android Studio, New Folder or similars.
If you are on Windows, you can do right-click on My Computer > Properties > Advanced System Settings > Environment Variables and create a new environment variable named ANDROID_SDK_HOME and as value you have to put the new path in which .android folder will be stored. It's the same path in which you have moved the .android folder in the step above.
Click "OK" button to accept your changes.
Re-launch Android Studio and look that the .android folder doesn't appear in the default path.
To move .AndroidStudio1.3 folder
With that folder I had some problems because I didn't noticed some details that were very important. Here the steps that I followed:
First of all, you have to close Android Studio before doing any change.
After, you have to move the folder .AndroidStudio1.3 to the path in which you want that it will be stored.
Next, you have to go to the folder in which Android Studio were installed and open "idea.properties" file and changed the lines where idea.config.path and idea.system.path appeared for the new path in which these folders are going to be located.
They have to be something similar to this:
idea.config.path=C:/Users/Administrator/AndroidStudio/.AndroidStudio1.3/config
idea.system.path=C:/Users/Administrator/AndroidStudio/.AndroidStudio1.3/system
Here I had three problems so please be careful:
Notice that the paths are with / and not with \ as Windows put by default.
DON'T CHANGE the values of idea.plugins.path and idea.log.path (My EDIT 3). Be sure that you are changing idea.config.path and idea.system.path values.
Uncomment the lines in which idea.config.path and idea.system.path appears. I mean, remove the # that they have at the begining of each line.
The last step, re-launch Android Studio.
Searching and doing some proves I also get the solution to move .gradle folder. The steps are the same as .android folder but I put here all the steps (with the values that changed) to avoid any confusion. Here it is:
To move .gradle folder
You have to move your .gradle folder, after closing Android Studio (if you have it running), to the folder in which you want that it will be stored, in my case, C:\Users\Administrator\AndroidStudio\.gradle.
BEWARE WITH THE SPACES IN THE NAME OF THE NEW FOLDER, IT COULD GIVE TO YOU PROBLEMS (AS ME). I mean, Android Studio, New Folder or similars.
If you are on Windows, you can do right-click on My Computer > Properties > Advanced System Settings > Environment Variables and create a new environment variable named GRADLE_USER_HOME and as value you have to put the new path in which .gradle folder will be stored. It's the same path in which you have moved the .gradle folder in the step above.
Click "OK" button to accept your changes.
Re-launch Android Studio and look that the .gradle folder doesn't appear in the default path.
How to move data from %UserProfile%
The folders will still remain under %UserProfile%, but not the data.
Move .android
Android Studio is closed
Add Environment Variable
Create "System variable":
Variable name: ANDROID_SDK_HOME
Variable value: D:\Android
Move .AndroidStudio
This is a example with Android Studio version 3.1
Start Android Studio
Help -> Edit Custom Properties...
Click Yes to create file
Edit file with:
idea.config.path=D:/Android/.AndroidStudio3.1/config
idea.system.path=D:/Android/.AndroidStudio3.1/system
The file "idea.properties" is located under:
%UserProfile%/.AndroidStudio3.1/config
Close Android Studio
Delete all under %UserProfile%/.AndroidStudio3.1 except the file "/config/idea.properties"
Optional: Delete older version folders of .AndroidStudio
Don't edit "Android Studio/bin/idea.properties". When updating Android Studio this file is cleared.
Move .gradle
Start Android Studio
File -> Settings... -> Gradle
Change "Service directory path" to:
D:/Android/.gradle
Update Android Studio
Start Android Studio
"Import Studio settings from" is showed
Select: D:/Android/.AndroidStudio3.0/config
I think most of the others answers address the issue, But I found more simple way for windows by adding few environment variables . (Might work for mac as well, I didn't test though)
ANDROID_SDK_ROOT - path to the SDK installation directory
default path - C:\Users\XXXX\AppData\Local\Android\Sdk
Add enviroment variable ANDROID_SDK_ROOT - set value to desired location
Eg: =E:\Android\local\Android\Sdk
For .android folder
default path - C:\Users\XXXX\.android
Add enviroment variable ANDROID_SDK_HOME- set value to desired location
Eg: = E:\Android
For .gradle folder
default path - C:\Users\XXXX\.gradle
Add enviroment variable GRADLE_USER_HOME - set value to desired location
Eg: = E:\Android\.gradle
For .androidstudioXXX
Android Studio-> Help-> Edit Custom Properties
Add below lines
idea.config.path=E:/Android/.AndroidStudio4.0/config
idea.system.path=E:/Android/.AndroidStudio4.0/system
Add environment variable STUDIO_PROPERTIES - set value to desired location
Eg: = E:\Android\idea.properties
Finally don't forget to copy files from the original location to the new location.
Source : https://developer.android.com/studio/command-line/variables
Please see the end of the page to know how to add the environment variable on Windows, Mac or Linux
At least for Android 3.0 the steps in the accepted solution are not enough to be able to run the emulators after moving the .android folder (let's say you moved the folder from c:\Users\<username>\.android to I:\Programs\AppData\.android).
In addition you need to
Copy (or leave) files adbkey and adbkey.pub in old location (i.e. c:\Users\<username>\.android\adbkey, c:\Users\<username>\.android\adbkey.pub)
Replace the old location path string C:\Users\<username>\ in all .INI files found in the new avd location (i.e. in I:\Programs\AppData\.android\avd) with the new location path string I:\Programme\AppData\
Delete all *.qcow2 files from the new avd location (i:\Programme\AppData\.android\avd) which contain the old location path string c:\Users\<username>\. Check Qcow2-files refer to incorrect/nonexistent base-images for an alternative to delete the *.qcow2 files. If you delete the files all data in the emulator is lost, in this case you will get a clean version of Android, like after a hard reset.
To change default .gradle folder using Android Studio 2.2
Open folder of .AndroidStudiox.x (x.x is the version you use) -> config -> options -> gradle.settings.xml file
just right click to open it with wordpad, you should only see 1 option name = serviceDirectoryPath, change the value of that to desired path
remember use / not backward slash \ for folder even in Windows OS
I use junction.exe from Sysinternals to make my Java/Android Studio fully "portable" in Windows:
I have "AndroidStudio" installed in a folder "work".
I have "Java\jdk1.8.0_77_x64" in the same "work".
In the same folder "work" I copied the original ".android", ".AndroidStudio2.2" and ".gradle" folders (from C:\Users\<YourProfile>).
Then in the same parent folder "work" I have copied "junction.exe".
Finally in the same "work" I have a batch __init__.bat with content listed below.
Closed Android Studio and deleted original ".android", ".AndroidStudio2.2" and ".gradle" folders (from C:\Users\<YourProfile>).
Run __init__.bat (as Administrator to set also the JAVA_PATH via setx) to create the new junctions then restart Android Studio. This solution works also after I reimage Windows, just have to remeber to run first the mentioned bat...
PS: When I update java or upgrade Android I have to remeber to tweak the bat with the new revision numbers
Content of __init__.bat:
#echo off
#SET mySrcPath=%cd%
#rem echo "%myPath%"
#rem JAVA_HOME = D:\work\Android\Java\jdk1.8.0_77_x64\
#SET myJavaTarget=Java\jdk1.8.0_77_x64\
#SET myJavaPath=%mySrcPath%\%myJavaTarget%
#if not exist "%myJavaPath%" (
#echo CANNOT FIND myJavaPath = "%myJavaPath%"
#goto _exit_
)
#rem echo myJavaPath = "%myJavaPath%"
#setx JAVA_HOME %myJavaPath%
#SET myTargetPath=%USERPROFILE%
#SET myCopy1=.android
#SET myCopy2=.AndroidStudio2.2
#SET myCopy3=.gradle
#SET mySource1="%mySrcPath%\%myCopy1%"
#SET mySource2="%mySrcPath%\%myCopy2%"
#SET mySource3="%mySrcPath%\%myCopy3%"
#SET myTarget1="%myTargetPath%\%myCopy1%"
#SET myTarget2="%myTargetPath%\%myCopy2%"
#SET myTarget3="%myTargetPath%\%myCopy3%"
#rem echo.
#if not exist %mySource1% (
#echo CANNOT FIND mySource1 = %mySource1%
#goto _exit_
)
#if not exist %mySource2% (
#echo CANNOT FIND mySource2 = %mySource2%
#goto _exit_
)
#if not exist %mySource3% (
#echo CANNOT FIND mySource3 = %mySource3%
#goto _exit_
)
#if not exist %myTarget1% (
#echo creating myTarget1 = %myTarget1% from mySource1 = %mySource1%
#junction.exe %myTarget1% %mySource1%
) else (
#echo myTarget1 = %myTarget1% ALREADY EXISTS !!!!!!
)
#if not exist %myTarget2% (
#echo creating myTarget2 = %myTarget2% from mySource2 = %mySource2%
#junction.exe %myTarget2% %mySource2%
) else (
#echo myTarget2 = %myTarget2% ALREADY EXISTS !!!!!!
)
#if not exist %myTarget3% (
#echo creating myTarget3 = %myTarget3% from mySource3 = %mySource3%
#junction.exe %myTarget3% %mySource3%
) else (
#echo myTarget3 = %myTarget3% ALREADY EXISTS !!!!!!
)
:_exit_
#echo exiting...
#pause

cocos2dx- 3.7 and 3.7.1 cocos studio don't work

Hello I'm working on cocos2dx-3.7.1 and I want to create an Scene on cocos studio, when I try to import the csb file only whit the template Helloworld.png works, but if I add a new Image and place it on the Scene(cocos studio) and publish, when I run the program I only see the helloworld.png.
Here is my code:
#include "GS_MissionSelect.h"
#include "Game.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
USING_NS_CC;
bool GS_MissionSelect::init()
{
//////////////////////////////
// 1. super init first
if (!Layer::init())
{
return false;
}
auto rootNode = CSLoader::createNode("CS_MainMenu/MainScene.csb");
this->addChild(rootNode);
return true;
}
I don't know what I need to do, I can't add more resources on Android studio and publish, only see Helloworld.png (default img of cocostudio).
I happen to meet same situation.
I deleted cocos 3.7.1 and have downgraded cocos 2dx to 3.4.
It solved publish problem.
I have had this problem before, and it happened because I only copied the .csb file published in the res folder, instead of copying all the files in the res folder as it is. You have to stick to the structure of your cocostudio project within your resource folder.
Just check the following please. Have you copied your entire publish folder into your resources folder? If not you should. Also could you edit your answer and put your directory structure for your published folder as well as your cocostudio content folder within the cocostudio editor and also the directory structure of your resource folder. It's just to rule out that your structure is correct and the problem lies in cocos.

openalpr on android - path to config and runtime_data

I want to use open alpr (automatic licences plate recognition) library in my android project. I compiled everything successfully and now it is time to use open alpr in app but...
to create Alpr class object properly I have to provide path to config file and path to runtime_data folder which contains some mandatory files needed by open alpr (ocr and trained data).
I tried something like:
Alpr alpr = new Alpr("eu", "android_assets/alpr.conf", "android_assets/runtime_data");
but Alpr.isLoaded() returns false which means that config or runtime_data have not been found.
Path to assets folder in project is: src/main/assets.
Can someone explain to me how path to "runtime_data" directory and "alpr.conf"
should looks to be visible by open alpr?
Thanks in advance.
I am not familiar with the specific library, but on newer Android devices (Android 6 and up), you can not rely on your application files residing under /data/data/your.package.name
The actual library name still includes the package name of your app, but also has some identifier appended to it in base64 format.
This identifier is unique per installation, and it will change if you uninstall and reinstall the app on the same device.
So, if your library needs to use a configuration file with a path to some other files, there are 2 options:
The right way:
Get the real address of your application files folder using Context.getFilesDir().
Unpack you files from the assets folder of the APK on the device using AssetManager.
Programmatically rewrite your configuration file with the path returned by getFilesDir().
The "hacky" but simpler way:
Use public storage to unpack your files.
You will need to add WRITE_EXTERNAL_STORAGE permission to your app, and unpack the assets files to the external storage.
For backwards compatibility this will be available under /sdcard folder on most Android devices, even with the latest Android version.
The second method is not recommended since using /sdcard directly is deprecated and strongly discouraged by Google.
Also, not all Android devices have /sdcard link to their public storage, but this is the only way to avoid dynamically editing the configuration file after installation.
Important note before you start implementing those steps. This library supports only arm CPU architecture. Good news is, most probably, your physical device is using arm architecture but to make sure just double-check it before implemting those steps.
I've recompiled this library to a new wrapper library. In original library, you need to manually configure openalpr.conf file and edit its content with correct path to your data directory. Manual configuration is cumbersome because since Android 5 multiple user accounts is supported and we can't simply hardcode data directory as /data/data/com.your.packagename/..... Because every user gets their symlink to data directory as /data/user/0/com.your.packagename/..... All those manual steps are gone in recompiled wrapper library.
Implementation
Add this in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency into app module:
dependencies {
...
implementation 'com.github.mecoFarid:openalpr:1.0.0'
}
And you're done. Please check this sample app to get started with UI.
Troubleshooting:
If your target sdk is targetSdkVersion >= 24 and you're running your app on a device with Android API 24+ you'll get following error:
android.os.FileUriExposedException: file:///storage/emulated/0/OpenALPR/2019-09-21-01-32-13.jpg exposed beyond app through ClipData.Item.getUri()
To solve this error: you can add following lines into onCreate() of your Activity as a workaround or you may use this thread for offical solution:
if(Build.VERSION.SDK_INT>=24){
try{
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
}catch(Exception e){
e.printStackTrace();
}
}
TEST:
You can use this image to test your app.
"/data/data/yourpackagename" + File.separatorChar + "runtime_data"
+ File.separatorChar + "openalpr.conf";

How to add add custom assets into .apk file?

I need to have some files in android assets folder, how can I add them using QtCreator/QMake?
Assuming you have the following structure in your source directory:
foo.pro
extra_data/file1
extra_data/file2
…
Adding the following to foo.pro should deploy the extra_data folder to assets://extra_data (exact path might differ, cannot verify right now) in the APK:
folder_01.source = extra_data
folder_01.target = extra_data
DEPLOYMENTFOLDERS += folder_01
If you are developing the application, then simply copy/paste the files in assets folder.
But if your application is already built and available as .apk file then you cannot modify any of its content.
Copying files to /5.2.0/android_armv7/src/android/java/assets did the trick

Categories

Resources