How can I get logcat data with ddmlib? - java

I'm coding an utility to make a showcase movies on the PC of the apps running on the Android devices. I was able to do it using xuggler (http://www.xuggle.com/xuggler) and ddmlib. It is really easy to obtain image as RawImage from the Android's adb using ddmlib, but now i need to get Logcat data from the moments when I shot the movie. I can't find any examples to obtaint he Logcat data; the logcat package has some classes to handle Logcat messages, but none to instantiate it. Anybody, help! I'll be glad to see any example how to obtaing logcat messages using ddmlib.

I have fount that it is possible using
LogCatReceiverTask lcrt;
LogCatListener lcl;
lcrt=new LogCatReceiverTask(devices[0]);
lcl= new LogCatListener() {
#Override
public void log(List<LogCatMessage> msgList) {
System.out.println("Called with messages list length "+msgList.size());
for (LogCatMessage msg : msgList) {
// System.out.println(msg.toString());
/*
System.out.println(msg.getTime());
System.out.println(msg.getPid());
System.out.println(msg.getLogLevel());
System.out.println(msg.getAppName());
System.out.println(msg.getTag());
System.out.println(msg.getTid());
System.out.println(msg.getMessage());
*/
logcat = logcat + msg.toString() + "\n";
}
}
};
}

Thank llya Yevlampiev,This help me developing android logcat api on ddmlib.
Custom Logfilter

Related

Unity ads returns INVALID_ARGUMENT

I've integrated UnityAds on my Android app (that is not published yet).
I get app id and placement id from database on my server.
App id and placement id are correct, I've copied and pasted about 30 times for be sure of it.
So, when I try to get an ad in test mode, it give me the INVALID_ARGUMENT error.
Here an explaination of the error code by Unity, but as you can see it is a little generic.
I have an object that simply represents an ad service (like admob, FAN, inmobi etc)
In this case the object is called advert, and here it's how I show an ad with Unity:
protected void showUnity(){
UnityAds.initialize(this, advert.getApiKey(), true); //advert.getApiKey() returns the app id
UnityAds.addListener(new IUnityAdsListener() {
#Override
public void onUnityAdsReady(String s) {
Log.i(TAG, "onUnityAdsReady "+s);
if(s.equals(advert.getUnitId()) && !unityReady)
UnityAds.show(ActivityAd.this, advert.getUnitId()); //advert.getUnitId() returns the placement id
}
#Override
public void onUnityAdsStart(String s) {
Log.i(TAG, "onUnityAdsStart "+s);
unityReady = true;
}
#Override
public void onUnityAdsFinish(String s, UnityAds.FinishState finishState) {
if (finishState.compareTo(UnityAds.FinishState.COMPLETED) == 0) {
onAdReward(); //my callback for reward
} else if (finishState.compareTo(UnityAds.FinishState.SKIPPED) == 0) {
onAdClosed(); //my callback for ad close
} else if (finishState.compareTo(UnityAds.FinishState.ERROR) == 0) {
onAdError(finishState.toString()); //my callback for errors
}
}
#Override
public void onUnityAdsError(UnityAds.UnityAdsError unityAdsError, String s) {
onAdError(unityAdsError.toString()); //my callback for errors, here results INVALID_ARGUMENT error
}
});
}
Does anyone know what is wrong? Thanks in advance
If you check the callback closely the onUnityAdsError has 2 params, first provides the error code and the second param provides you information about what went wrong.
#Override
public void onUnityAdsError(UnityAds.UnityAdsError unityAdsError, String reason) {
onAdError(unityAdsError.toString()); //my callback for errors, here results INVALID_ARGUMENT error
}
So just check the reason and you should be able to find out what is going wrong in your integration.
Here are some methods which you can follow to solve this INVALID_ARGUMENT problem
1. Make sure you are implementing the right Initialization code in your app. There are 2 types of Initialization.
Only Unity ads Initialization
Mediation Initialization
and both methods have their own banner, interstitial, and rewarded ad code.
2. Make sure you enable test mode as Boolean. (i.e: private Boolean testMode = true;) (make sure to do false this before publish on store)
3. You can add your mobile phone as a test device to get test ads on your phone forcefully. for this, you have to first copy the Ad ID of your device. For that, go to your mobile settings > Google > Ads > This device's advertising ID. copy that ID and go to unity dashboard > Monetization > Testing > Add Test Device. Add your device Ads ID here with any name, and now you will be able to see test ads on the device.

setting badge when Firebase Cloud Message is received in Ionic App

