I would like to know how much is the sending of an SMS via SMSManager? let me explain:
I have a list of several people and I make a FOREACH loop on their phone number.
The list contains more than 200 numbers
Thanks
after going through the Android sources for all the APIs supported by my app I cam up with the following code
`private void setSmsDefaultLimitations(){
int apiLevel = Build.VERSION.SDK_INT;
String versionRelease = Build.VERSION.RELEASE;
switch(apiLevel){
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
sMaxAllowed = 100;
sCheckPeriod = 3600000;
break;
case 16:
sMaxAllowed = 30;
sCheckPeriod = 1800000;
break;
case 17:
sMaxAllowed = 30;
if(versionRelease.contains("4.2.2")){
sCheckPeriod = 60000;
}else {
sCheckPeriod = 1800000;
}
break;
case 18:
sMaxAllowed = 30;
sCheckPeriod = 60000;
break;
default:
sMaxAllowed = 30;
sCheckPeriod = 1800000;
break;
}
sMaxAllowed = sMaxAllowed - 2; //This is to give us a little buffer to be extra safe (like a condom ;)
Log.d(TAG, "maxAllowed = "+sMaxAllowed+"; checkPeriod = "+(sCheckPeriod/60000) + " minutes");
}`
Related
I want to change my app's background randomly. It's supposed to have a random image from its own folder as background. It works perfectly with some devices but with some of them doesn't. I wonder what could cause this inconsistency. Here is my random background generator class:
public class arkaplanGenerator {
public static int arkaplan(){
int sonucArkaplan = 0;
Random r = new Random();
int sayi = r.nextInt(11);
switch (sayi){
case 0:
sonucArkaplan = R.drawable.bavaria;
break;
case 1:
sonucArkaplan = R.drawable.gorges;
break;
case 2:
sonucArkaplan = R.drawable.more;
break;
case 3:
sonucArkaplan = R.drawable.mountains;
break;
case 4:
sonucArkaplan = R.drawable.pisa;
break;
case 5:
sonucArkaplan = R.drawable.sea;
break;
case 6:
sonucArkaplan = R.drawable.sunset;
break;
case 7:
sonucArkaplan = R.drawable.sunset2;
break;
case 8:
sonucArkaplan = R.drawable.wai;
break;
case 9:
sonucArkaplan = R.drawable.water;
break;
case 10:
sonucArkaplan = R.drawable.waterfall;
break;
}
return sonucArkaplan;
}
And here is how i use it in my main activity:
LinearLayout linearLayout = (LinearLayout)findViewById(R.id.activity_main);
linearLayout.setBackground(getResources().getDrawable(arkaplanGenerator.arkaplan()));
Those images are in drawable folder.Thanks in advance.
The method getDrawable from the Resources class has been deprecated. You should use the one from ContextCompat:
linearLayout.setBackground(ContextCompat.getDrawable(getApplicationContext(),arkaplanGenerator.arkaplan()));
So this is what I am doing.The below statement is the last line of an int return type method.
return ContextCompat.getColor(getContext(),magColor);
The error says that i have passed the wrong first argument.
Precisely:
Wrong 1st argument type. Found: 'java.security.AccessControlContext',
required: 'android.content.Context'
Entire Method:
public int getMagnitudeColor(double mag) {
int magColor;
int mag1=(int) mag;
switch (mag1) {
case 1:
magColor = R.color.magnitude1;
break;
case 2:
magColor = R.color.magnitude2;
break;
case 3:
magColor = R.color.magnitude3;
break;
case 4:
magColor = R.color.magnitude4;
;
break;
case 5:
magColor = R.color.magnitude5;
break;
case 6:
magColor = R.color.magnitude6;
break;
case 7:
magColor = R.color.magnitude7;
break;
case 8:
magColor = R.color.magnitude8;
break;
case 9:
magColor = R.color.magnitude9;
break;
default:
magColor = R.color.magnitude10plus;
break;
}
return ContextCompat.getColor(getContext(),magColor);
}
This is because your getContext() in:
return ContextCompat.getColor(getContext(),magColor);
is not android.content.Context.
You need to use context from Activity, Service, Application and View.
If you use custom class, you need to pass the context to the class.
I did this and it worked , 1 single line
view.listViewPalabrasLinearLayout.setBackgroundColor(ContextCompat.getColor(view.context,color))
where "listViewPalabrasLinearLayout" is the id of my layout and "color" is the variable I specify the color
in the davik vm/mterp/out/InterpC-portable.cpp code, when interpret invokeMethod, I find it can only handle the case when count is less or equal than 5:
switch (count) {
case 5:
outs[4] = GET_REGISTER(vsrc1 & 0x0f);
case 4:
outs[3] = GET_REGISTER(vdst >> 12);
case 3:
outs[2] = GET_REGISTER((vdst & 0x0f00) >> 8);
case 2:
outs[1] = GET_REGISTER((vdst & 0x00f0) >> 4);
case 1:
outs[0] = GET_REGISTER(vdst & 0x0f);
default:
;
}
then what about the case when the argument size is more than 5?
Sorry I miss something, that the senario I mentioned is the case of non-range call, there is a range call that I missed:
*/
if (methodCallRange) {
// could use memcpy or a "Duff's device"; most functions have
// so few args it won't matter much
assert(vsrc1 <= curMethod->outsSize);
assert(vsrc1 == methodToCall->insSize);
outs = OUTS_FROM_FP(fp, vsrc1);
for (i = 0; i < vsrc1; i++)
outs[i] = GET_REGISTER(vdst+i);
....
so it's handled here!
My Log line says animalclass is 4 but instead of going to "case 4" it returns default. It works with case 2 though. How is this possible? Thanks in advance.
public int gettile(int animalclass) {
Log.e("gettile", "animalclass = " + animalclass);
switch (animalclass) {
case 1: //
tile=R.drawable.picnictile;
break;
case 2: //
tile=R.drawable.picnictile;
break;
case 3: //
tile=R.drawable.picnictile;
case 4: //
tile=R.drawable.picnictile;
case 5: //
tile=R.drawable.face;
default:
Log.e("gettile", "failed!!!!!!!!!! = " + animalclass);
tile=R.drawable.rainbowtile;
break;
}
Log.e("gettile", "returning = " + tile);
return tile;
}
you need to use break; to stop other case execution because without break it will execute the correct case block statements and also "default" code block
Try adding the Break statemenet after all cases.
case 3: //
tile=R.drawable.picnictile;
break;
case 4: //
tile=R.drawable.picnictile;
break;
case 5: //
tile=R.drawable.face;
break;
If you dont break it after the "thing" the case should do, the switch does not work correct.
You forgot to add a break keyword before the default keyword.
Try this one:
public int gettile(int animalclass) {
Log.e("gettile", "animalclass = " + animalclass);
switch (animalclass) {
case 1: //
tile=R.drawable.picnictile;
break;
case 2: //
tile=R.drawable.picnictile;
break;
case 3: //
tile=R.drawable.picnictile;
break;
case 4: //
tile=R.drawable.picnictile;
break;
case 5: //
tile=R.drawable.face;
break;
default:
Log.e("gettile", "failed!!!!!!!!!! = " + animalclass);
tile=R.drawable.rainbowtile;
break;
}
Log.e("gettile", "returning = " + tile);
return tile;
}
Add break; keyword after each case, otherwise switch will execute default statement also and result will be unexpected.
TelephonyManager.getNetworkType() returns one of the constant values.
It appears that the constant values have an integer order, by possible bearer link speed.
I know using constant values used in the following manner is generally bad,
however could one use this to determine a basic cutoff for application functionality and have it work between API levels? (in API-v1 there was nothing above 0x03)
if( telephonyManager.getNetworkType() > TelephonyManager.NETWORK_TYPE_EDGE )
{
return "3G! party on!";
}
else if( telephonyManager.getNetworkType() > TelephonyManager.NETWORK_TYPE_UNKNOWN )
{
return "2G, OK. just don't go nuts!";
}
else
{
return "No data sorry"
}
You cannot assume they are in order because they are not. For example, LTE is 13 while HSPAP (HSPA+) is 15. Those are not in order. I wrote a "speed ranking" piece of code, which assignes each network type its own speed rank
public static int getNetTypeSpeedRank(int t) {
switch (t) {
case -1:
t = -1;
case ContextManager.MDM_NETWORK_TYPE_UNKNOWN:
t = 0;
break;
case ContextManager.MDM_NETWORK_TYPE_IDEN:
t = 1;
break;
case ContextManager.MDM_NETWORK_TYPE_GPRS:
t = 2;
break;
case ContextManager.MDM_NETWORK_TYPE_EDGE:
t = 3;
break;
case ContextManager.MDM_NETWORK_TYPE_UMTS:
t = 4;
break;
case ContextManager.MDM_NETWORK_TYPE_CDMA:
t = 5;
break;
case ContextManager.MDM_NETWORK_TYPE_1xRTT:
t = 6;
break;
case ContextManager.MDM_NETWORK_TYPE_EVDO_0:
t = 7;
break;
case ContextManager.MDM_NETWORK_TYPE_EVDO_A:
t = 8;
break;
case ContextManager.MDM_NETWORK_TYPE_EVDO_B:
t = 9;
break;
case ContextManager.MDM_NETWORK_TYPE_HSDPA:
t = 10;
break;
case ContextManager.MDM_NETWORK_TYPE_HSUPA:
t = 11;
break;
case ContextManager.MDM_NETWORK_TYPE_HSPA:
t = 12;
break;
case ContextManager.MDM_NETWORK_TYPE_HSPAP:
t = 13;
break;
case ContextManager.MDM_NETWORK_TYPE_EHRPD:
t = 14;
break;
case ContextManager.MDM_NETWORK_TYPE_LTE:
t = 15;
break;
default:
t = 16;
}
return t;
}
I really wouldn't count on that behavior.