2012-05-07 10 views
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) 
       { 

       } 
      } 
     }); 
    } 
} 

main.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> 

string.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> 

これはなぜだろうハプニング?

+0

アプリに通話権限を追加しましたか?フォーラムに質問を投稿する前に[いくつかの調査](https://www.google.com.pk/search?q=android+unfortunatly+application+has+stopped)を実行してください。 :) –

+0

は、はい私は –

+0

ボタンが資本 <ボタンアンドロイドだろうコール許可CALL_PHONを追加します。id = "@ + ID/callButton" アンドロイド:layout_width = "fill_parent" アンドロイド:layout_height = "wrap_content" アンドロイド:テキスト=」 ShowDialer " android:background ="#d3d3d3 "> ここにコードを入力してください –

答えて

0

マニフェストで許可を追加することを忘れないでください。

関連する問題