Android: what to choose for requestcode values?

Documenting the findings for future reference: The following are code from android.support.v4.app.FragmentActivity /** * Modifies the standard behavior to allow results to be delivered to fragments. * This imposes a restriction that requestCode be <= 0xffff. */ @Override public void startActivityForResult(Intent intent, int requestCode) { if (requestCode != -1 && (requestCode&0xffff0000) != 0) { throw … Read more

App links intent filters in assetlinks.json not working on Android

For us it was Windows line endings! Testing with “https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://domain1:port&relation=delegate_permission/common.handle_all_urls” proved invaluable as it gave us an “Could not parse statement list (not valid JSON)” error which led us to the problem. TIP: It was good to use the ‘Save File’ button in the Android Studio App Links Assistant instead of copying and pasting as … Read more

How to use the new Android M feature of “Text Selection” to be offered from outside of your app?

First, to clarify the question: On an M emulator, if you highlight text, you will see the new floating action mode. If you click the overflow icon, you will see “API DEMOS” show up: Clicking that brings up an activity from the API Demos app, showing the highlighted text: Replacing the value in the field … Read more

Answer Incoming Call in Android 6.0

Hope this will help some one 🙂 public void acceptCall() { if (Build.VERSION.SDK_INT >= 21) { Intent answerCalintent = new Intent(context, AcceptCallActivity.class); answerCalintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); answerCalintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(answerCalintent); } else { Intent intent = new Intent(context, AcceptCallActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } } AcceptCallActivity.java import android.app.Activity; import android.app.KeyguardManager; import android.content.BroadcastReceiver; import … Read more

How to get SD_Card path in android6.0 programmatically

Here’s my solution, which is guaranteed to work till Android 7.0 Nougat: /* returns external storage paths (directory of external memory card) as array of Strings */ public String[] getExternalStorageDirectories() { List<String> results = new ArrayList<>(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //Method 1 for KitKat & above File[] externalDirs = getExternalFilesDirs(null); String internalRoot = Environment.getExternalStorageDirectory().getAbsolutePath().toLowerCase(); … Read more

Grant permission required for EXTERNAL_STORAGE in Android M?

I agree with Guillaume Perrot ‘s answer. I have met the similar question when I write the permission of READ_WRITE_EXTERNAL_STORAGE in AndroidManifest.xml with no permissions showing up in the app by default , people need to switch the toggle button of storage in the app permissions.Then I modify my targetSdkVersion in build.gradle to less than … Read more

Since marshmallow update Bluetooth discovery using BluetoothAdapter.getDefaultAdapter().startDiscovery(); is broken

Bluetooth Adapter has been change in Android 6.0 You need to set the permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission and need to use BluetoothLeScanner.startScan() method to start the scan. Below is the description from change logs: To provide users with greater data protection, in Android 6.0, Android removes programmatic access to the device’s local hardware identifier … Read more

Get Current Location 0 in marshmallow where below 23 API its give exact current Location using fused Location

Use below code. Hope this is useful. Make sure you run this code into real device only. activity_main.xml <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”match_parent” android:layout_height=”match_parent”> <fragment xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:id=”@+id/map” android:name=”com.google.android.gms.maps.SupportMapFragment”/> </LinearLayout> MainActivity.java import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationManager; import android.os.Build; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import … Read more