I'm having a hard time getting responses to my questions lately and I'm not why. If I am not asking right, can someone please let me know so I can adjust?
I am building an app with Ionic but having issues sending badge numbers for Android via FCM. I can't find anything in the Firebase Docs. How do I set the badge count when a message is received?
Here is my thought process but I don't know how to get it to work:
when the message is received, use the ionic native badge plugin to set it
send the badge count using FCM payload
NOTE: I am using NodeJS implementation for Firebase
What I've tried
I am using the cordova-plugin-fcm plugin and the Android ShortcutBadger to set the badge, but I am unable to set the badge when the message is received. I was only able to set it when the app is already open by calling the shortcutbadger function in the MyFirebaseMessagingService java class (of the cordova-plugin-fcm). Below is the code I am using in my FCMPluginActivity java class:
// more imports here
import me.leolin.shortcutbadger.ShortcutBadger;
public class FCMPluginActivity extends Activity {
private static String TAG = "FCMPlugin";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "==> FCMPluginActivity onCreate");
Map<String, Object> data = new HashMap<String, Object>();
if (getIntent().getExtras() != null) {
Log.d(TAG, "==> USER TAPPED NOTFICATION");
data.put("wasTapped", true);
for (String key : getIntent().getExtras().keySet()) {
String value = getIntent().getExtras().getString(key);
Log.d(TAG, "\tKey: " + key + " Value: " + value);
data.put(key, value);
}
}
FCMPlugin.sendPushPayload(data);
ShortcutBadger.applyCount(FCMPluginActivity.this, 8);
finish();
forceMainActivityReload();
}
I am importing ShortcutBadger and using it in the onCreate method. The idea is to set the badger when the notification is received; however, this is not working.
Your thoughts and comments are very much appreciated
Set the badge field when you send the notification. The documentation specifies this for ios and based on my test it works, but with some delay. I would also try it for Android, but it may not be possible:
Search for 'badge' here:
https://firebase.google.com/docs/cloud-messaging/http-server-ref

OneSignal #Override not applicable to type

{Novice Android Developer}
I am following this tutorial regarding adding OneSignal Push notifications to my application. One thing that I am having difficulty with is the adding of the MainActivity.java code found at the end of the tutorial. I receive multiple errors.
I would be much obliged if someone would be able to assist me with this last portion of OneSignal integration. The main issue I am having is the placement of this code in regards to what is already in the MainActivity and what the tutorial mentions.
When I insert the code where the tutorial says, I receive an error which says
#Override not applicable to type
GitHub Repo of Project
// This fires when a notification is opened by tapping on it or one is received while the app is running.
private class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
    #Override
    public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
        try {
            if (additionalData != null) {
                if (additionalData.has("actionSelected"))
                    Log.d("OneSignalExample", "OneSignal notification button with id " + additionalData.getString("actionSelected") + " pressed");
                Log.d("OneSignalExample", "Full additionalData:\n" + additionalData.toString());
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
This is the code I am referring to.
*Note
I omitted other parts of the tutorial in the code for the reason that I am aware of that portion of the tutorial
That means either the name of the function or the parameters are not correct. Or that function doesn't exist in the library at all. According to OneSignal's docs, the correct signature is
public void notificationOpened(OSNotificationOpenResult result)
So either that tutorial is for a different version or the tutorial was never working.

How can I DetectFaces in Amazon Rekognition AWS with Android Studio?

I have tried so many way but i can't succeed. I haven't found any source code examples for Android(about rekognition)
there's a source code in JAVA in the Developer Guide but i cannot implement that even though I tried TT
I try to detect faces by sending an image file from an external storage(from the emulator)
I don't know what i did wrong(I'm not good at coding)
Here is my code
AmazonRekognitionClient amazonRekognitionClient;
Image getAmazonRekognitionImage;
DetectFacesRequest detectFaceRequest;
DetectFacesResult detectFaceResult;
File file = new File(Environment.getExternalStorageDirectory(),"sungyeol.jpg.jpg");
public void test_00(View view) {
ByteBuffer imageBytes;
try{
InputStream inputStream = new FileInputStream(file.getAbsolutePath().toString());
imageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream));
Log.e("InputStream: ",""+inputStream);
Log.e("imageBytes: ","");
getAmazonRekognitionImage.withBytes(imageBytes);
// Initialize the Amazon Cognito credentials provider
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(),
"us-east-2:.......", // Identity Pool ID
Regions.US_EAST_2 // Region
);
//I want "ALL" attributes
amazonRekognitionClient = new AmazonRekognitionClient(credentialsProvider);
detectFaceRequest = new DetectFacesRequest()
.withAttributes(Attribute.ALL.toString())
.withImage(getAmazonRekognitionImage);
detectFaceResult = amazonRekognitionClient.detectFaces(detectFaceRequest);
detectFaceResult.getFaceDetails();
}
catch(Exception ex){
Log.e("Error on something:","Message:"+ex.getMessage());
}
and here is my errors
02-04 09:30:07.268 29405-29405/? E/InputStream:: java.io.FileInputStream#a9b23e7
02-04 09:30:07.271 29405-29405/? E/Error on something:: Message:Attempt to invoke virtual method 'com.amazonaws.services.rekognition.model.Image com.amazonaws.services.rekognition.model.Image.withBytes(java.nio.ByteBuffer)' on a null object reference
what is a null object reference?
i try to change the file path but he said no such file ... and when I change to this path, there's errors above.
by the way I've already asked a user for a permission to access a folder from Emulator in Android
please help me
PS. sorry for my bad English
Thank you in advance.
Now I am ok with the issues. I have been through many many things <3 <3 <3.
Thank you
I'm Thai and I had to try harder to find the solutions because there's lack of information in the particular language. Here are my solutions.
My solutions are:
0.There is an endpoint for setting for the Rekognition-->
http://docs.aws.amazon.com/general/latest/gr/rande.html#rekognition_region
1.On a "null object reference issue" I found that I have to create a new object first such as "Image image = new Image();" <-- The "new" command creates an object instance in that class
2.After the above error, there are more errors (Errors on NetworkOnMainThreadException), so I tried everything until I found this page -->
https://docs.aws.amazon.com/cognito/latest/developerguide/getting-credentials.html the page said that ...
Consequently, I looked up for more information about the AsyncTask and after that I created an AsyncTask class and then I move all my code about the initialize, the request, the response to the AsyncTask class. ตอนรันตอนท้ายๆน้ำตาจิไหล my code worked... TT and by the conclusion the sungyeol.jpg.jpg file worked
for example
private void testTask(){
.... all code in the main thread particularly on the requests and responses
from the services
//print the response or the result
//Log.e() makes the message in the android monitor red like an error
Log.e("Response:", [responseparameter.toString()]);
}
//create the inherited class from the AsyncTask Class
//(you can create within your activity class)
class AsyncTaskRunner extends AsyncTask<String,String,String>{
#Override
public String doInBackground(String ... input){
testTask(); // call the testTask() method that i have created
return null; // this override method must return String
}
}
//I've created a button for running the task
public void buttonTask(View view){
AsyncTaskRunner runner = new AsyncTaskRunner();
runner.execute();
}
for more information about the AsyncTask:
https://developer.android.com/training/basics/network-ops/connecting.html#AsyncTask
http://www.compiletimeerror.com/2013/01/why-and-how-to-use-asynctask.html#.WJdkqVOLTIU
I hope these help :)

