null title - Remix OS for PC

null

Settings=>Location=>High Accuracy

null

Related

[Q] Exception when receiving an Intent

Hello,
we are developing something to watch the battery drain - logging battery % steps - and get sometimes an exception into our Uncaught Exception Handler looks like this:
Code:
07-15 12:29:41.815 D/AndroidRuntime(27028): Shutting down VM
07-15 12:29:41.815 W/dalvikvm(27028): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
07-15 12:29:41.815 E/DrainGuardService(27028): Default uncaught exception handler
07-15 12:29:41.815 E/DrainGuardService(27028): Caught throwable java.lang.RuntimeException: [B]Error receiving broadcast Intent [/B]{ act=[B]android.intent.action.BATTERY_CHANGED[/B] flg=0x60000000 (has extras) } in [email protected] for thread Thread[main,5,main]
Thats our Codesnipplet
Code:
private IntentFilter batteryLevelFilterpercentchange = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
private BroadcastReceiver batteryLevelReceiver3;
Code:
batteryLevelReceiver3 = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
int level = -1;
try
{
int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale;
}
...
We tried to catch the exception with a try-finally but it looks like we are crashing before.
Funny thing: It happens only 1-2 times a week but we want to fix it. How/where can we catch this exception correctly without ending the app?
I also think that its not our mistake, because the system sends the message with the intent. but sometimes it seems not to be filled in correctly.
Thanks in advance!
Here's a pretty cookie cutter BroadcastReceiver that I use frequently(Modified with your code). Let me know if it helps.
Code:
private class BatteryLevelReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null)
return;
if (context == null)
return;
String action = intent.getAction();
if (action == null)
return;
if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
int level = -1;
int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale;
}
else {
// DO SOMETHING ELSE
}
}
}
Thanks, will try tomorrow and report back in a few days after testing.
After optimizing my code - had ~5 batterylevel receiver xD - and implementing your code, everything works like a charm.
Many thanks!
Thanks so much for the code! I was ahving the same issue, now it's solved!!!! Thanks again
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums & Read the Forum Rules
Moving to Q&A

[Q] Exception: Fragment already active

Hi!
I have a problem... again
In my layout I have a container which I want to replace with
a) a Google map view
b) a text view
This must be configurable by a settings fragment. Everything works fine. But every time I switch from text to map or visa verse my app crashes with an exception.
java.lang.IllegalStateException: Fragment already active
I don't know what I am doing wrong. After switching from map to text within my settings I call this getMainActivity().setView() method:
Code:
protected void setView(boolean setMap) {
if (setMap == true) {
Log.i(TAG, "Inflating Google Maps fragment");
// Get a new Fragment Manager
fm = getFragmentManager();
FragmentTransaction fta = fm.beginTransaction();
// New instance if none exists
if (this.fragmentMap == null)
{
Log.d(TAG, "map fragment is null");
this.fragmentMap = new FragmentMap();
}
// Ok... if the fragment is not already added we will do it here right now
if (!this.fragmentMap.isAdded())
{
Log.d(TAG, "map fragment not added yet");
// Create a new bundle for the fragment
Bundle args = new Bundle();
this.fragmentMap.setArguments(args);
fta.replace(R.id.container, this.fragmentMap).commit();
} else
{
fta.show(this.fragmentMap).commit();
}
this.useMap = true;
} else if (setMap == false) {
Log.i(TAG, "Inflating text fragment");
// Get a new Fragment Manager
fm = getFragmentManager();
FragmentTransaction fta = fm.beginTransaction();
// New instance if none exists
if (this.fragmentText == null)
{
Log.d(TAG, "textfragment is null");
this.fragmentText = new FragmentText();
}
// Ok... if the fragment is not already added we will do it here right now
if (this.fragmentText != null)
{
// Create a new bundle for the fragment
Bundle args = new Bundle();
Log.d(TAG, "textfragment not yet added");
this.fragmentText.setArguments(args);
fta.replace(R.id.container, this.fragmentText).commit();
} else
{
fta.show(this.fragmentText).commit();
}
this.useMap = false;
}
}
The last messages I get before the exception is thrown are the "....fragment not yet added" messages.
How can I switch between a map fragment and a text fragment?
Thorsten

[Q] Why width and height of the CodecContext gives me always zero. ffmpeg

