1

当我运行以下代码时,我看到“不幸的是拨号器已停止工作”。

这是我的代码片段:

DialerActivity.java

package com.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.net.Uri;
import android.widget.Button;
import android.view.*;


public class DialerActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button callButton=(Button) findViewById(R.id.callButton);
        callButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) 
            {
                try {

                   Intent CallIntent = 
                      new Intent(Intent.ACTION_CALL,Uri.parse("tel:9563460376"));
                   CallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(CallIntent);
               }
               catch(Exception e)
               {

               }
           }
        });
    }
}

主要的.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <button android:id="@+id/callButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="ShowDialer"         
        android:background="#d3d3d3">
    </button>
</LinearLayout>

字符串.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hell">sanjoy</string>
    <string name="app_name">Test</string>
    <string name="button">ShowDialer</string>    
</resources>

为什么会发生这种情况?

4

1 回答 1

0
Intent serviceIntent = new Intent(context, YourClass.class);
serviceIntent.setAction("android.intent.action.NEW_OUTGOING_CALL");
serviceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(serviceIntent);

试试这个,别忘了在 Manifest 中添加权限。

于 2012-05-07T11:40:24.877 回答