Logging and crash stack traces not showing in Android Studio

I'm trying to debug an app on my device and I'm having a bit of trouble with the debugger. I tried testing the logger to see if it would write to Logcat like so:
Log.d("MyActivity", "Testing logging...");
But nothing shows up in Logcat with the app: com.myapp.debug filter. It comes up when I simply filter by string (using my app name) but the entry looks like this:
01-08 13:45:07.468 29748-29748/? D/MyActivity﹕ Testing logging...
Does this question mark mean that something in the app is not getting passed through to the debugger? This might relate to my second issue with the debugger:
I've been debugging a crash and every time it happens, the phone simply shows the 'App is not responding' message then closes the current activity, disconnects the debugger, and the app keeps on running with the previous activity. No stack trace, no info about the crash, nothing. Is there something I need to set up in Android Studio to get this working?
I'm also having this trouble and I can't find too a good answer for this.
Instead I did a work around and catch the error with Thread.setDefaultUncaughtExceptionHandler() and Log it with Log.e()
I used this class to do it.
public class ExceptionHandler implements java.lang.Thread.UncaughtExceptionHandler {
private final String LINE_SEPARATOR = "\n";
public static final String LOG_TAG = ExceptionHandler.class.getSimpleName();
#SuppressWarnings("deprecation")
public void uncaughtException(Thread thread, Throwable exception) {
StringWriter stackTrace = new StringWriter();
exception.printStackTrace(new PrintWriter(stackTrace));
StringBuilder errorReport = new StringBuilder();
errorReport.append(stackTrace.toString());
Log.e(LOG_TAG, errorReport.toString());
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(10);
}
}
Then in my Activity .
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/**
* catch unexpected error
*/
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler());
setContentView(R.layout.activity_main);
//other codes
}
Hope this helps.
I think it is the same adb or filer problem.
At first remove all filters.
Restart adb - type in terminal adb kill-server && adb start-server.
Probably your google analytics "ga_reportUncaughtExceptions" is set to true, turning it to false fixes the issue and exceptions get printed to logcat.Please refer to below link for further details.
Why does android logcat not show the stack trace for a runtime exception?
You should define a class that implement UncaughtExceptionHandler and use stackTraceToString in Kotlin:
import android.util.Log
import java.lang.Thread.UncaughtExceptionHandler
class ExceptionHandler : UncaughtExceptionHandler {
override fun uncaughtException(t: Thread, e: Throwable) {
val stackTrace: String = e.stackTraceToString()
Log.d("TAG", stackTrace)
}
}
and register it in your application:
Thread.setDefaultUncaughtExceptionHandler(ExceptionHandler())

Categories

Resources