Android 10 BroadcastReceiver на прием не вызывается - PullRequest
0 голосов
/ 25 марта 2020

Мой код работает нормально до Android ОС 9. Но когда я обновляюсь до последней Android 10. Метод Broadcast Receiver onReceived не работает. ShareTargetReceiver onReceive () перестает работать после обновления на устройстве ниже приведены примеры кода. Я хочу использовать этот код для обмена изображениями в социальных сетях. Пожалуйста, помогите мне решить проблему.

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
public static void handleImageForAppName(Activity context, Uri bmpUri, String url,int storyId) {
    Intent receiverIntent = new Intent(context, ShareTargetReceiver.class);
    receiverIntent.putExtra(ShareTargetReceiver.EXTRA_IMAGE, 0);
    receiverIntent.putExtra(ShareTargetReceiver.EXTRA_TYPE, "stories");
    receiverIntent.putExtra(ShareTargetReceiver.EXTRA_CHANNEL, 0);
    receiverIntent.putExtra(ShareTargetReceiver.EXTRA_STORY_ID,storyId);
    Intent waIntent = new Intent(Intent.ACTION_SEND);
    waIntent.setType("image/*");
    waIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
    waIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    context.startActivity(Intent.createChooser(waIntent, context.getString(R.string.share_image_with), pendingIntent.getIntentSender()));
}

        <receiver android:name=".receiver.ShareTargetReceiver">
        <intent-filter>
            <action android:name="android.intent.extra.CHOSEN_COMPONENT" />
        </intent-filter>
    </receiver>



public class ShareTargetReceiver extends BroadcastReceiver {

public static final String EXTRA_STICKER = "STICKER";
public static final String EXTRA_NEWS = "NEWS";
public static final String EXTRA_IMAGE = "IMAGE";
public static final String EXTRA_CHANNEL = "CE";
public static final String EXTRA_TYPE = "type";
public static final String EXTRA_STORY_ID = "STORY_ID";
private static final String TAG = ShareTargetReceiver.class.getSimpleName();
private String appName = "socialMedia";
private static final String CHOSEN_COMPONENT = "android.intent.extra.CHOSEN_COMPONENT";
static final String WTS_APP = "com.whatsapp";
static final String FB = "com.facebook.katana";
static final String MSNGR = "com.facebook.orca";
static final String TXTRA = "com.textra";
static final String GMAIL = "com.google.android.gm";
static final String SKYPE = "com.skype.raider";
static final String BT = "com.android.bluetooth";
int StoryId = 0;
@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    if (bundle == null)
        return;
    String type = bundle.getString(EXTRA_TYPE, "");
    //Remove the stickerId extra to iterate on the chosen component only
    String stickerId = bundle.getString(EXTRA_STICKER);
    int newsId = bundle.getInt(EXTRA_NEWS);
    int timePassId = bundle.getInt(EXTRA_IMAGE);
    String channelid = bundle.getString(EXTRA_CHANNEL);
    StoryId = 0;
    if (bundle.containsKey(EXTRA_STORY_ID)) {
        StoryId = bundle.getInt(EXTRA_STORY_ID);
    }

    //iterate to find the componentName for android.intent.extra.CHOSEN_COMPONENT
    if (bundle.containsKey(CHOSEN_COMPONENT)) {
        Log.d(TAG, "STR->" + intent.getAction() + "key:  " + CHOSEN_COMPONENT + "=" + bundle.get(CHOSEN_COMPONENT));
        ComponentName componentName = (ComponentName) bundle.get(CHOSEN_COMPONENT);
        if (componentName != null) {
            appName = getAppName(componentName.getPackageName());
        } else {
            appName = "socialMedia";
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...