无法在片段类

时间:2017-04-23 17:22:37

标签: java android android-fragments android-intent

这很疯狂。我可以从活动中开始调用,但不能从片段中开始调用。

package com.teslaqubitsins.fasih.teslahcm;


import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;



public class LocationDetailFragment extends Fragment {
    public static Location LOCATION;
    TextView _campusName;
    TextView _campusAddress;
    TextView _campusPhone;
    View parentView;

    public LocationDetailFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        parentView = inflater.inflate(R.layout.fragment_location_detail, container, false);
        _campusName = (TextView) parentView.findViewById(R.id.campus_name);
        _campusAddress = (TextView) parentView.findViewById(R.id.campus_address);
        _campusPhone = (TextView) parentView.findViewById(R.id.campus_phone);

        _campusName.setText("Campus Name:\n" + LOCATION.getLocation_name());
        _campusAddress.setText("\n\nCampus Address:\n" + LOCATION.getLocation_address());
        _campusPhone.setText("\n\nCampus Phone:\n" + LOCATION.getLocation_phone());
        setUpViews();
        return parentView;

    }
    private void setUpViews() {
        parentView.findViewById(R.id.callbutton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
                alertDialog.setTitle("Boss, really?");
                alertDialog.setMessage(LOCATION.getLocation_phone());
                alertDialog.setNegativeButton("No",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                                int which) {
                                dialog.cancel();
                            }
                        });
                alertDialog.setPositiveButton("Yes, make the call",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                                int which) {
                                Intent callIntent = new Intent(Intent.ACTION_CALL);
                                callIntent.setData(Uri.parse("tel:" + LOCATION.getLocation_phone()));
                                callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                                LocationDetailFragment.this.startActivity(callIntent);

                            }
                        });
                alertDialog.show();
            }
        });

这里是崩溃数据

  

04-23 22:12:08.177 2001-2278 / com.google.android.gms.persistent   W / GCoreFlp:没有为getLastLocation()返回的位置04-23   22:21:05.030 19253-19253 / com.teslaqubitsins.fasih.teslahcm   E / AndroidRuntime:致命异常:主要                                                                                      过程:com.teslaqubitsins.fasih.teslahcm,PID:19253                                                                                      java.lang.SecurityException:Permission Denial:启动Intent {   act = android.intent.action.CALL dat = tel:xxxxxxxxxxxx flg = 0x10000000   来自的cmp = com.android.server.telecom / .components.UserCallActivity}   ProcessRecord {54750a4 19253:com.teslaqubitsins.fasih.teslahcm / u0a75}   (pid = 19253,uid = 10075)具有撤销权限   android.permission.CALL_PHONE                                                                                          在android.os.Parcel.readException(Parcel.java:1684)                                                                                          在android.os.Parcel.readException(Parcel.java:1637)                                                                                          在   android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3101)                                                                                          在   android.app.Instrumentation.execStartActivity(Instrumentation.java:1518)                                                                                          在android.app.Activity.startActivityForResult(Activity.java:4225)                                                                                          在   android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)                                                                                          在   android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)                                                                                          在   android.support.v4.app.ActivityCompatJB.startActivityForResult(ActivityCompatJB.java:30)                                                                                          在   android.support.v4.app.ActivityCompat.startActivityForResult(ActivityCompat.java:146)                                                                                          在   android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:932)                                                                                          在   android.support.v4.app.FragmentActivity $ HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:1047)                                                                                          在android.support.v4.app.Fragment.startActivity(Fragment.java:940)                                                                                          在android.support.v4.app.Fragment.startActivity(Fragment.java:929)                                                                                          在   com.teslaqubitsins.fasih.teslahcm.LocationDetailFragment $ 1 $ 2.onClick(LocationDetailFragment.java:69)                                                                                          在   android.support.v7.app.AlertController $ ButtonHandler.handleMessage(AlertController.java:161)                                                                                          在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                          在android.os.Looper.loop(Looper.java:154)                                                                                          在android.app.ActivityThread.main(ActivityThread.java:6119)                                                                                          at java.lang.reflect.Method.invoke(Native Method)                                                                                          在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:886)                                                                                          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)04-23   22:21:05.919 2001-2278 / com.google.android.gms.persistent W / GCoreFlp:   没有为getLastLocation()返回的位置

0 个答案:

没有答案