// 强制打开GPS
 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 (CanceledException e) {
     e.printStackTrace();
   }
 }
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   CardPresenter cardPresenter = mCardPresenters.get(position);
   PendingIntent pendingIntent = cardPresenter.getPendingIntent();
   if (pendingIntent != null) {
     try {
       pendingIntent.send();
     } catch (CanceledException e) {
       Log.w(TAG, e.getMessage());
     }
   } else {
     Log.w(TAG, "No PendingIntent attached to card!");
   }
 }
  private void openSMSComposer(String message) {
    System.out.println("openSMSComposer");

    // Intent sentIntent = new Intent(Intent.ACTION_VIEW);
    // sentIntent.putExtra("sms_body", message);
    // sentIntent.setType("vnd.android-dir/mms-sms");
    // this.cordova.getActivity().startActivity(sentIntent);

    PendingIntent sentIntent =
        PendingIntent.getActivity(this.cordova.getActivity(), 0, new Intent(Intent.ACTION_VIEW), 0);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.putExtra("sms_body", message);
    intent.setType("vnd.android-dir/mms-sms");
    // this.cordova.getActivity().startActivity(sentIntent);
    try {
      sentIntent.send(this.cordova.getActivity().getApplicationContext(), 0, intent);
    } catch (CanceledException e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
    }

    System.out.println("sent sms");
  }
Example #4
0
 @Override
 public void run() {
   if (password.length() > 4) {
     password = password.substring(0, 4);
   }
   if (password.length() == 4) {
     if (TextUtils.equals(MD5Utils.MD5(password), config.getDigitalPassword())) {
       if (isLaunchCamera) {
         AppUtils.launchCamera(getContext());
       } else if (notification != null) {
         try {
           notification.contentIntent.send();
         } catch (CanceledException e) {
           e.printStackTrace();
         }
       }
       LockerManager.getInstance(getContext()).unlock();
     } else {
       indicator.passwordWrong();
       password = "";
     }
   }
 }
