Java Code Examples for android.app.PendingIntent#CanceledException

The following examples show how to use android.app.PendingIntent#CanceledException . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void onBatchScanResults(@NonNull final List<ScanResult> results) {
	final Context context = this.context != null ? this.context : this.service;
	if (context == null)
		return;

       // On several phones the broadcast is sent twice for every batch.
       // Skip the second call if came to early.
       final long now = SystemClock.elapsedRealtime();
	if (lastBatchTimestamp > now - reportDelay + 5) {
           return;
       }
       lastBatchTimestamp = now;

	try {
		final Intent extrasIntent = new Intent();
		extrasIntent.putExtra(BluetoothLeScannerCompat.EXTRA_CALLBACK_TYPE,
				ScanSettings.CALLBACK_TYPE_ALL_MATCHES);
		extrasIntent.putParcelableArrayListExtra(BluetoothLeScannerCompat.EXTRA_LIST_SCAN_RESULT,
				new ArrayList<Parcelable>(results));
		extrasIntent.setExtrasClassLoader(ScanResult.class.getClassLoader());
		callbackIntent.send(context, 0, extrasIntent);
	} catch (final PendingIntent.CanceledException e) {
		// Ignore
	}
}
 
Example 2
@Override
public void onReceive (Context context, Intent intent)
{
    try
    {
        PackageManager pm = context.getPackageManager();
        Intent launchIntent = pm.getLaunchIntentForPackage(context.getPackageName());
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent, 0);
        //
        contentIntent.send();
        //
        if (OBAnalyticsManager.sharedManager != null)
        {
            OBAnalyticsManager.sharedManager.deviceTurnedOn();
        }
    }
    catch (PendingIntent.CanceledException e)
    {
        e.printStackTrace();
    }
}
 
Example 3
protected final void newSatisfiedState(Boolean newState) {
    lck_satisfied.lock();
    try {
        if (satisfied == newState) {
            return;
        }
        satisfied = newState;
        if (satisfied == null)
            return;
        PendingIntent pendingIntent = satisfied ? event_positive : event_negative;
        try {
            pendingIntent.send();
        } catch (PendingIntent.CanceledException e) {
            Logger.wtf("PendingIntent for notify in SkeletonTracker cancelled before sending???");
            e.printStackTrace();
        }
    } finally {
        lck_satisfied.unlock();
    }
}
 
