Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import pub.devrel.easypermissions.AppSettingsDialog;
import pub.devrel.easypermissions.EasyPermissions;

public class MainActivity extends AppCompatActivity implements
EasyPermissions.PermissionCallbacks {
public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks {

private static final String TAG = "MainActivity";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;

/**
* Created in {@link R.layout#activity_main}
*/
public class MainFragment extends Fragment implements EasyPermissions.PermissionCallbacks {

private static final String TAG = "MainFragment";
private static final int RC_SMS_PERM = 122;
private static final int RC_SETTINGS = 123;

@Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package pub.devrel.easypermissions;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.app.Fragment;
import android.text.TextUtils;

Expand Down Expand Up @@ -65,6 +66,7 @@ public void onClick(DialogInterface dialog, int which) {
intent.setData(uri);

// Start for result
//noinspection NewApi The Builder constructor prevents this
startForResult(activityOrFragment, intent, settingsRequestCode);
}
});
Expand All @@ -76,7 +78,7 @@ public void onClick(DialogInterface dialog, int which) {
mAlertDialog = dialogBuilder.create();
}

@TargetApi(11)
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TargetApi is technically deprecated.

From the RequiresApi docs:

This is similar in purpose to the older @TargetApi annotation, but more clearly expresses that this is a requirement on the caller, rather than being used to "suppress" warnings within the method that exceed the minSdkVersion.

private void startForResult(Object object, Intent intent, int requestCode) {
if (object instanceof Activity) {
((Activity) object).startActivityForResult(intent, requestCode);
Expand Down Expand Up @@ -135,7 +137,7 @@ public Builder(@NonNull android.support.v4.app.Fragment fragment, @NonNull Strin
* @param fragment the Fragment in which to display the dialog.
* @param rationale text explaining why the user should launch the app settings screen.
*/
@TargetApi(11)
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public Builder(@NonNull android.app.Fragment fragment, @NonNull String rationale) {
mActivityOrFragment = fragment;
mContext = fragment.getActivity();
Expand Down
Loading