Java Code Examples for android.content.Intent.getLongExtra()

The following are Jave code examples for showing how to use getLongExtra() of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: financisto1-holo   File: PurgeAccountActivity.java   View Source Code Vote up 8 votes
private void loadAccount() {
    Intent intent = getIntent();
    if (intent == null) {
        Toast.makeText(this, "No account specified", Toast.LENGTH_SHORT).show();
        finish();
        return;
    }

    long accountId = intent.getLongExtra(ACCOUNT_ID, -1);
    if (accountId <= 0) {
        Toast.makeText(this, "Invalid account specified", Toast.LENGTH_SHORT).show();
        finish();
        return;
    }

    account = em.getAccount(accountId);
    if (account == null) {
        Toast.makeText(this, "No account found", Toast.LENGTH_SHORT).show();
        finish();
    }
}
 
Example 2
Project: Cable-Android   File: UpdateApkReadyListener.java   View Source Code Vote up 7 votes
@Override
public void onReceive(Context context, Intent intent) {
  Log.w(TAG, "onReceive()");

  if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) {
    long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -2);

    if (downloadId == TextSecurePreferences.getUpdateApkDownloadId(context)) {
      Uri    uri           = getLocalUriForDownloadId(context, downloadId);
      String encodedDigest = TextSecurePreferences.getUpdateApkDigest(context);

      if (uri == null) {
        Log.w(TAG, "Downloaded local URI is null?");
        return;
      }

      if (isMatchingDigest(context, downloadId, encodedDigest)) {
        displayInstallNotification(context, uri);
      } else {
        Log.w(TAG, "Downloaded APK doesn't match digest...");
      }
    }
  }
}
 
Example 3
Project: airgram   File: WearReplyReceiver.java   View Source Code Vote up 7 votes
@Override
public void onReceive(Context context, Intent intent) {
    ApplicationLoader.postInitApplication();
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null) {
        return;
    }
    CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY);
    if (text == null || text.length() == 0) {
        return;
    }
    long dialog_id = intent.getLongExtra("dialog_id", 0);
    int max_id = intent.getIntExtra("max_id", 0);
    if (dialog_id == 0 || max_id == 0) {
        return;
    }
    SendMessagesHelper.getInstance().sendMessage(text.toString(), dialog_id, null, null, true, null, null, null);
    MessagesController.getInstance().markDialogAsRead(dialog_id, max_id, max_id, 0, true, false);
}
 
Example 4
Project: FlickLauncher   File: MemoryTracker.java   View Source Code Vote up 7 votes
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.v(TAG, "Received start id " + startId + ": " + intent);

    if (intent != null) {
        if (TestingUtils.ACTION_START_TRACKING.equals(intent.getAction())) {
            final int pid = intent.getIntExtra("pid", -1);
            final String name = intent.getStringExtra("name");
            final long start = intent.getLongExtra("start", System.currentTimeMillis());
            startTrackingProcess(pid, name, start);
        }
    }

    mHandler.sendEmptyMessage(MSG_START);

    return START_STICKY;
}
 
Example 5
Project: OSchina_resources_android   File: UserEventActivity.java   View Source Code Vote up 7 votes
@Override
protected void initWidget() {
    super.initWidget();
    mEmptyLayout.setOnLayoutClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mEmptyLayout.getErrorState() != EmptyLayout.NETWORK_LOADING) {
                mEmptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
                mPresenter.onRefreshing();
            }
        }
    });

    UserEventFragment fragment = UserEventFragment.newInstance();
    addFragment(R.id.lay_container, fragment);
    Intent intent = getIntent();
    mPresenter = new UserEventPresenter(fragment,
            this,
            intent.getLongExtra("authorId", 0),
            intent.getStringExtra("authorName"));
}
 
