My Android app has to launch gmaps on Wear OS
Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/search/?api=1&query=" +Uri.encode( string));
Intent mapIntent = new Intent(ACTION_VIEW, gmmIntentUri);
// mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(activity.getPackageManager()) != null) {
activity.startActivity(mapIntent);
}
but I get an error that says Permission denial... It wants
com.google.android.wearable.READ_SETTINGS
If I put this
<uses-permission android:name="com.google.android.wearable.READ_SETTINGS" />
in the manifest then I get the same kind of error.
I am not able to ask for permission programmatically with something similar to this
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_SETTINGS)
== PackageManager.PERMISSION_GRANTED) {
Log.d("permissions","granted");
} else {
// Show rationale and request permission.
ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.READ_SETTINGS},
MY_LOCATION_REQUEST_CODE);
}
because that constant is not found. It is not useful to write the complete com.google.android.wearable.READ_SETTINGS string.
I do not understand why READ_SETTINGS is needed.
How to solve?
Google Maps on wearOS cannot handle Uri.parse("https://www.google.com/maps/search/?api=1&query=" +Uri.encode( string)) or in this format as suggested in documentation Uri gmmIntentUri = Uri.parse("geo:0,0?q=1600 Amphitheatre Parkway, Mountain+View, California"). While the same intent on phone launches Google Maps and shows you a list of suggestions.
My guess is that the Maps app on wearOS is meant to be lightweight , you can only search for something in a particular city or region like this:
// Searches for 'Main Street' near San Francisco
Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4194?q=101+main+street");
The below link shows examples of Google Maps intents to use on Android : https://developers.google.com/maps/documentation/urls/android-intents
For the error:
com.google.android.wearable.READ_SETTINGS
You don't need to add this in permissions, but check whether your wear app manifest has this :
<uses-feature android:name="android.hardware.type.watch" />
Related
So this functionality was working previously, but I guess somewhere when I upgraded versions, it does not anymore.
I want to create dynamically an audio file (this is working), and copy it to the storage (this is working, it is currently copied to my local app storage :
Android/data/com.mypackagename/files/xxx.mp3
Then I create a new ContentValues with the data & metadata and insert it into MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.
After that I set ringtone and launch ringtone picker to check:
RingtoneManager.setActualDefaultRingtoneUri(_instance, RingtoneManager.TYPE_RINGTONE, newUri);
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, newUri);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, newUri);
startActivityForResult(intent, 1);
But the ringtone set is only the ID of the media, not the name, and I can't find it in the list..
I though the Media wasn't scanned, so i tried this beforehand:
Intent scanFileIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri);
sendBroadcast(scanFileIntent);
I'm not really sure what this does, but it didn't helped.
Any clues what's going on with the current status of creating ringtone with Android Studio ?
So here was my error. I needed to correct some things in my Manifest to get the rights permissions:
//Without this folders will be inaccessible in Android-11 and above devices
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
//Without this entry storage-permission entry will not be visible under app-info permissions list Android-10 and below
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29"
tools:ignore="ScopedStorage"/>
//Without this entry the folders will remain in-accessible in Android-10, even if WRITE_EXTERNAL_STORAGE as above is present.
<application
android:requestLegacyExternalStorage="true"/>
The Ringtones external root folder is not accessible from basic WRITE_EXTERNAL_STORAGE permissions anymore. We have access to app specific external folder, & others (link).
Even the Media store does not give you access to this folder, so from Android 11 & forward, you need the MANAGE_EXTERNAL_STORAGE permission, that gives you this warning:
Most apps are not allowed to use MANAGE_EXTERNAL_STORAGE. Because you need to ask for this permission to the user, and he might refuse..
But if you want to do what I wanted to do, you'll need it..
Be sure that your app ask for the permission through:
// permission: Manifest.permission.WRITE_EXTERNAL_STORAGE
// permission_id: 1
public Boolean checkPermission(String permission, Integer permission_id) {
if (ContextCompat.checkSelfPermission(_instance, permission) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(_instance, new String[]{permission}, permission_id);
return false;
} else {
return true;
}
}
I'm trying to list all apps in android device with queryIntentActivities method but the list doesn't return all the apps , It returns only three of them. Here is my code:
PackageManager packageManager = getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> allApps = packageManager.queryIntentActivities(intent, 0);
for (ResolveInfo ri : allApps) {
Log.d("Labels", String.valueOf(ri.loadLabel(packageManager)));
}
is there anyone now why it returns only 3 applications ?
You are most likely trying to do this on Android 11. Make sure you add the <uses-permission android:name"android.permission.QUERY_ALL_PACKAGES"> permission to the AndroidManifest.xml file.
While I haven't tested this aspect of R DP2 yet, it appears that your
app now can't find out what other apps are installed, on a general
basis. The cited example is queryIntentActivities(), but to make this
really work you would need to seriously lobotomize PackageManager. You
can whitelist certain packages and certain structures
to try to get by this for certain use cases. And, this is where the
mysterious QUERY_ALL_PACKAGES permission seen in DP1 comes into play —
this permission removes these new restrictions. Given the "look for
Google Play to provide guidelines for apps that need this permission"
caveat, it is safest to assume that if you try using it, eventually
you will be banned from the Play Store by a bot.
Some hidden settings require to type codes like *#06# in dialer.
Is it possible to create an app that does something when it detects a specific code like that ?
If you are trying to create a USSD based application then below link can help.
Read USSD messages in Android
However, if you want to simply dial a USSD content add respective permission in AndroidManifest.xml file as below and try :
<uses-permission android:name="android.permission.CALL_PHONE" />
private void dialUSSD(String uriString) {
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(uriString));
startActivity(callIntent);
}
I have a button in my application which opens the imdb application in the phone with a imdb id I received from https://developers.themoviedb.org/3/getting-started/introduction
But I couldnt find anyway(using intents) to make my app recognize the imdb app and open it and if imdb app do not exist then I want to open the web site. How can I accomplish this?
I think I may be able to point you in the right direction. Just to be sure, you seem to be using TMDB but wish to open in the IMDB app?
The code below is from the Android documentation.
It will start your intent if the package manager can find an app with the appropriate intent filter installed on your device. If multiple apps are able to open this intent then an app chooser should pop up, unless the user has previously set a default for this kind of URI.
Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Always use string resources for UI text.
// This says something like "Share this photo with"
String title = getResources().getString(R.string.chooser_title);
// Create intent to show the chooser dialog
Intent chooser = Intent.createChooser(sendIntent, title);
// Verify the original intent will resolve to at least one activity
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
If you add an else onto that then you can use a view intent like this :
Intent internetIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieUrl));
//Watch out here , There is a URI and Uri class!!!!
if (internetIntent.resolveActivity(getPackageManager()) != null){
startActivity(internetIntent);
}
I also found this (rather old) post about calling an explicit imdb uri
Imdb description
startActivity(android.intent.action.VIEW, imdb:///title/<titleID>);
// take note of the Uri scheme "imdb"
I hope this helps. If you post some more detail , code, links , I might be able to work through this with you.
If my answer is way off base then please be kind and set me right. We are all learning every day!
Good Luck.
Because I want to make sure the MediaStore has the latest information without having to reboot I'd like to trigger the MediaScanner using the popular way I found on SO
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
This works fine on my Samsung S2 w/ICS but not on my Nexus 7 w/JellyBean. Logcat shows this on my Nexus 7:
WARN/ActivityManager(480): Permission denied: checkComponentPermission() owningUid=10014
WARN/BroadcastQueue(480): Permission Denial: broadcasting Intent { act=android.intent.action.MEDIA_MOUNTED dat=file:///storage/emulated/0 flg=0x10 } from com.example.foo.bar (pid=17488, uid=10046) is not exported from uid 10014 due to receiver com.android.providers.downloads/.DownloadReceiver
INFO/ActivityManager(480): Start proc com.google.android.music:main for broadcast com.google.android.music/.store.MediaStoreImportService$Receiver: pid=17858 uid=10038 gids={50038, 3003, 1015, 1028}
INFO/MusicStore(17858): Database version: 50
INFO/MediaStoreImporter(17858): Update: incremental Added music: 0 Updated music: 0 Deleted music: 0 Created playlists: 0 Updated playlists: 0 Deleted playlists: 0 Inserted playlist items: 0 Deleted playlist items: 0 Removed orphaned playlist items: 0
The last line sounds encouraging in theory, but the values are always 0 even after new files had been pushed to the SD card (via adb push). On my older device (S2) it does remount the SD card.
I've added the following permissions to my AndroidManifest.xml but it behaves the same as without those permissions:
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Any ideas/alternatives?
Edit 1:
Note that I don't know any file paths of new or modified or deleted files. I just want to make sure the MediaStore is up-to-date.
Here's the sample code based on CommonsWare's answer:
MediaScannerConnection.scanFile(activity, new String[]{path}, null,
new MediaScannerConnection.OnScanCompletedListener() {
#Override
public void onScanCompleted(final String path, final Uri uri) {
Log.i(TAG, String.format("Scanned path %s -> URI = %s", path, uri.toString()));
}
});
Even though in most of the cases, where one knows the files to be added/updated/etc. to the MediaStore, one should follow CommonsWare's answer, I wanted to post the my solution where I need to do it the rough way because I don't know the file paths. I use this mostly for testing/demoing:
Uri uri = Uri.fromFile(Environment.getExternalStorageDirectory());
activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, uri));
BTW, no permissions are necessary for either solution.
using the popular way I found on SO
Faking ACTION_MEDIA_MOUNTED broadcasts has never been an appropriate solution IMHO.
Any ideas/alternatives?
Use MediaScannerConnection, such as via its scanFile() static method.
My answer is a little late, but it might help those, who save a new file, and would like to extend the media store by just that file on Android Kitkat: On Android Kitkat the intent ACTION_MEDIA_MOUNTED is blocked for non-system apps (I think, because scanning the whole filesystem is pretty expensive). But it is still possible to use the intent ACTION_MEDIA_SCANNER_SCAN_FILE to add a file to the media store:
File f = new File(path to the file you would like to add to the media store ...);
try {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(f);
mediaScanIntent.setData(uri);
sendBroadcast(mediaScanIntent);
} catch(Exception e) {
...
}