Example 4
public static void sendNotify(AccessibilityEvent event) {
    List<CharSequence> texts = event.getText();
    if (!texts.isEmpty()) {
        String message = texts.get(0).toString();

        //过滤微信内部通知消息
        if (isInside(message)) {
            return;
        }

        //模拟打开通知栏消息
        if (event.getParcelableData() != null && event.getParcelableData() instanceof Notification) {
            Log.i("demo", "标题栏canReply=true");
            try {
                Notification notification = (Notification) event.getParcelableData();
                PendingIntent pendingIntent = notification.contentIntent;
                pendingIntent.send();
            } catch (PendingIntent.CanceledException e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 5
Source Project: stynico   File: dex_smali.java    License: MIT License 6 votes vote down vote up
/** 打开通知栏消息*/
   private void openNotify(AccessibilityEvent event)
   {
       if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification))
{
           return;
       }
       Notification notification = (Notification) event.getParcelableData();
       PendingIntent pendingIntent = notification.contentIntent;
       try
{
           pendingIntent.send();
       }
catch (PendingIntent.CanceledException e)
{
           e.printStackTrace();
       }
   }
 
Example 6
Source Project: stynico   File: MD5_jni.java    License: MIT License 6 votes vote down vote up
/** 打开通知栏消息 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void openNotify(AccessibilityEvent event)
{
	if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification))
	{
		return;
	}
	// 将微信的通知栏消息打开
	Notification notification = (Notification) event.getParcelableData();
	PendingIntent pendingIntent = notification.contentIntent;
	try
	{
		pendingIntent.send();
	} catch (PendingIntent.CanceledException e)
	{
		e.printStackTrace();
	}
}
 
Example 7
/**
 * Send an intent to start the geofence service that listens to location
 * updates at a normal rate of frequency.
 */
private void startGeofenceService() {

  LocalGeofence.setSubtitle(mFenceSubtitleEditText.getText().toString());

  Intent serviceIntent = new Intent(MainActivity.ACTION_START_NORMAL_UPDATES,
      null, this, GeofenceServiceNormal.class);
  PendingIntent pendingIntent = PendingIntent.getService(this, 0,
      serviceIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  try {
    pendingIntent.send();
  }
  catch (PendingIntent.CanceledException e) {
    Toast.makeText(MainActivity.this, "Problem starting geofence service",
        Toast.LENGTH_SHORT).show();
    e.printStackTrace();
  }
}
 
Example 8
Source Project: Mobike   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 强制帮用户打开GPS
 * @param context
 */
public static final void openGPS(Context context) {
    Intent GPSIntent = new Intent();
    GPSIntent.setClassName("com.android.settings",
            "com.android.settings.widget.SettingsAppWidgetProvider");
    GPSIntent.addCategory("android.intent.category.ALTERNATIVE");
    GPSIntent.setData(Uri.parse("custom:3"));
    try {
        PendingIntent.getBroadcast(context, 0, GPSIntent, 0).send();
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
    }
}
 
Example 9
Source Project: RedEnvelopeAssistant   File: RedEnvelopeHelper.java    License: MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void openNotification(AccessibilityEvent event) {
    if( !(event.getParcelableData() instanceof Notification)) {
        return;
    }
    Notification notification = (Notification) event.getParcelableData();
    PendingIntent pendingIntent = notification.contentIntent;
    try {
        pendingIntent.send();
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
    }
}
 
Example 10
void restorePendingWhileIdleAlarmsLocked() {
    if (RECORD_DEVICE_IDLE_ALARMS) {
        IdleDispatchEntry ent = new IdleDispatchEntry();
        ent.uid = 0;
        ent.pkg = "FINISH IDLE";
        ent.elapsedRealtime = SystemClock.elapsedRealtime();
        mAllowWhileIdleDispatches.add(ent);
    }

    // Bring pending alarms back into the main list.
    if (mPendingWhileIdleAlarms.size() > 0) {
        ArrayList<Alarm> alarms = mPendingWhileIdleAlarms;
        mPendingWhileIdleAlarms = new ArrayList<>();
        final long nowElapsed = SystemClock.elapsedRealtime();
        for (int i=alarms.size() - 1; i >= 0; i--) {
            Alarm a = alarms.get(i);
            reAddAlarmLocked(a, nowElapsed, false);
        }
    }

    // Reschedule everything.
    rescheduleKernelAlarmsLocked();
    updateNextAlarmClockLocked();

    // And send a TIME_TICK right now, since it is important to get the UI updated.
    try {
        mTimeTickSender.send();
    } catch (PendingIntent.CanceledException e) {
    }
}
 
Example 11
Source Project: SprintNBA   File: NetworkUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 强制帮用户打开GPS
 */
public static final void openGPS() {
    Intent GPSIntent = new Intent();
    GPSIntent.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
    GPSIntent.addCategory("android.intent.category.ALTERNATIVE");
    GPSIntent.setData(Uri.parse("custom:3"));
    try {
        PendingIntent.getBroadcast(AppUtils.getAppContext(), 0, GPSIntent, 0).send();
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
    }
}
 
Example 12
private void onComplicationTap(int complicationId) {
    // TODO: Step 5, onComplicationTap()
    Log.d(TAG, "onComplicationTap()");

    ComplicationData complicationData =
            mActiveComplicationDataSparseArray.get(complicationId);

    if (complicationData != null) {

        if (complicationData.getTapAction() != null) {
            try {
                complicationData.getTapAction().send();
            } catch (PendingIntent.CanceledException e) {
                Log.e(TAG, "onComplicationTap() tap action error: " + e);
            }

        } else if (complicationData.getType() == ComplicationData.TYPE_NO_PERMISSION) {

            // Watch face does not have permission to receive complication data, so launch
            // permission request.
            ComponentName componentName =
                    new ComponentName(
                            getApplicationContext(), ComplicationWatchFaceService.class);

            Intent permissionRequestIntent =
                    ComplicationHelperActivity.createPermissionRequestHelperIntent(
                            getApplicationContext(), componentName);

            startActivity(permissionRequestIntent);
        }

    } else {
        Log.d(TAG, "No PendingIntent for complication " + complicationId + ".");
    }
}
 
Example 13
Source Project: Pasta-Music   File: TutorialActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    if(v.getId() == R.id.tutorial_button_left || v.getId() == R.id.tutorial_button_image_left) {
        boolean hasCustomAction = false;

        if(mFragmentList.get(mViewPager.getCurrentItem()) instanceof CustomAction) {
            if(((CustomAction)mFragmentList.get(mViewPager.getCurrentItem())).isEnabled()) {
                hasCustomAction = true;
            }
        }
        if(hasCustomAction) {
            PendingIntent intent = ((CustomAction)mFragmentList.get(mViewPager.getCurrentItem())).getCustomActionPendingIntent();
            try {
                intent.send();
            } catch (PendingIntent.CanceledException exception) {
                exception.printStackTrace();
            }
        } else if(mViewPager.getCurrentItem() == 0) {
            finish();
        } else {
            mViewPager.setCurrentItem(mViewPager.getCurrentItem()-1, true);
        }
    } else if (v.getId() == R.id.tutorial_button_image_right) {
        if(mViewPager.getCurrentItem() == getCount()-1) {
            finish();
        } else {
            mViewPager.setCurrentItem(mViewPager.getCurrentItem()+1, true);
        }
    }
}
 
Example 14
/**
 * Creates an OnClickListener that triggers the specified PendingIntent.
 *
 * @hide
 */
public static OnClickListener createIntentOnClickListener(@NonNull final PendingIntent intent) {
    Preconditions.checkNotNull(intent);
    return v -> {
        try {
            intent.send();
        } catch (PendingIntent.CanceledException e) {
            Log.e(LOG_TAG, "Error sending PendingIntent", e);
        }
    };
}
 
Example 15
Source Project: V.FlyoutTest   File: SampleMediaRouteProvider.java    License: MIT License 5 votes vote down vote up
private void handleSessionStatusChange(String sid) {
    if (mSessionReceiver != null) {
        Intent intent = new Intent();
        intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sid);
        intent.putExtra(MediaControlIntent.EXTRA_SESSION_STATUS,
                mSessionManager.getSessionStatus(sid).asBundle());
        try {
            mSessionReceiver.send(getContext(), 0, intent);
            Log.d(TAG, mRouteId + ": Sending session status update from provider");
        } catch (PendingIntent.CanceledException e) {
            Log.d(TAG, mRouteId + ": Failed to send session status update!");
        }
    }
}
 
Example 16
private void dismissAfterSharing(PendingIntent originalIntent) {
    try {
        originalIntent.send();
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
        if (isOrderedBroadcast()) {
            try {
                abortBroadcast();
            } catch (RuntimeException ignored) {

            }
        }
    }
}
 
Example 17
Source Project: styT   File: RedPacketService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 开启红包所在的聊天页面
 */
private void openWeChatPage(AccessibilityEvent event) {
    //A instanceof B 用来判断内存中实际对象A是不是B类型,常用于强制转换前的判断
    if (event.getParcelableData() != null && event.getParcelableData() instanceof Notification) {
        Notification notification = (Notification) event.getParcelableData();
        //打开对应的聊天界面
        PendingIntent pendingIntent = notification.contentIntent;
        try {
            pendingIntent.send();
        } catch (PendingIntent.CanceledException e) {
            e.printStackTrace();
        }
    }
}
 
Example 18
Source Project: styT   File: dex_smali.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 打开通知栏消息
 */
private void openNotify(AccessibilityEvent event) {
    if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification)) {
        return;
    }
    Notification notification = (Notification) event.getParcelableData();
    PendingIntent pendingIntent = notification.contentIntent;
    try {
        pendingIntent.send();
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
    }
}
 
