I'm attempting to send notifications to Sony LiveWare devices
I've installed: com.sonyericsson.extras.liveware.extension.notificationsample, but I get errors and exceptions while trying to run it:
Load the preference activity onto the device
Check "Active" on the preferences screen
The following method is called in SampleExtensionService:
private void addData() {
Random rand = new Random();
int index = rand.nextInt(5);
String name = NAMES[index];
String message = MESSAGE[index];
long time = System.currentTimeMillis();
long sourceId = NotificationUtil
.getSourceId(this, EXTENSION_SPECIFIC_ID);
if (sourceId == NotificationUtil.INVALID_ID) {
Log.e(LOG_TAG, "Failed to insert data");
return;
}
String profileImage = ExtensionUtils.getUriString(this,
R.drawable.widget_default_userpic_bg);
ContentValues eventValues = new ContentValues();
eventValues.put(Notification.EventColumns.EVENT_READ_STATUS, false);
eventValues.put(Notification.EventColumns.DISPLAY_NAME, name);
eventValues.put(Notification.EventColumns.MESSAGE, message);
eventValues.put(Notification.EventColumns.PERSONAL, 1);
eventValues.put(Notification.EventColumns.PROFILE_IMAGE_URI, profileImage);
eventValues.put(Notification.EventColumns.PUBLISHED_TIME, time);
eventValues.put(Notification.EventColumns.SOURCE_ID, sourceId);
try {
getContentResolver().insert(Notification.Event.URI, eventValues);
} catch (IllegalArgumentException e) {
Log.e(LOG_TAG, "Failed to insert event", e);
} catch (SecurityException e) {
Log.e(LOG_TAG, "Failed to insert event, is Live Ware Manager installed?", e);
} catch (SQLException e) {
Log.e(LOG_TAG, "Failed to insert event", e);
}
}
The first problem is that "long sourceId = NotificationUtil.getSourceId(this, EXTENSION_SPECIFIC_ID)" returns -1
I'm not sure how to change, but the docs say it is an optional field. So I removed it to see if I could get any further:
When removing the sourceId code I get an exception on the insert call:
"java.lang.SecurityException: You do not have sufficient permission to perform a insert"
My Environment:
HTC One V paired with a LiveView wrist pager
http://www.amazon.co.uk/Sony-Ericsson-0001516170-LIVE-VIEW/dp/B00477X6DA
I've got the followings apps installed
LiveView
SmartConnect(LiveWare Manager)
I'd appreciate any help getting this sample to work or if anyone knows of a more straight forward approach to doing simple text notifications for LiveWare.
EDIT:
Made some progress. Found an emulator here:
android-sdk\add-ons\addon-sony_add-on_sdk_1_0-sony-16\apk_files
I installed that on the phone. The "SampleExtensionService" works fine in the emulator.
My assumption now is that add-on sample is not compatible with the LiveView device.
The LiveView is unfortunately not supported by the SmartExtension APIs. Instead, there is a specific developer kit for the LiveView here.
If you would, in the future, buy a newer wearable device from Sony Mobile, a notification extension based on the Smart Extension APIs would be usable for several devices including SmartWatch, SmartWatch 2, SBH50, SBH52 etc.
Related
Is there a way to see Android logs that were logged before connecting to the Android Studio?
I have an app that tracks GPS location. The issue is that it terminates after some time and I get the Android system message that says "Application Terminated"
I want to see what went wrong and where. When I connect Android studio later, it shows logs that happened from time it is connected.
I want the logs from past.
There are couple of things you can try to resolve:
1) I generally write logs when I have such cases to test.
public static void writeToFile(String msg) {
Log.d("MyApp", msg);
try {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
FileOutputStream dio = null;
File file = new File(Environment.getExternalStorageDirectory(), "MyApp_File_Logs.txt");
if (file != null) {
try {
dio = new FileOutputStream(file, true);
dio.write((msg+"\n").getBytes());
dio.close();
dio = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}
} catch (Exception e) {
Log.e("MyApp", "Exception in writeToFile(): " + e.getMessage());
}
}
So instead of Log.d , Use this Utility method. You can add time in the message to be more precise.
Done forget to give write external storage permission to you app
2) Once you see crash , go to command prompt
and use the below commands:
adb shell
logcat -b crash
You might see something in this, if you connect within a minute or so
3) Increase the "Logger Buffer Size " in your developer options , but in this case you will see delay in getting logs when you connect your device to adb and open logcat.
you can add a log module into your app,let log module output your app's log into local file,like logger
I'm trying to connect my Android application to my company local network (Windows) using smb protocol. The problem is I'm kinda newbie on this matter and something is missing me.
The goal is download the file AREQA.txt from the network to the device. However I don't even can verify if the code can trace the file location because the application crashes when I compile it to the device (it loads fine but crashes when I call the DownLoadF001 procedure). Here's the code:
public void DownLoadF001(View v) {
jcifs.Config.registerSmbURLHandler();
String user;
String password;
String filename;
File localFile;
SmbFile path = null;
try {
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null,"######", "********");
path = new SmbFile("smb:\\192.168.1.11/.../AREQA.txt", auth);
try {
if(path.exists()){
Toast.makeText(getApplicationContext(), "Sucesso!", Toast.LENGTH_LONG).show();
}
} catch (Exception e1) {
Toast.makeText(getApplicationContext(), e1.toString(), Toast.LENGTH_LONG).show();
}
} catch (MalformedURLException e2) {
Toast.makeText(getApplicationContext(), e2.toString(), Toast.LENGTH_LONG).show();
}
}
I already tried to remove the inside try from the main one (with all its associated code), and the application stops crashing. However, without it, I can't see if the connection is working.
EDIT: I managed to catch the error (Exception e1):
java.lang.NullPointerException: Attempt to invoke virtual method int java.lang.String.length()' on a null object reference. Any ideas to solve it?
Also, as pointed by #greenapps, I'm calling this procedure from a .xml button by onClick method.
e.g If user clicks on check for update then action should be..
Check version of my application in market
If my application's current version and market version are not same then I just want to give a dialog of "Upgrade now".
Also wants to know is there any possibilities without WebServices for this aciton? because I have referred some answers with WebServices, instead of it is there any possibilities then please share your knowledge.
Thanks in advance :)
You can't get version of android market app, I wanna explain this... You can get current version of the app with this code:
public int getAppVersion(Context context) {
try {
PackageInfo packageInfo = context.getPackageManager()
.getPackageInfo(context.getPackageName(), 0);
return packageInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
// should never happen
throw new RuntimeException("Could not get package name: " + e);
}
}
If you want to know the version that have android market, that it's impossible, you need to think alternative, webservice how you say... In my case, for example, I save the version of Android Market in my server, when I sync my app with my server I obtain the AndroidMarket version then in this moment I can compare versions and apply the necessary code, in your case showDialog.
Not exist alternative that you can get version from you android app market, why? The apps have their code and not it's the same code for all apps...
Tell me if I helped you and good programming!
public String getLatestVersionNumber()
{
String versionNumber = "0.0.0";
try
{
Document doc = Jsoup.connect("<market:urlofparticularapp>").get();
Elements changeLog = doc.select("div.clDesc");
for (Element div : changeLog)
{
String divText = div.text();
if (divText.contains("Version"))
{
return divText.split(" ")[1];
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
return versionNumber;
}
Download Library of Jsoup from http://jsoup.org/download
As I know there is no way to get current version of market Application.
But i am doing this in my application by using of server.
I am putting the Upcoming app version on server and getting the current app version from app By using this code
oldVersion = Splash.this.getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
When app will launch then we will get the version from server and compare with app version for old user. If version will mismatch then give the popup for update for application using this code
Uri uri = Uri.parse("market://details?id=" + MainActivity.this.getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
MainActivity.this.startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
MainActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + MainActivity.this.getPackageName())));
}
I've sucessfully compiled jNetPcap as a shared library for Android. I have made a simple application using this code: http://jnetpcap.com/examples/classic to test the API.
The problem is that when I call the method findAllDevs and exception is raised with this message: "Can't read list of devices, error issocket: Permission denied"
I cannot understand the reason, since I have made a call in the first part of my program so as to get root permissions for my application and I test my application to a rooted phone. When I run the application, a pop up is raised with this message:"SnifferApp has been granted Superuser permissions" and then the exception occurs.
Any ideas?
Here is a piece of my code:
Process p = Runtime.getRuntime().exec("su");
/*try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // do nothing for 1000 miliseconds (1 second)
*/
try {
System.loadLibrary(JNETPCAP_LIBRARY_NAME);
}
catch (UnsatisfiedLinkError e) {
System.out.println("Native code library failed to load.\n" + e);
}
/***************************************************************************
* First get a list of devices on this system
**************************************************************************/
int r = Pcap.findAllDevs(alldevs, errbuf);
r = Pcap.findAllDevs(alldevs, errbuf);
if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
tv.append("Can't read list of devices, error is" + errbuf
.toString());
setContentView(tv);
return;
}
As far as I understand, you're creating a new process and getting superuser permission, but your app doesn't have them.
Try adding this permission in your manifest file:
<uses-permission android:name="android.permission.INTERNET" />
as I guess findAllDevs is going to open the network devices on the phone.
I've got it wrapped in a try catch, but the exception still trips that ugly screen.
URL u = null;
try {
u = new URL(txturl.getText().toString());
}
catch (MalformedURLException e) {
ReportError(e,"Unable to connect to "+u);
}
calls this:
private void ReportError(Exception e, String message){
Display(message+" - "+ e.getMessage().toString());
System.out.println(">>>>>>>>>>>>>>>>>>>>> "+message+" - "+e.getMessage().toString());printStackTrace();
}
Any way around this. It happens on the Android 2.2 emulator with Eclipse and on my Sprint Hero.
Do I have to validate the form?
Thanks.
I just needed to return after these exceptions. duh. sorry.