Application not woking on android 4.0 - java

My program is working absolutely fine from android 2.1 to android 2.3
But its not working on higher version of android.
It does not give any exception when the app is executed on a higher version than 2.3.
When run on 2.3 or lower version the number is correctly dialed and imei or other query is executed properly but when the app is run on higher version only dialpad with the code opens but the number/code is not dialed
I have used in my manifest file
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="18" />
And my MainActivity Class
public class Motorola extends Activity implements OnClickListener{
TextView tvm1,tvm2,tvm3;
Intent myIntent;
String m=Uri.encode("#");
String str;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.motorola);
tvm1=(TextView) findViewById(R.id.tvmo1);
tvm2=(TextView) findViewById(R.id.tvmo3);
tvm3=(TextView) findViewById(R.id.tvmo2);
AdView adv3=(AdView) findViewById(R.id.ad4);
adv3.loadAd(new AdRequest());
tvm1.setOnClickListener(this);
tvm2.setOnClickListener(this);
tvm3.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
/* *#06#:DISPLSYS IMEI NUMBER.
*#*#4636#*#*:DISPLAY INFORMATION ABOUT PHONE, BATTERY AND USAGE STATISTICS.
##7764726:MOTOROLA DROID HIDDEN SERVICE MENU. THE DEFAULT SPC PASSWORD IS SIX ZEROES (000000).*/
switch(v.getId())
{
case R.id.tvmo1:
str="*"+m+"06"+m;
myIntent=new Intent(Intent.ACTION_DIAL);
myIntent.setData(Uri.parse("tel:"+str));
startActivityForResult(myIntent,1);
break;
case R.id.tvmo2:
str="*"+m+"*"+m+"4636"+m+"*"+m+"*";
myIntent=new Intent(Intent.ACTION_DIAL);
myIntent.setData(Uri.parse("tel:"+str));
startActivityForResult(myIntent,1);
break;
case R.id.tvmo3:
str=m+m+7764726;
myIntent=new Intent(Intent.ACTION_DIAL);
myIntent.setData(Uri.parse("tel:"+str));
startActivityForResult(myIntent,1);
break;
}
}
}

For some codes, you can try using Intent.ACTION_CALL instead of Intent.ACTION_DIAL
But for most codes Im afraid you wont be able of doing that.
You can take a look at this answer
... in the beginning, it was possible to directly call USSD
codes from an app (using the intent Intent.ACTION_DIAL) [...]
But that was actually considered a
vulnerability of the system, since somebody could write malicious
software, or even more, insert malicious code in a website that could
even wipe your phone or block the sim card[...]
At this point it will be hard to find any device
still vulnerable.
Go to the answer to find out more

You shouldn't be using the dialer for these tasks. Instead, use the appropriate Android APIs to get this information. Here are two questions to get you started quickly:
How to get the device's IMEI/ESN programmatically in android?
Get battery level before broadcast receiver responds for Intent.ACTION_BATTERY_CHANGED
For more details, see the TelephonyManager reference documentation and the Android training article Monitoring the Battery Level and Charging State.

Related

Android App Recognising lack of permissions but not allowing the ability to grant them

I am trying to develop a basic app usage monitor for Android. There's not much online help I could find bar one video here without just copying someone else's GitHub repo. I selected development with Android 10 (Q) as my SDK.
Essentially, since to my understanding in Lollipop and above you have to perform an Intent to get permissions, it should be as simple doing an intent to get Settings.ACTION_USAGE_ACCESS_SETTINGS which is what I would need to get an app's total time in foreground.
However, the app recognises it lacks permissions and takes the user to the system permissions page in the settings, but there is no option to actually give the app any settings. The app will complain about having no required permissions but I, as the user, have no ability to grant it any of those permissions on the emulated device.
The following is an extract of the start of my MainActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sharedPreferences = getSharedPreferences("Focus", MODE_PRIVATE);
if(!checkUsageStatsAllowedOrNot()) {
Intent usageAccessIntent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
usageAccessIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(usageAccessIntent);
if (checkUsageStatsAllowedOrNot()) {
startService(new Intent(MainActivity.this, BackgroundService.class));
}
else {
Toast.makeText(getApplicationContext(), "please give me access", Toast.LENGTH_SHORT).show();
}
This is the checkUsageStatsAllowedOrNot function:
public boolean checkUsageStatsAllowedOrNot() {
try {
PackageManager packageManager = getPackageManager();
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0);
AppOpsManager appOpsManager = (AppOpsManager) getSystemService(APP_OPS_SERVICE);
int mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, applicationInfo.uid, applicationInfo.packageName);
return (mode==AppOpsManager.MODE_ALLOWED);
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), "error cannot find any usage stats", Toast.LENGTH_SHORT).show();
return false;
}
}
As you can see from this image (ignore the crossed out one, that's not relevant), the only apps there are generic pre-installed ones when it opens the Usage permissions screen:
usage permissions opens but relevant developer app not there
Do you have any idea why this may be the case? I'm not sure if it's just because the video I followed is a bit old or most likely the fact that I only started using Android Studio 2 weeks and have barely a clue how this all works, but from my research this seems fine??
Any ideas will go a long way, thanks for reading.

Android Studio startActvity requires permission

I'm attempting to make a simple click action which calls a certain number, I'm on the last stage of the code and I cannot see what I'm doing wrong. Currently its the startActivity action which seems to be presenting the error but I don't know why I have watched multiple tutorials and I can see any difference. When above startActivity it informs me that a call permission is required?
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_home);
//On load the program automatically hides the taskbar.
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
Button b = (Button) this.findViewById(R.id.BTNCall);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Intent PhoneCall = new Intent(Intent.ACTION_CALL);
PhoneCall.setData(Uri.parse("tel:123"));
startActivity(PhoneCall);
}
});
}
I have also added a permission into the android manifest
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
You should set your target SDK version to lvl 22 or under, because for lvl 23 you need to ask user at run time for permission, look there for a better explanation.
Since you are doing it from a OnClickListener, the "this" pointer references to the clickListener class you are implementing, you need to get the reference to your activity just use:
MyActivityClassName.this.startActivity() //Dont know your class name
That should get rid of the red highlight.
If you are still getting a crash we will need the logcat output to solve it.
Hope this helps.

