簡體   English   中英

在Android中使用Intent通話

[英]Call using Intent in android

這是我的代碼。 我不知道為什么它不起作用。

package com.example.designing;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

public class Informationpage extends ActionBarActivity {
private static Button callbutton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_informationpage);
        callbutton=(Button)findViewById(R.id.button1);
       callbutton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String number = "01238888397";
                // TODO Auto-generated method stub
                 Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse( "tel" + number));
                    startActivity(callIntent);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.informationpage, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

我還在清單文件中包含了必需的文件。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.designing"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
     <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>   

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Listviewactivity"
            android:label="@string/title_activity_listviewactivity" >
        </activity>
        <activity
            android:name=".Informationpage"
            android:label="@string/title_activity_informationpage" >
        </activity>
    </application>

</manifest>

每當我運行此應用程序時,它就會停止。 它與另一個帶有按鈕的文件鏈接。 當我單擊一個按鈕時,將調用此活動,並且該應用程序停止。 請幫忙!

嘗試替換下面的行

 callIntent.setData(Uri.parse( "tel" + number));

 callIntent.setData(Uri.parse( "tel:" + number));

tel后添加列(:)

用這個:

String url = "tel:3334444";
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));

代替這個:

                String number = "01238888397";
                // TODO Auto-generated method stub
                 Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse( "tel" + number));
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" +your number));
startActivity(intent);

@khan請檢查本教程

 private void call() {
      Intent in=new Intent(Intent.ACTION_CALL,Uri.parse("01238888397"));
      try{
         startActivity(in);
      }

      catch (android.content.ActivityNotFoundException ex){
         Toast.makeText(getApplicationContext(),"yourActivity is not founded",Toast.LENGTH_SHORT).show();
      }
   }

Android-電話

http://www.tutorialspoint.com/android/android_phone_calls.htm

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM