开发者

dial_action cannot be resolved or is not a field

开发者 https://www.devze.com 2023-02-19 09:57 出处:网络
I have tried to execute a sample Intent application, but I am getting these errors in the java file: DIAL_ACTION cannot be resolved or is not a field

I have tried to execute a sample Intent application, but I am getting these errors in the java file:

DIAL_ACTION cannot be resolved or is not a field

NEW_TASK_LAUNCH cannot be resolved or is not a field

Here's my code:

package android_programmers_guide.AndroidTeleDial;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;


public class AndroidTeleDial extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Intent DialIntent=new Intent(Intent.DIAL_ACTION,Uri.parse("tel:5551212"));
        DialIntent.setLaunchFlags(Intent.NEW_TASK_开发者_JAVA技巧LAUNCH);
        startActivity(DialIntent);
    }
}


It's Intent.ACTION_DIAL.

To avoid this kind of errors, if you're using eclipse, use the auto-completion feature: while typing a word, press ctrl+space and it will open a list of possible completions.

This way, trying to auto complete Intent.DIAL you would find that there's no such member in Intent class.


I don't think setLaunchFlags() is used any more. I think you just need to set the flag:

Intent.FLAG_ACTIVITY_NEW_TASK

And as @bigstones states, you should also use Intent.ACTION_DIAL.


dial_action cannot be resolved or is not a field

Try this code.

package android_programmers_guide.AndroidPhoneDialer;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;

public class AndroidPhoneDialer extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Intent DialIntent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:5551212"));
        DialIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(DialIntent);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消