Error : Call requires API level 23(current min is 15):

I am trying to access the methods of the PlaybackParams class in my code but it gives me this error:
Call requires API level 23 (current min is
15): android.media.PlaybackParams#PlaybackParams
The song is playing (not smoothly it kind buffers like in youtube videos) but the set speed isn't increasing the tempo of the song.
Also, the seekTo() methods works properly but the setSpeed() method doesn't.
I've been trying to figure out the bug in the code but haven't found my way through yet.
Also, if I delete the whole implementation and the access of PlaybackParams' methods then only the song plays otherwise (as with the provided code) it throws many (-38,0) errors and this error also:
Attempt to perform seekTo in wrong state: mPlayer=0xad7a2460, mCurrentState=0
I know state =0 error means it's trying to start the song before it's loaded but I don't know how to make everything fit in place properly.
Here's my code:
MediaPlayer mySong;
PlaybackParams params = new PlaybackParams();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mySong = MediaPlayer.create(this, R.raw.fixyou);
}
public void musicPlayer (View view) {
mySong.seekTo(20000);
params.setSpeed(0.75f);
mySong.setPlaybackParams(params);
mySong.start();
}
Run the program on an emulator or a real device with API 23 because PlaybackParams class was newly added for API 23 and doesn't exist for lower API's.

Can you restrict a specific Android API version from running/downloading app from googlePlay store?

Alright so I'm having this one problem with an app I'm working on and planning on releasing, but the problem is only occurring on one version of the android SDK (Version 4.1.1 API 16).
Can I restrict JUST android version 4.1.1 API 16 from downloading and running my app?
I know googlePlay has a restrict certain device list, but the problem is occurring because of the OS version, NOT the device, at least it seems that way from debugging...
I also know there's the uses-sdk attributes in the manifest file:
<uses-sdk android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
But setting the android:minSdkVersion to 17 will be way to high and not be available to many users, I also put a lot of work into making the app backwards compatible and works fine on pre 3.0 devices, it's just this android version 4.1.1 API 16 that is causing me trouble...
Please help! Thank you!
Edit: This is my current uses-sdk in my apps manifest:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
Edit with relevant code:
//button listener for the number buttons. Each button will display a number 1 - 10
//upon clicking the button the number that is displayed on the button will be
//added to what is displayed in the textView
//
//mCurrentWorkingText is the current expression that is being added updated.
View.OnClickListener genericNumberButtonListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
//cast the incoming view to a textView so we can get
//the text the button displays
TextView textView = (TextView) v;
String textFromButton = textView.getText().toString();
if (mCurrentWorkingText.length() == 0) {
mWorkingTextView.setText(mWorkingTextView.getText()
.toString().concat(textFromButton));
mCurrentWorkingText = textFromButton;
} else {
// if the working TextView isn't zero we need to
// append
// the
// textFromButton to what is already there.
mWorkingTextView.setText(mWorkingTextView.getText()
.toString().concat(textFromButton));
mCurrentWorkingText = mCurrentWorkingText
.concat(textFromButton);
}
}
};
Edit with log of problem:
The string changes almost randomly to a completely random number in the last log statement.
You can prevent the app from running.
And no, you cannot prevent the app from downloading when on an API in between minSDKVersion and maxSDKVersion/targetSDKVersion
You can check it like this:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD && android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.HONEYCOMB) {
// For gingerbread but lesser than HONEYCOMB, show a dialog or something and close the app
finish();
}
So the problem I was having was caused by the pageTransformer that I was using. Android 4.1.1 really didn't like it. I don't know why but all I know is that if you're using pageTransformer with custom views and ActionBarSherlock you better be careful when using the pageTransformer to add animation to the page turns.

Android HTC Hero not reporting back correct FeatureInfo

I'm having a strange problem with my HTC Hero 2.1
model=HERO200
manufacturer=HTC
APILevel=7
It is not reporting back that it has a hardware microphone. Here is my code to check for Features.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Context context = this;
PackageManager pm = context.getPackageManager();
FeatureInfo[] foo = pm.getSystemAvailableFeatures();
for (FeatureInfo bar : foo) {
if (bar.name != null) {
System.out.println(bar.toString());
if (bar.name.equalsIgnoreCase("android.hardware.microphone"))
System.out.println("Booyah!");
}
}
}
It does report back these features:
android.hardware.camera
android.hardware.wifi
android.hardware.location.network
android.hardware.bluetooth
android.hardware.sensor.light
android.hardware.location
android.hardware.location.gps
android.hardware.camera.autofocus
android.hardware.touchscreen.multitouch
android.hardware.touchscreen
android.hardware.sensor.accelerometer
android.hardware.sensor.compass
Some are API Level 8 like compass and gps, and others are level 7. Is there another way I can search for features? Something else I can use besides getSystemAvailableFeatures()? Maybe a lower level system call? Why is my phone not reporting back that it has a hardware microphone? Help please :) Thanks!
I guess if this phone is set for Android API Level 7... then I just can't set a requirement that was designed for API Level 8 (Like microphone).
This is the proper way to request features of the phone from Android.
So... this sucks... oh well. But still weird that this phone does report back some features from API Level 8, but you shouldn't rely upon that.

Categories