how to get all music players - java

I want to query all activitys that can play a music file.
I have tried to get all music players like this:
Intent resolve_intent = new Intent();
resolve_intent.setAction(android.content.Intent.ACTION_VIEW);
resolve_intent.setType("audio/*");
packages = getPackageManager().queryIntentActivities(resolve_intent, 0);
if (packages == null || packages.size() <= 0)
{
//none found
}
but i everytime get an empty (or null) list...
if i do this for type = "image/* or "video/*"
i get all applications that can handle this type.
only for "audio/*" i get no players installed, even if i know that there is one...
so what am i doing wrong?

Fond it myself:
i forgot to set the Data, and i didn't know android uses the data too
to resolve the matching intents...
working code:
Intent resolve_intent = new Intent();
resolve_intent.setAction(android.content.Intent.ACTION_VIEW);
resolve_intent.setDataAndType(Uri.fromFile(new File("/some/path/to/a/file")), "audio/*");
List<ResolveInfo> packages = context.getPackageManager().queryIntentActivities(resolve_intent, 0);

Related

“Protected Apps” setting on Android phones

We can ask the user to protect our app, by using (e.g. Huawei phones):
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
startActivity(intent);
Is there a way of knowing if the app got protected or not? I'm trying to avoid asking the user to protect the app e.g. every time the app is created.
For other intents, I can use:
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(
new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:" + getPackageName()))
,
PackageManager.MATCH_DEFAULT_ONLY);
System.out.println("MY_intent_TEST_1(looks always true): "+( list.size() > 0 ) );
PowerManager pwm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
System.out.println("MY_intent_TEST_2(true when whitelisted): "+ pwm.isIgnoringBatteryOptimizations(context.getPackageName()) );
P.S. I'm learning from: "Protected Apps" setting on Huawei phones, and how to handle it
Because related interfaces are not exposed, currently you cannot get to know whether the app got protected or not.

How to search specific nearby places

I am creating a Google Maps app. In my app I am searching for nearby ATMs by using Places type "ATM". It all works perfectly, but I have to find specific nearby ATMs such as Axis bank ATMs. So how do I do this?
I have implemented the same in my app . Use the following function for the same:
private void showNearbyAtms(){
Uri mapIntentUri = Uri.parse("geo:0,0?q= Axis atm");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, mapIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (getActivity() != null && mapIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(mapIntent);
}
}

can any one help me on this android app

hello i have an app of POS ( point of sale )
i wanted to make it send printing data to be printed through bluetooth printer
i found this solution
https://play.google.com/store/apps/details?id=com.fidelier.posprinterdriver
its a driver for my printer
they say
+### Print from your Android App (interactive user action)
+
+Create your ESC data using the helpers Create an Android Intent using Add your ESC data as a “Data” extra Start the intent.
+You can be printing in minutes with just a couple lines of code. It's as simple as creating your intent, adding your ESC formatted string and start the (service) intent.
+
+Example:
+
+```java
+
+String dataToPrint="$big$This is a printer test$intro$posprinterdriver.com$intro$$intro$$cut$$intro$";
+
+Intent intentPrint = new Intent();
+
+intentPrint.setAction(Intent.ACTION_SEND);
+intentPrint.putExtra(Intent.EXTRA_TEXT, dataToPrint);
+intentPrint.setType("text/plain");
+
+this.startActivity(intentPrint);
+
+```
can any body tell me how can i do that ???
where should i put these codes ? ?
Lets say you have your activity with a button link to this method :
public void click(View v){
Intent intentPrint = new Intent();
intentPrint.setAction(Intent.ACTION_SEND);
intentPrint.putExtra(Intent.EXTRA_TEXT, "Just some dummy text to print");
intentPrint.setType("text/plain");
this.startActivity(intentPrint);
}
By clicking on this button, the intent will be launched, this will probably open a list of application that can handle this kind of intent (ACTION_SEND), choose the correct one and this should do it.

How can I programmatically open a user specified calling/sms/mms Android app?

I've created an address book app, and am trying to add some features to it. What I'm trying to do right now is add the ability to longclick a phone number, and then either call/text/mms the number. This all works fine with phones, but I was wondering how to do this on tablets, since they will not have that same ability. The device I'm debugging on is a tablet, and I use HeyWire for texting. I know there are apps out there for calling via WiFi as well. Here's what I have so far for the texting section of my switch statement:
case 1: //SMS
if(CanCallAndText)
{
CustomSMSDialog SendSMSDialog = new CustomSMSDialog(BrowseListActivity.this, ParsedPhoneNum);
SendSMSDialog.setTitle("Sending text to " + PhoneNum);
SendSMSDialog.setCancelable(false);
SendSMSDialog.show();
}
else
{
try
{
Intent WiFiSMS = new Intent(Intent.ACTION_VIEW);
WiFiSMS.setData(Uri.parse("sms:" + PhoneNum));
WiFiSMS.setType("vnd.android-dir/mms-sms");
startActivityForResult(Intent.createChooser(WiFiSMS, ""), 0);
}//endtry
catch(Exception e)
{
Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}//endcatch
}//endelse
break;
I don't know if I'm doing the create chooser incorrectly or not, but it simply tells me that no apps can handle it. Thank you!
EDIT: Ooh, spotted a slight error that I should fix tomorrow. The URI should include ParsedPhoneNum, instead of PhoneNum. Anything other than a number, like a -, would be included in PhoneNum.

Proximity Alert Intent not putting or returning extras

What I'm doing is adding different proximity alerts with a unique ID as an extra and it's not working -
for (int i = 0; i < latArray.size(); i++)
{
Bundle extra = new Bundle();
extra.putInt("UID", i);
Intent intent = new Intent(IntentToFire);
intent.putExtra("Blob", extra);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this,-1 , intent, 0);
LocationManager locationManager =
Log.i("Picture:","Location img:"+GetLocation.imgArray.get(i));
Log.i("Potatoo:", "Lat :"+latArray.get(i)+" Lng :"+lngArray.get(i));
locationManager.addProximityAlert(Double.valueOf(latArray.get(i)), Double.valueOf(lngArray.get(i)), radius,expiration,proximityIntent);
}
And then on the broadcast receiver I'm putting this code -
flag = intent.getBundleExtra("blob").getInt("UID");
Every time I got to print flag, I just get an error. An ideas?
Try to use the FLAG_UPDATE_CURRENT:
PendingIntent.getBroadcast(this,-1 , intent, PendingIntent.FLAG_UPDATE_CURRENT);
I found it easiest is to encode data in the data-uri with proximity alerts on the Intent that is included in the pending intent, e.x.:
geo:<lat>,<lon>?id=<your id>
You can use your own protocol part though (geo is used by google maps AFAIK). No caching problems for me (seems you get a cached/old/wrong PendingIntent).

Categories

Resources