Not sure what was my mistake in the below code. I m trying with ffmpeg 0.11 and SDL2.0 in android.
QUESTION: Why Width and Height of the CodecContext gives me always zero ?..
int main(int argc, char *argv[])
{
int flags;
flags = SDL_INIT_VIDEO | SDL_INIT_TIMER;
if (SDL_Init (flags)) {
LOGD ("Could not intialize Video for SDL: %s \n", SDL_GetError());
}
else
LOGD (" SUCCESS: SDL_Init ");
// ffmpeg Register all services..
ffmpeg_register_all ();
pFrame = avcodec_alloc_frame ();
context = avformat_alloc_context();
err = avformat_open_input (&context, "rtsp:iport", NULL, NULL);
if ( err < 0) {
__android_log_print(ANDROID_LOG_DEBUG, "ffmpegguard", "Unable to open rtsp... ");
return -1;
}
for (i = 0; i < context->nb_streams; i++)
{
// Find the Decoder.
codec = avcodec_find_decoder(context->streams->codec->codec_id);
if (codec->type == AVMEDIA_TYPE_VIDEO ) {
__android_log_print(ANDROID_LOG_DEBUG, "ffmpegguard", "Found Video Streaming.. ");
videoStreamIndex = i;
}
}
// Play RTSP
av_read_play(context);
// Get Codec Context.
pCodecCtx = context->streams[videoStreamIndex]->codec;
if ( pCodecCtx == NULL )
__android_log_print(ANDROID_LOG_DEBUG, "ffmpegguard", "CodecCtx is NULL>>> ");
else
__android_log_print(ANDROID_LOG_DEBUG, "ffmpegguard", "CodecCtx is <<<OK>>> ");
//Find the Decoder.
pCodec = avcodec_find_decoder (pCodecCtx->codec_id);
avcodec_open2 (pCodecCtx, pCodec, NULL);
int w = pCodecCtx->width; // Why me getting 0 ?
int h = pCodecCtx->height;
window = SDL_CreateWindow ("Test ffmpeg",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_SHOWN|SDL_WINDOW_ALLOW_HIGHDPI);
// What this HIGHDPI Means ??
if ( window != NULL )
{
LOGD (" WINDOW CREATED.. , create Renderer ..");
renderer = SDL_CreateRenderer (window, -1, 0);
}
else
{
LOGD (" Invalid SDL Window ");
}
__android_log_print(ANDROID_LOG_DEBUG, "ffmpegguard", "Width and Height of PCodeccCtx.. %d .. %d " , w, h);
return 0;
}

[Q] Issues reading contact's phone numbers