Example 6
Project: Simpler   File: GroupEditActivity.java   View Source Code Vote up 7 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_group_edit);
    ButterKnife.bind(this);

    Intent intent = getIntent();
    mType = intent.getIntExtra(INTENT_TYPE, TYPE_EDIT);
    if (mType == TYPE_EDIT) {
        mTvTitle.setText(R.string.title_edit_group);
        mGid = intent.getLongExtra(INTENT_GID, 0L);
        mPosition = intent.getIntExtra(INTENT_POSITION, 0);
        mGroupName = intent.getStringExtra(INTENT_NAME);
        mDesc = intent.getStringExtra(INTENT_DESC);
        mEtGroupName.setText(mGroupName);
        mEtGroupName.setSelection(mGroupName.length());
        mEtGroupDesc.setText(mDesc);
        mEtGroupDesc.setSelection(mDesc.length());
    } else if (mType == TYPE_ADD) {
        mTvTitle.setText(R.string.title_add_group);
    }
    mGroupMgrOp = new GroupMgrOp(this);
    mGroupMgrOp.setOnGroupCreateListener(new MyGroupCreateListener());
    mGroupMgrOp.setOnGroupUpdateListener(new MyGroupUpdateListener());
}
 
Example 7
Project: Android-2017   File: ViewNoteActivity.java   View Source Code Vote up 7 votes
/**
 * procesa el retorno del borrado de una nota.
 * @param requestCode codigo con el que se llama a la activity nueva
 * @param resultCode resultado de ejecución de la activity
 * @param data datos adicionales en forma de intent
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == AppConstants.REQUEST_CODE_EDIT) {
        switch (resultCode) {
            case AppConstants.RETURN_CODE_NOTE_DELETED :
                Toast.makeText(this, R.string.delete_note_ok, Toast.LENGTH_LONG).show();
                this.finish();
                break;
            case AppConstants.RETURN_CODE_NOTE_EDITED :
                long idNote = data.getLongExtra(AppConstants.EXTRA_NOTE_ID, 0);
                loadAndShowNote(idNote);
                Toast.makeText(this, R.string.edit_note_ok, Toast.LENGTH_LONG).show();
                break;
        }
    }
}
 
Example 8
Project: q-mail   File: OpenPgpKeyPreference.java   View Source Code Vote up 6 votes
@Override
public void onReturn(Intent result) {
    switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
        case OpenPgpApi.RESULT_CODE_SUCCESS: {

            long keyId = result.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, NO_KEY);
            save(keyId);

            break;
        }
        case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: {

            PendingIntent pi = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
            try {
                Activity act = (Activity) getContext();
                act.startIntentSenderFromChild(
                        act, pi.getIntentSender(),
                        requestCode, null, 0, 0, 0);
            } catch (IntentSender.SendIntentException e) {
                Log.e(OpenPgpApi.TAG, "SendIntentException", e);
            }
            break;
        }
        case OpenPgpApi.RESULT_CODE_ERROR: {
            OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
            Log.e(OpenPgpApi.TAG, "RESULT_CODE_ERROR: " + error.getMessage());

            break;
        }
    }
}
 
Example 9
Project: Simpler   File: WBStatusesActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wb_statuses);
    ButterKnife.bind(this);

    // 每次刷新微博数
    mRefreshCount = BaseSettings.sSettings.refreshCount;
    Intent intent = getIntent();
    mUid = intent.getLongExtra(INTENT_UID, 0L);
    String name = intent.getStringExtra(INTENT_NAME);

    mTvTitle.setText(getString(R.string.title_statuses, name));
    mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            // 刷新微博,加载最新微博
            loadStatuses(0, true);
            mSwipeRefresh.setRefreshing(true);
        }
    });
    // 创建适配器
    mAdapter = new StatusListAdapter(WBStatusesActivity.this, null);
    mSwipeRefresh.setRecyclerViewAndAdapter(mRvStatuses, mAdapter);
    mSwipeRefresh.setOnLoadingListener(new DSwipeRefresh.OnLoadingListener() {
        @Override
        public void onLoading() {
            if (mMaxId != 0) {
                // 加载更早微博
                mAdapter.setFooterInfo(getString(R.string.data_loading));
                loadStatuses(mMaxId, false);
            }
        }
    });
    loadStatuses(0, true);  // 加载最新微博
    mSwipeRefresh.setRefreshing(true);
}
 
Example 10
Project: Synapse   File: MainService.java   View Source Code Vote up 6 votes
@Override
public void onReceive(Context context, Intent intent) {
    final long downloadedId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);

    final DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(downloadedId);

    final Cursor cursor = mDownloadManager.query(query);

    if (cursor.moveToFirst() &&
            DownloadManager.STATUS_SUCCESSFUL == cursor.getInt(
                    cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))) {
        mIds.remove(downloadedId);

        if (mIds.isEmpty()) {
            Global.getInstance().getBus()
                    .post(new MSNEvent<>(MSNEvent.DOWNLOAD_COMPLETE, true));
        }
    } else {
        for (Long id : mIds) {
            mDownloadManager.remove(id);
        }

        Global.getInstance().getBus()
                .post(new MSNEvent<>(MSNEvent.DOWNLOAD_COMPLETE, false));
    }
}
 
Example 11
Project: Sprog-App   File: PoemsLoader.java   View Source Code Vote up 6 votes
public static void loadPoems(final Context context, final MainPresenter presenter) {
    File poems_file = new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
            "poems.json");
    File poems_old_file = new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
            "poems_old.json");
    if (poems_file.exists()) {
        poems_file.renameTo(poems_old_file);
    }

    String url = "https://almoturg.com/poems.json";
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    request.setDescription("Sprog poems");
    request.setTitle("Sprog");
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);

    request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS,
            "poems.json");

    // get download service and enqueue file
    DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    receiver = new BroadcastReceiver() {
        public void onReceive(Context ctxt, Intent intent) {
            if (intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) != downloadID){return;}
            context.unregisterReceiver(PoemsLoader.receiver);
            PoemsLoader.receiver = null;
            presenter.downloadComplete();
        }
    };
    context.registerReceiver(receiver,
            new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    downloadID = manager.enqueue(request);
}
 
Example 12
Project: MyRepository   File: DownloadService.java   View Source Code Vote up 6 votes
@Override
        public void onReceive(Context context, Intent intent) {
            Log.e("收到的action", intent.getAction());

            //判断是否下载完成的广播
            if (intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
//                Toast.makeText(context, "下载完成", Toast.LENGTH_SHORT).show();
//                timer.cancel();
                remoteViews.setTextViewText(R.id.tv_title, "产品医院下载完成");
                notifyProgress(100);

                //获取下载的文件id
                long downId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
                Uri downloadFileUri = manager.getUriForDownloadedFile(downId);
                Log.e("下载的apk路径", downloadFileUri.getPath());
                if (manager.getUriForDownloadedFile(downId) != null) {
                    //自动安装apk
                    Log.e("自动安装apk", "执行了");
                    installAPK(manager.getUriForDownloadedFile(downId), context);
//                    installAPK(context);
                } else {
                    Toast.makeText(context, "下载失败", Toast.LENGTH_SHORT).show();
                }
                //停止服务并关闭广播
                DownloadService.this.stopSelf();
            }
        }
 
Example 13
Project: SuperNote   File: NoteMainPresenter.java   View Source Code Vote up 6 votes
private void resultForAddNote(int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        String noteId = data.getStringExtra("note_id");
        String content = data.getStringExtra("note_content");
        long modifiedTime = data.getLongExtra("modified_time", 0);
        addNote(noteId, content, modifiedTime);
    }
}
 
Example 14
Project: SSHFileManager   File: SSHServersFragment.java   View Source Code Vote up 6 votes
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    final DBHelper dbHelper = new DBHelper(this.getContext());
    final SQLiteDatabase db = dbHelper.getWritableDatabase();
    final long id;

    if (requestCode == 0) {
        switch (resultCode) {
            case 0:

                break;
            case 1:
                final ContentValues cv = new ContentValues();
                cv.put("host", data.getStringExtra("host"));
                cv.put("username", data.getStringExtra("username"));
                cv.put("password", data.getStringExtra("password"));
                cv.put("port", data.getStringExtra("port"));
                cv.put("initDir", data.getStringExtra("initDir"));
                cv.put("userText", data.getStringExtra("userText"));

                id = data.getLongExtra("id", Integer.MAX_VALUE);
                if (id == Integer.MAX_VALUE) {
                    db.insert("sshServers", null, cv);
                } else {
                    db.update("sshServers", cv, "id=?", new String[] { (id+"") });
                }

                break;
            case 2:
                id = data.getLongExtra("id", Integer.MAX_VALUE);
                if (id != Integer.MAX_VALUE) {
                    db.delete("sshServers", "id=?", new String[] { (id+"") });
                }
                break;
        }

        dbHelper.close();
        refresh();
    }
}
 
Example 15
Project: GitHub   File: ShareIntentUtil.java   View Source Code Vote up 5 votes
public static long getIntentPatchCostTime(Intent intent) {
    return intent.getLongExtra(INTENT_PATCH_COST_TIME, 0);
}
 
Example 16
Project: IslamicLibraryAndroid   File: BookDownloadCompletedReceiver.java   View Source Code Vote up 5 votes
@Override
public void onReceive(Context context, Intent intent) {
    long enqueId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
    updateBookDownloadStatus(context, enqueId);
}
 
Example 17
Project: android-project-gallery   File: DownloadBroadcastReceiver.java   View Source Code Vote up 5 votes
@Override
public void onReceive(final Context context, Intent intent)
{
	String action = intent.getAction();
	if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equalsIgnoreCase(action))
	{
		DownloadFactory utils = DownloadFactory.getInstance(context.getApplicationContext());
		long downId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
		
		if (utils.containsTask(downId))
		{
			Log.D("info", "Current down id is in download task list!!!");
			utils.remove(downId); // 从队列中移除
			
			DownloadManager.Query query = new DownloadManager.Query().setFilterById(downId);
			
			Cursor cursor = utils.getDownloadManager().query(query);
			if (cursor != null && cursor.moveToFirst())
			{
				// 只有一条记录
				final long id = cursor.getLong(cursor.getColumnIndex("_id"));
				final String local_filename = cursor.getString(cursor.getColumnIndex("local_filename"));
				final String mediaprovider_uri = cursor.getString(cursor.getColumnIndex("mediaprovider_uri"));
				final String destination = cursor.getString(cursor.getColumnIndex("destination"));
				final String title = cursor.getString(cursor.getColumnIndex("title"));
				final String description = cursor.getString(cursor.getColumnIndex("description"));
				final String uri = cursor.getString(cursor.getColumnIndex("uri"));
				final String status = cursor.getString(cursor.getColumnIndex("status"));
				final String hint = cursor.getString(cursor.getColumnIndex("hint"));
				final String media_type = cursor.getString(cursor.getColumnIndex("media_type"));
				final String total_size = cursor.getString(cursor.getColumnIndex("total_size"));
				final String last_modified_timestamp = cursor.getString(cursor.getColumnIndex("last_modified_timestamp"));
				final String bytes_so_far = cursor.getString(cursor.getColumnIndex("bytes_so_far"));
				final String local_uri = cursor.getString(cursor.getColumnIndex("local_uri"));
				final String reason = cursor.getString(cursor.getColumnIndex("reason"));
				
				// 关闭
				cursor.close();
				
				if ("application/vnd.android.package-archive".equalsIgnoreCase(media_type))
				{
					// 下载完成后直接打开安装界面
					final File file = new File(local_filename);
					final String message = context.getString(R.string.download_install, title + "");
					Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
					
					new Thread(new Runnable()
					{
						
						@Override
						public void run()
						{
							Log.I(TAG, "Ready to install [" + title + "]");
							SystemClock.sleep(200);
							DownloadFactory.installApk(context, file);
						}
					}).start();
				}
			}
		}
	}
}
 
Example 18
Project: Open-Quran-Radio   File: SleepTimerService.java   View Source Code Vote up 5 votes
@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    // checking for empty intent
    if (intent == null) {
        LogHelper.v(LOG_TAG, "Null-Intent received. Stopping self.");
        stopSelf();
    }

    // ACTION TIMER START
    else if (intent.getAction().equals(TransistorKeys.ACTION_TIMER_START)) {
        LogHelper.v(LOG_TAG, "Service received command: START");

        if (intent.hasExtra(TransistorKeys.EXTRA_TIMER_DURATION)) {
            // get duration from intent
            long duration = intent.getLongExtra(TransistorKeys.EXTRA_TIMER_DURATION, 0);

            // set remaining time
            if (mTimerRemaining > 0) {
                mTimerRemaining = mTimerRemaining + duration;
            } else {
                mTimerRemaining = duration;
            }

            // set sleep timer
            setSleepTimer(mTimerRemaining);

            // start countdown
            mSleepTimer.start();

            // save timer state to preferences
            saveTimerState(true);
        }

    }

    // ACTION TIMER STOP
    else if (intent.getAction().equals(TransistorKeys.ACTION_TIMER_STOP)) {
        LogHelper.v(LOG_TAG, "Service received command: STOP");

        // set remaining time
        mTimerRemaining = 0;

        // cancel timer
        if (mSleepTimer != null) {
            mSleepTimer.cancel();
        }

        // save timer state to preferences
        saveTimerState(false);

    }

    // START_STICKY is used for services that are explicitly started and stopped as needed
    return START_STICKY;

}
 
Example 19
Project: health   File: NewsDetailActivity.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_news_detail);

    prefManager = new PrefManager(getApplicationContext());

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle("");

    imgPreview = (ImageView) findViewById(R.id.imgPreview);
    txtText = (TextView) findViewById(R.id.txtText);
    txtSubText = (TextView) findViewById(R.id.txtSubText);

    txtDescription = (WebView) findViewById(R.id.txtDescription);

    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content);

    prgLoading = (ProgressBar) findViewById(R.id.prgLoading);
    txtAlert = (TextView) findViewById(R.id.txtAlert);

    Intent iGet = getIntent();

    Product_ID = iGet.getLongExtra("product_id", 0);

    NewsDetailAPI = HackConstants.NewsDetailAPI +"?accesskey="+ HackConstants.AccessKey+"&product_id="+ Product_ID;

    com.github.clans.fab.FloatingActionButton fabShare = (com.github.clans.fab.FloatingActionButton) findViewById(R.id.share);
    fabShare.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent sendInt = new Intent(Intent.ACTION_SEND);
            sendInt.putExtra(Intent.EXTRA_SUBJECT, Product_name);
            sendInt.putExtra(Intent.EXTRA_TEXT, Product_description + "\n" + Product_image + "\n");
            sendInt.setType("text/plain");
            startActivity(Intent.createChooser(sendInt, "Хуваалцах"));
        }
    });
}
 
Example 20
Project: letv   File: DownloadService.java   View Source Code Vote up 5 votes
protected void onHandleIntent(Intent intent) {
    LogInfo.log(TAG, "onHandleIntent intent " + intent);
    if (intent != null && !TextUtils.isEmpty(intent.getAction())) {
        String action = intent.getAction();
        long vid = intent.getLongExtra("vid", 0);
        boolean isUserPause = intent.getBooleanExtra(IS_USER_PAUSE_ARG, true);
        DownloadVideo downloadVideo = (DownloadVideo) intent.getParcelableExtra(DOWNLOAD_VIDEO_ARG);
        if (action.equals(ACTION_PAUSE_DOWNLOAD)) {
            if (vid != 0) {
                pauseDownload(vid);
            }
        } else if (action.equals(ACTION_REMOVE_DOWNLOAD)) {
            if (vid != 0) {
                removeDownload(vid);
            }
        } else if (action.equals(ACTION_STARTALL_DOWNLOAD)) {
            startAllDownload();
        } else if (action.equals(ACTION_PAUSE_ALL_DOWNLOAD)) {
            try {
                pauseAllDownload(isUserPause);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (action.equals(ACTION_ADD_DOWNLOAD)) {
            if (downloadVideo != null) {
                addDownloadVideo(downloadVideo);
            }
        } else if (action.equals(ACTION_RESUME_DOWNLOAD)) {
            if (vid != 0) {
                resumeDownload(vid);
            }
        } else if (action.equals(ACTION_INIT_DOWNLOAD)) {
            L.v(TAG, "ACTION_INIT_DOWNLOAD>>");
            initDownloading();
        } else if (action.equals(ACTION_INIT_NOTIFICAITON)) {
            if (intent.getSerializableExtra("class") != null) {
                setClass((Class) intent.getSerializableExtra("class"));
            }
            L.v(TAG, "onHandleIntent ACTION_INIT_NOTIFICAITON " + this.mDownloadNotification);
            if (this.mDownloadNotification == null && this.mTargetClass != null) {
                initDownloadNotification(this.mTargetClass);
            }
        } else if (action.equals(ACTION_PAUSE_VIP_DOWNLOAD)) {
            pauseVipDownload();
        }
    }
}