Example 19
private void openNotification(int id) {

        StatusBarNotification sbn = mNotificationArray.get(id);

        if(sbn != null){

            try {

                sbn.getNotification().contentIntent.send();


                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    cancelNotification(sbn.getKey());
                }

                cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId());

            } catch (PendingIntent.CanceledException e) {
                e.printStackTrace();
            }
        }

        mNotificationArray.remove(id);
    }
 
Example 20
/**
  * Internal service callback; not meant for application use
  * @param jobId the job Id that was used in the original request, so that we can correlate the two
  * @param peer the peer from which the call arrived
  * @param sdpOffer sdp offer sent by the peer
  * @param customHeaders any custom SIP headers sent by the peer
  */
public void onCallArrivedEvent(String jobId, String peer, String sdpOffer, HashMap<String, String> customHeaders)
{
   RCLogger.i(TAG, "onCallArrivedEvent(): id: " + jobId + ", peer: " + peer);

   // filter out potential '<' and '>' and leave just the SIP URI
   String peerSipUri = peer.replaceAll("^<", "").replaceAll(">$", "");

   RCConnection connection = new RCConnection.Builder(true, RCConnection.ConnectionState.CONNECTING, this, signalingClient, audioManager)
         .jobId(jobId)
         .incomingCallSdp(sdpOffer)
         .peer(peerSipUri)
         .deviceAlreadyBusy(state == DeviceState.BUSY)
         .customHeaders(customHeaders)
         .build();

   // keep connection in the connections hashmap
   connections.put(jobId, connection);

   if (state == DeviceState.BUSY) {
      // If we are already talking disconnect the new call
      connection.reject();
      return;
   }

   state = DeviceState.BUSY;

   if (isAttached()) {
      audioManager.playRingingSound();
      // Service is attached to an activity, let's send the intent normally that will open the call activity
      callIntent.setAction(ACTION_INCOMING_CALL);
      callIntent.putExtra(RCDevice.EXTRA_DID, peerSipUri);
      callIntent.putExtra(RCDevice.EXTRA_VIDEO_ENABLED, (connection.getRemoteMediaType() == RCConnection.ConnectionMediaType.AUDIO_VIDEO));
      if (customHeaders != null) {
         callIntent.putExtra(RCDevice.EXTRA_CUSTOM_HEADERS, customHeaders);
      }
      //startActivity(callIntent);

      if (!this.parameters.containsKey(ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS) || !(Boolean) this.parameters.get(ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS)) {
         PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, callIntent, PendingIntent.FLAG_UPDATE_CURRENT);

         try {
            pendingIntent.send();
         } catch (PendingIntent.CanceledException e) {
            throw new RuntimeException("Pending Intent cancelled", e);
         }
      }
      else {
         // ParameterKeys.DEBUG_USE_BROADCASTS_FOR_EVENTS == true, we need to broadcast a separate intent, so that the Test Case is able to receive it.
         // For some reason PendingIntent is not received properly even when we construct a broadcast for it using getBroadcast()
         Intent testIntent = new Intent(RCDevice.ACTION_INCOMING_CALL);  //, null, InstrumentationRegistry.getTargetContext(), IntegrationTests.class));
         testIntent.putExtra(RCDevice.EXTRA_DID, peerSipUri);
         sendBroadcast(testIntent);
      }
      // Phone state Intents to capture incoming phone call event
      sendQoSIncomingConnectionIntent(peerSipUri, connection);
   } else {
      onNotificationCall(connection, customHeaders);
   }
}