This would better be located in Galaxy S III Android Development forum, but apparently I can't post there yet as I have fewer than 10 posts. Moderators, please move this to that forum.
I am a new developer to Android. I wrote a simple program that tries to figure out which contacts are most called to. The program works just fine on the emulator, but fails to work on my Samsung S3. Specifically, I can not read the list of phone numbers of a particular contact. What I see is that ContactsContract.Contact._ID does not correspond to the ContactsContract.Data.RAW_CONTACT_ID. For example, I have a contact in my phone called "Mailbox abhören" ("voice mail"), which has a phone number +491793000333. In the ContactsContract.Contact I see two relevant entries (dumped using this code: http://tny.cz/95e6124e):
Code:
_ID = 1087
LOOKUP_KEY = 4063i27e12adb8d7365fe
DISPLAY_NAME = Mailbox abhören
DISPLAY_NAME_PRIMARY = Mailbox abhören
PHOTO_ID = null
PHOTO_URI = null
PHOTO_THUMBNAIL_URI = null
IN_VISIBLE_GROUP = 1
HAS_PHONE_NUMBER = 1
TIMES_CONTACTED = 0
LAST_TIME_CONTACTED = 0
STARRED = 0
CUSTOM_RINGTONE = null
SEND_TO_VOICEMAIL = 0
CONTACT_PRESENCE = null
CONTACT_STATUS = null
CONTACT_STATUS_TIMESTAMP = null
CONTACT_STATUS_RES_PACKAGE = null
CONTACT_STATUS_LABEL = null
CONTACT_STATUS_ICON = null
_ID = 3098
LOOKUP_KEY = 298i1
DISPLAY_NAME = Mailbox abhören
DISPLAY_NAME_PRIMARY = Mailbox abhören
PHOTO_ID = null
PHOTO_URI = null
PHOTO_THUMBNAIL_URI = null
IN_VISIBLE_GROUP = 1
HAS_PHONE_NUMBER = 1
TIMES_CONTACTED = 0
LAST_TIME_CONTACTED = 0
STARRED = 0
CUSTOM_RINGTONE = null
SEND_TO_VOICEMAIL = 0
CONTACT_PRESENCE = null
CONTACT_STATUS = null
CONTACT_STATUS_TIMESTAMP = null
CONTACT_STATUS_RES_PACKAGE = null
CONTACT_STATUS_LABEL = null
CONTACT_STATUS_ICON = null
However, in the ContactsContract.Data, the entries for these two contacts are completely irrelevant and point to some other contact (real names and addresses obfuscated, dumped using http://tny.cz/afef6836):
Code:
id = 6985
mimeType = vnd.android.cursor.item/photo
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 0
data1 = null
data2 = null
data3 = null
data4 = null
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = https://www.google.com/m8/feeds/photos/media/[email protected]/zzz
sync2 = null
sync3 = null
sync4 = 0
id = 6986
mimeType = vnd.android.cursor.item/name
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 = Someone Private
data2 = Someone
data3 = Private
data4 = null
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = 1
data11 = 0
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11
id = 6987
mimeType = vnd.android.cursor.item/note
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 =
data2 = null
data3 = null
data4 = null
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11
id = 6988
mimeType = vnd.android.cursor.item/nickname
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 = null
data2 = null
data3 = null
data4 = null
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11
id = 6989
mimeType = vnd.com.google.cursor.item/contact_misc
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 = null
data2 = null
data3 = null
data4 = null
data5 = null
data6 = null
data7 = null
data8 = 4
data9 = 5
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11
id = 6990
mimeType = vnd.android.cursor.item/group_membership
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 = 5
data2 = null
data3 = null
data4 = null
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11
id = 6991
mimeType = vnd.android.cursor.item/phone_v2
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 = +380975356308
data2 = 2
data3 = null
data4 = +380975356308
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11
id = 2340183
mimeType = vnd.android.cursor.item/name_svoice_dmetaphone_primary_encoding
rawContactId = 1087
isPrimary = 0
isSuperPrimary = 0
dataVersion = 0
data1 = SOMEONE PRIVATE
data2 = SOMEONE
data3 = PRIVATE
data4 = null
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = null
I've also tried dumping the whole ContactsContract.Data database and found entries with the expected number:
Code:
id = 118113
mimeType = vnd.android.cursor.item/phone_v2
rawContactId = 3047
isPrimary = 1
isSuperPrimary = 0
dataVersion = 1
data1 = +491793000333
data2 = 2
data3 = null
data4 = +491793000333
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = null
id = 6969
mimeType = vnd.android.cursor.item/phone_v2
rawContactId = 1084
isPrimary = 0
isSuperPrimary = 0
dataVersion = 1
data1 = +491793000333
data2 = 2
data3 = null
data4 = +491793000333
data5 = null
data6 = null
data7 = null
data8 = null
data9 = null
data10 = null
data11 = null
data12 = null
data13 = null
data14 = null
data15 = null
sync1 = null
sync2 = null
sync3 = null
sync4 = 11
3047 does not exist. 1084 points closes the loop and points to the Someone Private:
Code:
_ID = 1084
LOOKUP_KEY = 4063i2a66cd210fc7ef2a
DISPLAY_NAME = Someone Private
DISPLAY_NAME_PRIMARY = Someone Private
PHOTO_ID = null
PHOTO_URI = null
PHOTO_THUMBNAIL_URI = null
IN_VISIBLE_GROUP = 1
HAS_PHONE_NUMBER = 1
TIMES_CONTACTED = 0
LAST_TIME_CONTACTED = 0
STARRED = 0
CUSTOM_RINGTONE = null
SEND_TO_VOICEMAIL = 0
CONTACT_PRESENCE = null
CONTACT_STATUS = null
CONTACT_STATUS_TIMESTAMP = null
CONTACT_STATUS_RES_PACKAGE = null
CONTACT_STATUS_LABEL = null
CONTACT_STATUS_ICON = null
I am confused. Is this some non-standard database used only by Samsung? My phone seems to work just fine with my voicemail and never calls Someone Private when I dial it. And when I dial Someone Private's number it is never identified as "Mailbox abhören".

Android sensor batching

I have implemented batching of accelerometer sensor and store the x,y,z values in file.I need to store all the accelerometer values.
The following is the code to store the values in file.Unfortunately,some of the values are missing when the device screen is off. I do not want to use wakelock since its drains the battery.
private final SensorEventListener mListener = new SensorEventListener() {
@override
public void onSensorChanged(SensorEvent event) {
// BEGIN_INCLUDE(sensorevent)
// store the delay of this event
recordDelay(event);
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
final String delayString = getDelayStringAccelero();
String rmsValues="";
String[] buffer=delayString.split(",");
for(int i=0;i<buffer.length;i++){
String[] buffer1=delayString.split(":");
Double x=Double.parseDouble(buffer1[0]);
Double y=Double.parseDouble(buffer1[1]);
Double z=Double.parseDouble(buffer1[2]);
float rms=(float) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2));
//Store in file
Logger.e(MainActivity.context,TAG,i+")RMS="+rms+" Timestamp="+buffer1[3]);
}
// Get accelerometer values.
mSteps = (int) event.values[0];
// Update the card with the latest values
getCardStream().getCard(CARD_COUNTING)
.setTitle(getString(R.string.counting_title, mSteps))
.setDescription(getString(R.string.counting_description,
getString(R.string.sensor_accelerometer), mMaxDelay, rmsValues));
}
}
@override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};

Categories

Resources