List of usage examples for android.content Intent getStringExtra
public String getStringExtra(String name)
From source file:com.sonetel.service.Downloader.java
@Override protected void onHandleIntent(Intent intent) { HttpGet getMethod = new HttpGet(intent.getData().toString()); int result = Activity.RESULT_CANCELED; String outPath = intent.getStringExtra(EXTRA_OUTPATH); boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false); int icon = intent.getIntExtra(EXTRA_ICON, 0); String title = intent.getStringExtra(EXTRA_TITLE); boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title)); // Build notification Builder nb = new NotificationCompat.Builder(this); nb.setWhen(System.currentTimeMillis()); nb.setContentTitle(title);/*from w w w . j a va2 s . co m*/ nb.setSmallIcon(android.R.drawable.stat_sys_download); nb.setOngoing(true); Intent i = new Intent(this, SipHome.class); nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.download_notif); contentView.setImageViewResource(R.id.status_icon, icon); contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text)); contentView.setProgressBar(R.id.status_progress, 50, 0, false); contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE); nb.setContent(contentView); final Notification notification = showNotif ? nb.getNotification() : null; notification.contentView = contentView; if (!TextUtils.isEmpty(outPath)) { try { File output = new File(outPath); if (output.exists()) { output.delete(); } if (notification != null) { notificationManager.notify(NOTIF_DOWNLOAD, notification); } ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() { private int oldState = 0; @Override public void run(long progress, long total) { //Log.d(THIS_FILE, "Progress is "+progress+" on "+total); int newState = (int) Math.round(progress * 50.0f / total); if (oldState != newState) { notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false); notificationManager.notify(NOTIF_DOWNLOAD, notification); oldState = newState; } } }); boolean hasReply = client.execute(getMethod, responseHandler); if (hasReply) { if (checkMd5) { URL url = new URL(intent.getData().toString().concat(".md5sum")); InputStream content = (InputStream) url.getContent(); if (content != null) { BufferedReader br = new BufferedReader(new InputStreamReader(content)); String downloadedMD5 = ""; try { downloadedMD5 = br.readLine().split(" ")[0]; } catch (NullPointerException e) { throw new IOException("md5_verification : no sum on server"); } if (!MD5.checkMD5(downloadedMD5, output)) { throw new IOException("md5_verification : incorrect"); } } } PendingIntent pendingIntent = (PendingIntent) intent .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT); try { Runtime.getRuntime().exec("chmod 644 " + outPath); } catch (IOException e) { Log.e(THIS_FILE, "Unable to make the apk file readable", e); } Log.d(THIS_FILE, "Download finished of : " + outPath); if (pendingIntent != null) { notification.contentIntent = pendingIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.icon = android.R.drawable.stat_sys_download_done; notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE); notification.contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.done) // TODO should be a parameter of this class + " - Click to install"); notificationManager.notify(NOTIF_DOWNLOAD, notification); /* try { pendingIntent.send(); notificationManager.cancel(NOTIF_DOWNLOAD); } catch (CanceledException e) { Log.e(THIS_FILE, "Impossible to start pending intent for download finish"); } */ } else { Log.w(THIS_FILE, "Invalid pending intent for finish !!!"); } result = Activity.RESULT_OK; } } catch (IOException e) { Log.e(THIS_FILE, "Exception in download", e); } } if (result == Activity.RESULT_CANCELED) { notificationManager.cancel(NOTIF_DOWNLOAD); } }
From source file:cm.aptoide.pt.RemoteInSearch.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list);/*from w w w . jav a 2 s . c o m*/ db = new DbHandler(this); mPm = getPackageManager(); getListView().setFastScrollEnabled(true); Intent i = getIntent(); query = i.getStringExtra(SearchManager.QUERY); apk_lst = db.getSearch(query, order_lst); }
From source file:fi.iki.murgo.irssinotifier.IrssiNotifierActivity.java
@Override protected void onNewIntent(Intent intent) { String intentChannelToView = intent.getStringExtra("Channel"); if (intentChannelToView != null && !preferences.isFeedViewDefault()) channelToView = intentChannelToView; IrcNotificationManager.getInstance().mainActivityOpened(this); startMainApp(false);/*from w w w . j a va 2 s. c o m*/ }
From source file:net.frygo.findmybuddy.GCMIntentService.java
@Override protected void onMessage(Context arg0, Intent intent) { // TODO Auto-generated method stub // --- Called when a cloud message has been received. // --- handle here the push notification e.g. Toast Notification Log.v("TAG", "GCMIntentService onMessage"); String message = intent.getStringExtra("ContactNotification"); if (message != null) { generateNotification(arg0, message); } //end of if else {//from w w w . j a v a2 s . c o m message = intent.getStringExtra("Location"); if (message != null) { //generateNotification(arg0, message); double latitude = 0.0; double longitude = 0.0; // check if GPS enabled GPSTracker gps = new GPSTracker(arg0); if (gps.canGetLocation()) { latitude = gps.getLatitude(); longitude = gps.getLongitude(); gps.stopUsingGPS(); } //can get location final ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add( new BasicNameValuePair("email_id_2", new SharedPreference(this).retrievedata("email"))); nameValuePairs.add(new BasicNameValuePair("latitude", String.valueOf(latitude))); nameValuePairs.add(new BasicNameValuePair("longitude", String.valueOf(longitude))); Getdatawithoutpbar obj = new Getdatawithoutpbar(this, nameValuePairs); String ur = URL.url + "updatelatitudelongitude.php"; obj.execute(ur); } //end of if else { message = intent.getStringExtra("Contactrequestaccepted"); if (message != null) { generateAcceptfriendNotification(arg0, message, "accept"); } else { message = intent.getStringExtra("Contactrequestrejected"); if (message != null) { generateAcceptfriendNotification(arg0, message, "reject"); } } } } //end of else }
From source file:net.gcompris.GComprisActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK && data != null && requestCode == 1001) { int responseCode = data.getIntExtra("RESPONSE_CODE", -1); String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA"); try {// w w w. ja v a2 s .c o m JSONObject jo = new JSONObject(purchaseData); String sku = jo.getString("productId"); int purchaseState = jo.getInt("purchaseState"); String payload = jo.getString("developerPayload"); String purchaseToken = jo.getString("purchaseToken"); if (sku.equals(SKU_NAME) && purchaseState == 0) { bought(true); return; } } catch (Exception e) { e.printStackTrace(); } Log.e(QtApplication.QtTAG, "Buying full version failed: Result code == " + resultCode); } }
From source file:net.evecom.androidecssp.activity.EventAddActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case 1: // String filePath = data.getStringExtra("filePath"); Log.v("mars", filePath); manageFileDataAndListView(filePath); break;/*from www. j a v a 2 s . co m*/ case 2: // listView fileList.removeAll(fileList); List<FileManageBean> allPictures = db.findAll(FileManageBean.class); // listView for (FileManageBean item : allPictures) { fileList.add(item); } // listView uploadPictureAdapter.notifyDataSetChanged(); if (null != imageListView) { UiUtil.setListViewHeightBasedOnChildren(imageListView); } break; case 3: // updateGpsview(); break; default: break; } super.onActivityResult(requestCode, resultCode, data); }
From source file:com.shinymayhem.radiopresets.ServiceAudioFormat.java
@Override protected void onHandleIntent(Intent intent) { if (LOCAL_LOGV) log("onHandleIntent()", "v"); String url = intent.getStringExtra(ServiceRadioPlayer.EXTRA_URL); Intent updateIntent = new Intent(this, ServiceRadioPlayer.class); try {//from w w w. j a va 2 s . co m AudioType type = this.processUrl(url); String newUrl = this.getUrlByType(type, url); if (!url.equals(newUrl)) { if (LOCAL_LOGD) log("New URL: " + newUrl, "d"); } else { if (LOCAL_LOGV) log("New URL same as old URL: " + newUrl, "v"); } updateIntent.setAction(ServiceRadioPlayer.ACTION_PLAY_STREAM); updateIntent.putExtra(ServiceRadioPlayer.EXTRA_URL, newUrl); boolean updateUrl; //update player url if it was a playlist and the audio stream url was resolved //don't update if url was already a streaming media url //TODO handle the case where metadata is in the playlist switch (type) { case M3U: case PLS: case XSPF: updateUrl = true; break; case AAC: case AACP: updateIntent.setAction(ServiceRadioPlayer.ACTION_UNSUPPORTED_FORMAT_ERROR); default: updateUrl = false; } updateIntent.putExtra(ServiceRadioPlayer.EXTRA_FORMAT, type.toString()); updateIntent.putExtra(ServiceRadioPlayer.EXTRA_UPDATE_URL, updateUrl); } catch (StreamHttpException e) { if (LOCAL_LOGD) log("StreamHttpException for " + url, "d"); updateIntent.setAction(ServiceRadioPlayer.ACTION_STREAM_ERROR); updateIntent.putExtra(ServiceRadioPlayer.EXTRA_RESPONSE_CODE, e.getResponseCode()); updateIntent.putExtra(ServiceRadioPlayer.EXTRA_RESPONSE_MESSAGE, e.getResponseMessage()); } catch (MalformedURLException e) { if (LOCAL_LOGD) log("MalformedURLException for " + url, "d"); updateIntent.setAction(ServiceRadioPlayer.ACTION_FORMAT_ERROR); updateIntent.putExtra(ServiceRadioPlayer.EXTRA_ERROR_MESSAGE, getResources().getString(R.string.error_url)); } catch (IOException e) { if (LOCAL_LOGD) log("IOException for " + url, "d"); updateIntent.setAction(ServiceRadioPlayer.ACTION_FORMAT_ERROR); updateIntent.putExtra(ServiceRadioPlayer.EXTRA_ERROR_MESSAGE, getResources().getString(R.string.error_unknown)); } startService(updateIntent); //stopSelf(); }
From source file:io.clh.lrt.androidservice.TraceListenerService.java
private void traceEventStart(Context context, Intent intent) { JSONObject jsonData = new JSONObject(); try {/*from w w w. j a v a 2s.c o m*/ String appName = intent.getStringExtra("appName"); jsonData.put("appName", appName); jsonData.put("appVersion", intent.getStringExtra("appVersion")); jsonData.put("osType", "Android"); jsonData.put("osVersion", android.os.Build.VERSION.SDK_INT); jsonData.put("traceServiceVersion", TRACE_SERVICE_VERSION); String userId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); Log.d(TAG, "start trace: " + jsonData.toString()); HttpResponse response = postAPI("users/" + userId + "/traces", "trace", jsonData.toString()); BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), "UTF-8")); String json = reader.readLine(); JSONTokener tokener = new JSONTokener(json); JSONObject finalResult = new JSONObject(tokener); Log.d(TAG, "start trace got response: " + finalResult.toString()); String traceId = finalResult.getString("_id"); appLut.put(appName, traceId); traceEvent(context, intent); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:be.vbsteven.bmtodesk.BackgroundSharingService.java
@Override /**/* w w w.jav a2s . co m*/ * starts the service and gets ready to send bookmark * * this service is supposed to only get started once for every bookmark * so if onStart is called it means a new bookmark needs to be sent */ public void onStart(Intent intent, int startId) { super.onStart(intent, startId); // init notification manager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (intent.hasExtra(Global.EXTRA_TITLE) && intent.hasExtra(Global.EXTRA_URL)) { title = intent.getStringExtra(Global.EXTRA_TITLE); url = intent.getStringExtra(Global.EXTRA_URL); Log.d(Global.TAG, "started BackgroundSharingService with values " + title + " " + url); sendToServer(title, url); } else { // if we're not called with a title and url, stop the service stopSelf(); return; } }
From source file:com.autoparts.sellers.activity.MainDrawerActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) {//?? switch (requestCode) { case CommonData.REQUEST_SEARCH: String model = data.getStringExtra("model"); break; }//from ww w . j a va 2 s . c om } }