Example #5
0
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    PrintWriter out = resp.getWriter();

    String phone = req.getParameter("phone");
    String sms = req.getParameter("sms");

    if (phone == null || sms == null) {
      out.println(createForm());
    } else {
      out.println("phone:" + phone + ";sms:" + sms);

      SmsManager smsManager = SmsManager.getDefault();
      try {
        this.sentPI.send(666);
      } catch (CanceledException e) {
        e.printStackTrace();
      }
      smsManager.sendTextMessage(phone, null, sms, this.sentPI, this.deliveredPI);
    }
    out.close();
  }
  /*
   * Handle the result of a sms being sent
   */
  private void handleSmsSent(Intent intent) {
    if (Log.DEBUG) Log.v("SMSReceiver: Handle SMS sent");

    PackageManager pm = getPackageManager();
    Intent sysIntent = null;
    Intent tempIntent;
    List<ResolveInfo> receiverList;
    boolean forwardToSystemApp = true;

    // Search for system messaging app that will receive our "message sent complete" type intent
    tempIntent =
        intent.setClassName(
            SmsMessageSender.MESSAGING_PACKAGE_NAME,
            SmsMessageSender.MESSAGING_RECEIVER_CLASS_NAME);

    tempIntent.setAction(SmsReceiverService.MESSAGE_SENT_ACTION);

    receiverList = pm.queryBroadcastReceivers(tempIntent, 0);

    if (receiverList.size() > 0) {
      if (Log.DEBUG)
        Log.v("SMSReceiver: Found system messaging app - " + receiverList.get(0).toString());
      sysIntent = tempIntent;
    }

    /*
     * No system messaging app was found to forward this intent to, therefore we will need to do
     * the final piece of this ourselves which is basically moving the message to the correct
     * folder depending on the result.
     */
    if (sysIntent == null) {
      forwardToSystemApp = false;
      if (Log.DEBUG)
        Log.v("SMSReceiver: Did not find system messaging app, moving messages directly");

      Uri uri = intent.getData();

      if (mResultCode == Activity.RESULT_OK) {
        SmsMessageSender.moveMessageToFolder(this, uri, SmsMessageSender.MESSAGE_TYPE_SENT);
      } else if ((mResultCode == SmsManager.RESULT_ERROR_RADIO_OFF)
          || (mResultCode == SmsManager.RESULT_ERROR_NO_SERVICE)) {
        SmsMessageSender.moveMessageToFolder(this, uri, SmsMessageSender.MESSAGE_TYPE_QUEUED);
      } else {
        SmsMessageSender.moveMessageToFolder(this, uri, SmsMessageSender.MESSAGE_TYPE_FAILED);
      }
    }

    // Check the result and notify the user using a toast
    if (mResultCode == Activity.RESULT_OK) {
      if (Log.DEBUG) Log.v("SMSReceiver: Message was sent");
      mToastHandler.sendEmptyMessage(TOAST_HANDLER_MESSAGE_SENT);

    } else if ((mResultCode == SmsManager.RESULT_ERROR_RADIO_OFF)
        || (mResultCode == SmsManager.RESULT_ERROR_NO_SERVICE)) {
      if (Log.DEBUG) Log.v("SMSReceiver: Error sending message (will send later)");
      // The system shows a Toast here so no need to show one
      // mToastHandler.sendEmptyMessage(TOAST_HANDLER_MESSAGE_SEND_LATER);

    } else {
      if (Log.DEBUG) Log.v("SMSReceiver: Error sending message");
      // ManageNotification.notifySendFailed(this);
      mToastHandler.sendEmptyMessage(TOAST_HANDLER_MESSAGE_FAILED);
    }

    /*
     * Now let's forward the same intent onto the system app to make sure
     * things there are processed correctly
     */
    //    sysIntent = intent.setClassName(
    //        SmsMessageSender.MMS_PACKAGE_NAME,
    //        SmsMessageSender.MMS_SENT_CLASS_NAME);

    //    Log.v("sysIntent = " + sysIntent.toString());
    //    Log.v("bundle = " + sysIntent.getExtras().toString());

    /*
     * Start the broadcast via PendingIntent so result code is passed over correctly
     */
    if (forwardToSystemApp) {
      try {
        Log.v("SMSReceiver: Broadcasting send complete to system messaging app");
        PendingIntent.getBroadcast(this, 0, sysIntent, 0).send(mResultCode);
      } catch (CanceledException e) {
        e.printStackTrace();
      }
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(WidgetUtils.BRIGHTNESS)) {
      mSettings = context.getSharedPreferences(PREFS_NAME, 0);
      mEditor = mSettings.edit();
      String BorderOfWidgetIDs = mSettings.getString("Table_Of_Widget_IDs", "-1");
      String[] setupItemsArray = context.getResources().getStringArray(R.array.setup_items_array);
      mConverter = new Converter();
      int[] border = mConverter.String_to_tabInt(BorderOfWidgetIDs, setupItemsArray.length);
      mTheID = border[1];
      mViews = new RemoteViews(context.getPackageName(), R.layout.widget_main_layout);

      // Setting up max brightness level NEED it here
      int curBrightnessValue = 100;
      try {
        curBrightnessValue =
            android.provider.Settings.System.getInt(
                context.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS);
      } catch (SettingNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
      if (curBrightnessValue < 130) {
        mState = 1;
        Settings.System.putInt(
            context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, 0);
        Settings.System.putInt(
            context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 255);
        mViews.setInt(R.id.main_one_one_one, "setAlpha", 1000);
        mViews.setInt(R.id.main_one_one_one, "setBackgroundResource", R.drawable.w_backbround_on);
      } else {
        mState = 0;
        Settings.System.putInt(
            context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, 0);
        Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 30);
        mViews.setInt(R.id.main_one_one_one, "setAlpha", 40);
        mViews.setInt(R.id.main_one_one_one, "setBackgroundResource", R.drawable.w_backbround_off);
      }
      mEditor.putInt("Screen_Brightness_State", mState);
      mEditor.commit();

      ComponentName thisWidget = new ComponentName(context, MyWidgetProviderOneOne.class);
      AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

      int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);

      for (int widgetId : appWidgetIds) {
        if (mTheID == widgetId) {
          appWidgetManager.updateAppWidget(widgetId, mViews);
          break;
        }
      }
      try {
        Intent myIntent = new Intent(context, RefreshClass.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, myIntent, 0);
        pendingIntent.send(context, 0, myIntent);
      } catch (CanceledException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }