I'm trying to use my wearOS app to extend my Paint app. I tried sending a Bitmap to the wear app everytime a new point was added, but that caused horrible lag.
I tried serializing a Path array, but then quickly noticed I could just pass the three different paint features, (start, move, end) via points and functions.
This is my onMove attempt:
public void sendPoint(Point p)
{
long[] newPoint = new long[2];
newPoint[0] = p.x;
newPoint[1] = p.y;
PutDataMapRequest dataMap = PutDataMapRequest.create("/count");
dataMap.getDataMap().putLongArray("count", newPoint);
PutDataRequest request = dataMap.asPutDataRequest();
Task<DataItem> putTask = Wearable.getDataClient(this).putDataItem(request);
}
Before I get into onStart and onEnd - I'd like to point out with this exact code:
public void sendPaint(Bitmap b)
{
Bitmap bitmap = b;
Asset asset = createAssetFromBitmap(bitmap);
PutDataMapRequest dataMap = PutDataMapRequest.create("/image");
dataMap.getDataMap().putAsset("profileImageX", asset);
PutDataRequest request = dataMap.asPutDataRequest();
Task<DataItem> putTask = Wearable.getDataClient(this).putDataItem(request);
}
I was able to send my bitmap.
The reason I say this is weird is becasue all I did was change .putAsset
dataMap.getDataMap().putAsset("profileImageX", asset);
to .putLongArray
dataMap.getDataMap().putLongArray("count", newPoint);
Any ideas as to why this isn't working? I noticed sendData only works if the data is new, perhaps this is the issue. In that case, I'd like to know how to erase the "data" send after it is received and used in the WearOS app.
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
is needed in order to work also within your gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "your.applicationid" // needs to be the same in both modules
minSdkVersion 20
targetSdkVersion 23
versionCode 1
versionName "1.0"
targetCompatibility = '1.7'
}
...
Also as you say I think you need to put something that's really new all the time like System MillTimes
dataMap.getDataMap().putLong("Time",System.currentTimeMillis())
Related
Is webcam detection still supported?
The MediaDiscovererTest.java file does not seem to detect any capture devices. (win/mac)
It seems to me that the device detection was working with earlier versions of vlcj on MAC webcam-capture driver for vlcj
...
MediaPlayerFactory mediaPlayerFactory = createMediaPlayerFactory();
MediaDiscoverer videoMediaDiscoverer = mediaPlayerFactory.newVideoMediaDiscoverer();
MediaList videoDeviceList = videoMediaDiscoverer.getMediaList();
List<MediaListItem> videoDevices = videoDeviceList.items();
...
VLC is able to detect the capture devices.
Thanks in advance for your help.
#edit1
Using the following code in vlcj-4.7.3 does not seem to return the webcam. But maybe I missed something.
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
List<MediaDiscovererDescription> videoDevices = mediaPlayerFactory.mediaDiscoverers().discoverers(MediaDiscovererCategory.DEVICES);
#edit 2
When i run this following code;
List<MediaDiscovererDescription> discoverers = factory.mediaDiscoverers().discoverers(MediaDiscovererCategory.DEVICES);
Under Windows 10 I get the following list: (no Video Capture)
[MediaDiscovererDescription[name=disc,longName=Discs,category=DEVICES],
MediaDiscovererDescription[name=disc,longName=Discs,category=DEVICES]
On MacOs 12.4 I get an empty list...
#edit 3
Capture device detection only works under linux
With vlcj-4.7.x, the API to discover video capture devices looks like this:
List<MediaDiscovererDescription> discoverers = factory.mediaDiscoverers().discoverers(MediaDiscovererCategory.DEVICES);
When I run that code, I see something like this:
[DEVICES ] v4l "Video capture"
[DEVICES ] disc "Discs"
[DEVICES ] xcb_apps "Screen capture"
[DEVICES ] mtp "MTP devices"
[DEVICES ] pulse "Audio capture"
In this case, on Linux, the discoverer ID is "v4l".
So now you find the "v4l" discoverer in the list of discoverer descriptions. Once you have that discoverer instance you can invoke methods on it to get the actual capture devices.
If you know the discoverer ID in advance, which in all (?) cases you will, you can do this instead:
MediaDiscoverer discoverer = factory.mediaDiscoverers().discoverer("v4l");
You then get the media list from that discoverer and add listeners to that media list.
Finally you must start() the discoverer.
The listener will be triggered when a capture device is added/removed (or 'detected').
MediaList list = discoverer.newMediaList();
list.events().addMediaListEventListener(new MediaListEventAdapter() {
#Override
public void mediaListItemAdded(MediaList mediaList, MediaRef item, int index) {
System.out.println(name + ": added " + item);
}
#Override
public void mediaListItemDeleted(MediaList mediaList, MediaRef item, int index) {
System.out.println(name + ": deleted " + item);
}
});
discoverer.start();
The vlcj MediaDiscovererTest class shows all of this.
The MediaRef instance is the MRL of the capture device, which you can then use to build a menu to select to play one of them or whatever.
I am attempting to add a function to that will check a json file on my server for the versionCode of an app outside of my own and if the versionCode in json on the server is greater than the one of the app outside of my own, then do an update action.
The update action works fine, however, I am experiencing issues getting the versionCode of the outside app. The versionCode always returns as 0 instead of the actual version of the outside app.
Why doesn't it return the proper version?
Here is my code for fetching the versionCode of the other app:
public static int getinstVersionCode(Context mContext) {
if (mContext != null) {
try {
return mContext.getPackageManager().getPackageInfo(Constants.PACKAGE_NAME, 0).versionCode;
} catch (PackageManager.NameNotFoundException ignored) {
}
}
return 0;
}
The PACKAGE_NAME equals the com.example.app app package name that is held in the json file on my server:
static final String APK_VERSION_CODE = "versionCode";
static final String PACKAGE_NAME = "package";
And finally, the json file itself:
"versionCode":0,
"package":"com.example.app",
Check the exception, the application which version you are trying to get must be present on the device and exactly match the package name.
I'm building a ProgressBar dynamically at Runtime, and the Progressar is not filled on API 19 only, it works on higher APIs, the green bar that represent the percentage does not appear.
Why it doesn't work on API 19 ?
private ProgressBar drawProgressBar(MatiereProgression mat) {
ProgressBar progress = new ProgressBar(mContext, null, R.style.Widget_AppCompat_ProgressBar_Horizontal);
LinearLayout.LayoutParams progressLayout = new LinearLayout.LayoutParams(0, dpToPx(4));
progressLayout.weight = 11;
progressLayout.gravity = Gravity.CENTER_VERTICAL;
progress.setLayoutParams(progressLayout);
progress.setIndeterminate(false);
progress.setMax(100);
progress.setMinimumHeight(0);
progress.setMinimumWidth(150);
progress.setProgress(mat.mProgress);
progress.setProgressDrawable(ContextCompat.getDrawable(mContext, R.drawable.progressbar));
return progress;
}
I found the bug, it was the last lines, on API 19 you need to care about the line order between "setProgressDrawable" and "setProgress", it worked for me.
progress.setLayoutParams(progressLayout);
progress.setIndeterminate(false);
progress.setMax(100);
progress.setProgressDrawable(ContextCompat.getDrawable(mContext, R.drawable.progressbar));
progress.setMinimumHeight(0);
progress.setMinimumWidth(150);
progress.setProgress(mat.mProgress);
I am new to android but already thinking if there is a way to include some important configurations for the app in continuous integration . We use visual studio online for build and release .
Example .
Currently we have Constants.java file which stores some imp configuration values like server URL which wil be different for each environment app is deployed on for example dev,test uat production , so currently that code needs to be manually checked before it goes in to vso for build and release . . Is it possible to somehow configure it in continuous integration of environment and pick from there so that manual check is not required ..
See this:
Look this function readApiKey() it reads the keys in from Environment or from a .properties file. Then look at this line:
buildConfigField("String", "API_PUBLIC_KEY", readApiKey(KeyType.PUBLIC_KEY)) it loads the string resource with the value.
If you have different builds with different values, that's where flavours comes in. You can read it up here.
apply plugin: 'com.android.application'
apply from: '../codequality/quality.gradle'
/*
* Read API key from CI server or from keys.properties file
*/
enum KeyType {
PUBLIC_KEY,
PRIVATE_KEY
}
def readApiKey(KeyType type) {
String apiKey = ""
if (System.getenv("CIENV")) {
if (type == KeyType.PUBLIC_KEY) {
apiKey = System.getenv("PB_KEY")
} else apiKey = System.getenv("PR_KEY")
} else {
Properties props = new Properties()
try {
props.load(new FileInputStream(new File(getRootDir().getAbsolutePath() + "/keys.properties")))
if (type == KeyType.PUBLIC_KEY) {
apiKey = props.getProperty("api_pb_key")
} else apiKey = props.getProperty("api_pr_key")
} catch (FileNotFoundException fnfe) {
println("Please create a keys.properties file in the root directory of the project")
}
}
return "\"$apiKey\"";
}
println 'PUBLIC KEY Log' + readApiKey(KeyType.PUBLIC_KEY)
println 'Private Key Log' + readApiKey(KeyType.PRIVATE_KEY)
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
dataBinding {
enabled true
}
testOptions {
unitTests.returnDefaultValues = true
}
defaultConfig {
applicationId "co.tonespy.dummarvel"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Setting up picked up data to String resource
buildConfigField("String", "API_PUBLIC_KEY", readApiKey(KeyType.PUBLIC_KEY))
buildConfigField("String", "API_PRIVATE_KEY", readApiKey(KeyType.PRIVATE_KEY))
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// support dependencies
....
// test dependencies
testCompile "junit:junit:$jUnitVersion"
androidTestCompile("com.android.support.test.espresso:espresso-core:$espressoCoreVersion", {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile "org.mockito:mockito-core:$mockitoVersion"
compile "com.android.support:support-v4:$supportLibraryVersion"
}
You can just use Replace Tokens step/task to replace the value per to each environment.
Install Replace Tokens extension
Add Replace Tokens task to each environment of your release definition (Target files **\ Constants.java)
Add environment variable (e.g server, same variable name for each environment) for each environment of you release definition
Modify Constants.java file, replace necessary value to #{server}# and check in changes (The developers can modify this file with specific value and do not check in changes if they need to debug/run app in local machine)
After that the #{server}# will be replaced with the value of server environment
I am trying to get local/scheduled notifications working. With push messages (using Parse) working fine I though local would be easy, but even though the registration seems to go fine (didRegisterUserNotificationSettings is fired) and the scheduling seems to work too, the notification does not show up. I have tested on iOS 7 (iphone 4) and iOS 9 (iphone simulator). What am I missing?
here is my code:
#Override
public boolean didFinishLaunching(UIApplication application,UIApplicationLaunchOptions launchOptions)
{
boolean retval = super.didFinishLaunching(application, launchOptions);
//some other stuff happens here regarding parse push. But since this works I have cut it out
registerForPush();
return retval;
}
public void registerForPush()
{
if (IOSLauncher.getOSMajorVersion() >= 8)
{
UIUserNotificationType userNotificationTypes = UIUserNotificationType.with(UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound);
UIUserNotificationSettings settings = new UIUserNotificationSettings(userNotificationTypes, null);
application.registerUserNotificationSettings(settings);
application.registerForRemoteNotifications();
}
else
{
UIRemoteNotificationType type = UIRemoteNotificationType.with(UIRemoteNotificationType.Alert, UIRemoteNotificationType.Badge, UIRemoteNotificationType.Sound);
application.registerForRemoteNotificationTypes(type);
}
}
public void scheduleNotification(String title, String text, Date date, int ID)
{
UILocalNotification notification = new UILocalNotification();
if(getOSMajorVersion() >= 8 && getOSMinorVersion() >= 2)
notification.setAlertTitle(title);
notification.setAlertBody(text);
notification.setFireDate(new NSDate(date));
NSMutableDictionary<NSObject, NSObject> dict = new NSMutableDictionary<>();
dict.put("id",NSNumber.valueOf(ID));
notification.setUserInfo(dict);
UIApplication.getSharedApplication().scheduleLocalNotification(notification);
}
Edit:
After settting the notification it is present in the array returned by:
UIApplication.getSharedApplication.getScheduledLocalNotifications();
The problem was resolved after Adding:
notification.setTimeZone(NSTimeZone.getLocalTimeZone());
and setting the expire time of my test timer from 1 minute to 5 minutes
I'm not sure which is the actual solution, but the problem is gone, so I'm happy!
EDIT:
UILocalNotification notification = new UILocalNotification();
notification.setAlertTitle("title");
notification.setAlertBody("text");
NSMutableDictionary<NSObject, NSObject> dict = new NSMutableDictionary<>();
//add any customer stuff to your dictionary here
notification.setUserInfo(dict);
notification.setFireDate(new NSDate(date)); //date is some date in the future. Make sure it is in the correct TZ. If it does not work, try to make it at least 5 minutes in the future. I remember this helping my situation
notification.setTimeZone(NSTimeZone.getLocalTimeZone());
UIApplication.getSharedApplication().scheduleLocalNotification(notification);