Hello everyone , I am here with new article which is hot topic nowadays "Android 11" .The stable version of Android.
Android 11 is the eleventh major release and 18th version of Android, the mobile operating system developed by the Open Handset Alliance led by Google. It was released on September 8, 2020.It is comes with many security features and other features as well .
And it is now compulsory in play store to upload new apps with API lavel 30 which is compatible with Android 11 and from November onwards old apps also have to update with API 30 .Some other guidelines you can check out from here .Play Store Guidelines
So its clear that we have to update our apps with API level 30 .But Android 11 comes with some changes as well which we have to do in our projects.
For example from Android developer site "Android 11 (API level 30) further enhances the platform, giving better protection to app and user data on external storage. ".
Scoped storage enforcement:
Apps that run on Android 11 but target Android 10 (API level 29) can still request the requestLegacyExternalStorage attribute. This flag allows apps to temporarily opt out of the changes associated with scoped storage, such as granting access to different directories and different types of media files. After you update your app to target Android 11, the system ignores the requestLegacyExternalStorage flag.
If your app targets Android 11, both the WRITE_EXTERNAL_STORAGE permission and the WRITE_MEDIA_STORAGE privileged permission no longer provide any additional access.
Whats does it mean ?
It means we have limited access of Write External Storage in Android 11 .Android introduce a new permission which is MANAGE_EXTERNAL_STORAGE
It will gives you some other access:
- Read and write access to all files within shared storage.
- Access to the contents of the MediaStore.Files table.
- Access to the root directory of both the USB on-the-go (OTG) drive and the SD card.
- Write access to all internal storage directories, except for /Android/data/, /sdcard/Android, and most subdirectories of /sdcard/Android. This write access includes direct file path access.
- File managers
- Backup and restore apps
- Anti-virus apps
- Document management apps
- On-device file search
- Disk and file encryption
- Device-to-device data migration
Uri imageUri = null; ......... share=(ImageView)findViewById(R.id.share); share.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Bitmap bitmap = takeScreenshot(); saveBitmap(bitmap); shareIt(); } }); ................. public Bitmap takeScreenshot() { View rootView = findViewById(android.R.id.content).getRootView(); rootView.setDrawingCacheEnabled(true); return rootView.getDrawingCache(); } public void saveBitmap(Bitmap bitmap) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { OutputStream fos = null; imageUri = null; ContentResolver resolver = ctx.getContentResolver(); ContentValues contentValues = new ContentValues(); contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, "screen"+System.currentTimeMillis()); contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/png"); contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_PICTURES + File.separator); imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues); if (imageUri == null) try { throw new IOException("Failed to create new MediaStore record."); } catch (IOException e) { e.printStackTrace(); } try { fos = resolver.openOutputStream(imageUri); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } private void shareIt() { if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.Q) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); sharingIntent.setDataAndType(imageUri, "image/*"); // sharingIntent.setType("image/*"); String shareBody = "Please Find the screenshot."; sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Your Subject here"); sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody); sharingIntent.putExtra(Intent.EXTRA_STREAM, imageUri); startActivity(Intent.createChooser(sharingIntent, "Share via")); } }
contct.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_PICK); intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); if (intent.resolveActivity(getPackageManager()) != null) { startActivityForResult(intent, PICK_CONTACT); } } }); ........ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode==Activity.RESULT_OK) { if (requestCode == PICK_CONTACT) { try { Uri contactUri = data.getData(); String[] projection = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER}; Cursor cursor = getContentResolver().query(contactUri, projection, null, null, null); // If the cursor returned is valid, get the phone number if (cursor != null && cursor.moveToFirst()) { int numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); String number = cursor.getString(numberIndex).replaceAll("-", ""); String selectedNumber = number.toString(); selectedNumber = selectedNumber.replace("-", ""); selectedNumber = selectedNumber.replace(" ", ""); selectedNumber =selectedNumber.replace("(",""); selectedNumber=selectedNumber.replace(")",""); selectedNumber = selectedNumber.replace("+91", ""); selectedNumber = selectedNumber.replace(" ", ""); if (selectedNumber.toString().length() >= 10) { enteredMobile.setText(selectedNumber); } else { Toast.makeText(ctx, "Choose Valid mobile number", Toast.LENGTH_SHORT).show(); } } } catch (Exception e) { e.printStackTrace(); } } } }
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
</intent>
</queries>
<queries> .... <package android:name="com.example.firstapp" /> <package android:name="com.example.secondapp" /> <package android:name="com.example.thirdapp" /> ..... </queries>
<queries>
<intent>
<action
android:name="android.intent.action.TTS_SERVICE" />
</intent>
</queries>
Comments
Post a Comment