PendingIntent不适用于参数

时间:2014-12-07 13:49:07

标签: android android-intent android-pendingintent

在我的应用程序中,我有一个对话框,显示2个选项:CopyDismiss
当用户点击Copy时,我想在状态栏中收到通知。

public void showDialog(final String planet) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setIcon(R.drawable.ic_launcher);
    dialogBuilder.setTitle("Here You Go!");
    dialogBuilder.setMessage(planet);
    dialogBuilder.setPositiveButton("Copy", new DialogInterface.OnClickListener() {

        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @SuppressLint("NewApi")
        @Override
        public void onClick(DialogInterface dialog, int which) {
            int sdk = android.os.Build.VERSION.SDK_INT;
            if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
                android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(getApplicationContext().CLIPBOARD_SERVICE);
                clipboard.setText(planet);
            } else {
                android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(getApplicationContext().CLIPBOARD_SERVICE); 
                android.content.ClipData clip = android.content.ClipData.newPlainText("",planet);
                clipboard.setPrimaryClip(clip);
            }
            Toast.makeText(getApplicationContext(), "Copied!", Toast.LENGTH_SHORT).show();
            nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            Intent intent = new Intent(List.this, List.class);
            PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

        }

这是代码,我在PendingIntent.getActivity上收到错误,通知The method getActivity(Context, int, Intent, int) in the type PendingIntent is not applicable for the arguments (new DialogInterface.OnClickListener(){}, int, Intent, int)  快速修复无济于事!

1 个答案:

答案 0 :(得分:3)

使用WhateverYourActivityIsThatIsCallingYourShowDialogMethod.this代替this,其中WhateverYourActivityIsThatIsCallingYourShowDialogMethod是此showDialog()方法所在活动的名称。