小编Sim*_*mon的帖子

在Android O上禁用通知声音

我尝试在下面的方法中摆脱通知声音.

我能够将它减少到只有一次,但它应该在Android O和更低版本中完全无声.

我在stackoverflow和google上搜索了很长时间,但直到现在还没有完全奏效.

任何帮助表示赞赏.

public void showUpdateProgressNotification(int id, String appName, int progress, String status, long downloadStart) {

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        String NOTIFICATION_CHANNEL_ID = "my_channel_id_01";

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel notificationChannel = new NotificationChannel
                    (NOTIFICATION_CHANNEL_ID, "Test Notifications", NotificationManager.IMPORTANCE_LOW);
            notificationChannel.setSound(null, null);

            // Configure the notification channel.
            notificationChannel.setDescription("Channel test");
            notificationManager.createNotificationChannel(notificationChannel);
        }

        Intent cancelIntent = new Intent(ACTION_FILE_CANCEL);
        cancelIntent.putExtra("id", id);
        PendingIntent cancel = PendingIntent.getBroadcast(this, ACTION_FILE_CANCEL.hashCode() + id,
                cancelIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Builder notification = new …
Run Code Online (Sandbox Code Playgroud)

notifications android android-8.0-oreo

10
推荐指数
3
解决办法
8587
查看次数

退出应用程序(弹出)菜单时泄露的窗口

我希望你能帮助我,一旦我通过工具栏中的(弹出)菜单选项退出我的应用程序,我就会有一个泄露的窗口.如果我通过正常方法退出应用程序一切都很好.

有人可能会帮忙吗?我似乎无法找到错误,我正在努力找到一个合适的解决方案.我有2个静态字符串变量声明,但我想这不是问题.

许多事先提前.

以下是菜单的相关代码:

public class LoginActivity extends AppCompatActivity {
//
private Object mState = null;
private Object HIDE_MENU = null;
//
@Override
    protected void onCreate(Bundle savedInstanceState) {
//
 @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // inflate menu from xml
        MenuInflater mInflater = this.getMenuInflater();
        mInflater.inflate(R.menu.menu_main, menu);

        if (mState == HIDE_MENU) {
            menu.getItem(0).setVisible(false);
        }
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {

            case R.id.settings:
                    // Unassigned
                return true;

            case R.id.exit:
                    this.finish(); …
Run Code Online (Sandbox Code Playgroud)

android menu drop-down-menu

6
推荐指数
1
解决办法
1660
查看次数

从服务更新/访问进度条、TextView

我有一个活动 A,它有一个进度条和一个文本视图。

如果用户单击正在启动的服务(ServiceB)按钮,我试图找到一种方法如何从 ServiceB 更新 Activity A 中的进度条,同时在 Activity A 的 Textview 中设置(进度)文本。

我在 Google 和 Stackoverflow 上四处查看,我想我找到了一种方法来做到这一点,如下所述

但我在实施这一点时遇到困难,非常感谢任何帮助。

PS:不要投反对票,我知道 UI 不应该直接从服务访问,所以我正在寻找一种正确的方法。

一些相关代码:

活动一:

@EActivity(R.layout.downloads_activity)
public class DownloadsActivity extends BaseActivity {

@ViewById(R.id.progress_text)
TextView progresstxt;

@ViewById(R.id.progressdownload)
ProgressBar downloadprogress;

// Update Progressbar and set Text sent from ServiceB
}
Run Code Online (Sandbox Code Playgroud)

服务B:

public class ServiceB extends IntentService {
...

@Override
    public void onProgress(DownloadRequest request, long totalBytes, long downloadedBytes, int progress) {
        int id = request.getDownloadId();

        if (!isActive) {
            downloadManager.cancel(downloadId1);
            deleteCancelledFile.deleteOnExit();
        } else if …
Run Code Online (Sandbox Code Playgroud)

service android handler

1
推荐指数
1
解决办法
925
查看次数

获得对非活动类中的getSupportFragmentManager的访问权限

我希望有人能帮帮忙。我有一个非活动类,需要在其中使用静态方法访问fragmentmanager ,不幸的是我不知道如何正确传递上下文。

任何帮助表示赞赏,

非活动类别:

public class testClass {
..
public synchronized static void checkNewdata(List<data>input, Context context) {
..
       FragmentManager ft = ((FragmentActivity)???).getSupportFragmentManager();
                DialogFragment newFragment = MyNotification.newInstance();
                newFragment.setCancelable(false);
                newFragment.show(ft, "mydialog");
..
   }
}
Run Code Online (Sandbox Code Playgroud)

还从非活动类中调用方法checkNewdata,在该类中我尝试传递上下文,但这不起作用:

public class SearchResponse extends SuccessResponse {

private Context mcontext;

public SearchResponse(Context context){
    mcontext = context;
}
..
@Override
    public void save() {
..
    testClass.checkNewdata(mainData, context);
..
   }
}
Run Code Online (Sandbox Code Playgroud)

android android-context fragmentmanager

1
推荐指数
1
解决办法
2035
查看次数